简体   繁体   English

如何将一些字符串映射到另一个字符串并在perl中打印输出

[英]how to map some string(s) into another and print output in perl

I have a log file and a table name entered by user as input. 我有一个日志文件和一个由用户输入的表名。 Now this table name entered by user will be searched in log file and if any data corresponding to that table is found it should be mapped into a more non technical language which the end user can understand. 现在,将在日志文件中搜索用户输入的该表名,如果找到与该表相对应的任何数据,则应将其映射为最终用户可以理解的非技术性语言。

Can anyonyone suggest how to do this mapping and then print the equivalent mapped string as output. 任何人都可以建议如何进行此映射,然后将等效的映射字符串打印为输出。

For example the data to be mapped is: 例如,要映射的数据是:

!!!!!! Diff004: record 0 differs in content for fields 'pid'
!!!!!! Diff005: record 1 differs in content for fields 'pid'
!!!!!! Diff006: record 2 differs in content for fields 'pid'

This data to be mapped into more non-technical statement and then those mapped statemennt to be shown to user instead of these. 该数据将被映射为更多非技术性陈述,然后将那些映射后的状态菜单(而不是这些映射状态)显示给用户。

real data on request of @TLP @TLP要求提供真实数据

Checking table CTusr000...
!!!!!! Diff004: record 0 differs in content for fields 'pid'
!!!!!!                        
uexpday,uexphr,uexpmin,uexpsec
db1 [Rec 000000] 30 00 00 00 00 00 00 00,00 00,53 55 50 45 52 55 53 45 52 00 00,77

It is really hard for me to figure out what mapped into a more non-technical language means, since that's not technical language, but it is.. english . 对于我来说,真的很难弄清楚映射到一种非技术性语言中意味着什么,因为这不是技术性语言,而是英语

So, have a look at the following example that shows you how to get record no and field name , from a generic $line . 因此,请看下面的示例,该示例向您展示如何从通用$line获取record nofield name

#!/usr/bin/perl -w

use strict;
use warnings;

my $line = "!!!!!! Diff004: record 0 differs in content for fields 'pid'";

$line =~ /^!{6}\s+.*record\s+(\d+)\s+differs.*fields\s+'(\w+)'$/;

print "record no: $1\n";
print "field name: $2\n";

Combine those informations in the better non-technical manner you intent. 以您希望的更好的非技术性方式结合这些信息。

The example is for a single $line only. 该示例仅适用于单个$line I'm leaving to you reading lines from file task and iterative processing task. 我要留给您阅读文件任务和迭代处理任务的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM