Problems? Is your data what you think it is? | |
PerlMonks |
Re^4: Output in variableby Sombrerero_loco (Beadle) |
on Jan 22, 2009 at 12:01 UTC ( [id://738126]=note: print w/replies, xml ) | Need Help?? |
maybe try this:
$PatternToMatch="^SELECT"; $tmpfile="pattern.txt"; open(MYFILE, "$tmpfile")|| die "Cannot create $tmpfile\n"; while (<MYFILE>) { if (/$PatternToMatch/) { push (@array, $_); } }As you are reading the file, you need to push every time perl founds Select to and array, because the variable get overwritten with every success match. After that, recover all the data from the array when you need. foreach $control (@array) { print "Line -> $control\n"; }
In Section
Seekers of Perl Wisdom
|
|