Another Matching Approach
Another Matching Approach
- Program worked fine after translation:
- No split or substitution operation was performed
- Notice the values calculated
- Could change the pattern match line
/^(cme|cbt|lif|smx|lifee)/ {
start_point=match($0,"\\[[0-9]+\\]")
printf "%-18s%8d\n", substr($0,1,RSTART-1),
substr($0,RSTART+1,RLENGTH-2)
}
#!/usr/local/bin/perl
$[ = 1; # set array base to 1
while (<>) {
chop; # strip record separator
if (/^(cme|cbt|lif|smx|lifee)/) {
$start_point = $_ =~ "\\[[0-9]+\\]" &&
($RLENGTH = length($&), $RSTART = length($`)+1);
printf "%-18s%8d\n", substr($_, 1, $RSTART - 1), substr($_,
$RSTART + 1, $RLENGTH - 2);
}
}