简体   繁体   中英

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

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 .

#!/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. I'm leaving to you reading lines from file task and iterative processing task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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