go ahead... be a heretic | |
PerlMonks |
Re: Perl file editingby Athanasius (Archbishop) |
on Nov 04, 2015 at 10:22 UTC ( [id://1146892]=note: print w/replies, xml ) | Need Help?? |
Hello rahulme81, Your while loop contains this line:
which sets $pattern and $id to the first and fifth fields, respectively, in the current line. But the data you show contains only three fields per line, so you should have:
(Note that the $_ is unnecessary here.) Also, this line:
tests whether the current line begins with $pattern. But you just initialized $pattern as the first field in the line, so how could this fail? (Well, it will fail if the line begins with whitespace, but I don’t think that’s what you had in mind.) You need to test $pattern against a pre-determined pattern, for example:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|