in reply to Re^3: Output in variable
in thread Output in variable
$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";
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Output in variable
by Anonymous Monk on Jan 22, 2009 at 12:03 UTC |