Hi.
Im not shure what you really want to load into the variable, select or all the line after the text select?
Try to change $_ for $1 (this its how perl saves the matched regex after the next iteration or line)
But...explain better what you want to get in the output | [reply] |
hi... actually i wanna save the whole output in a variable. so that i can use it later.
| [reply] |
$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";
}
| [reply] |
$PatternToMatch="^SELECT";
$tmpfile="pattern.txt";
$var = '';
open(MYFILE, "<$tmpfile")|| die "Cannot create $tmpfile\n";
while (<MYFILE>) {
$var .= $_ if /$PatternToMatch/;
}
.
.
.
.
eval $var;
??
A user level that continues to overstate my experience :-))
| [reply] [d/l] |
Tanx Loco... its working :)
| [reply] |
Right now i am printing the output directly by print "$_". but i wanna save this output in a variable. how can i do this ??? | [reply] |
Uhm, you already have the output in a variable. The variable is called $_. If you don't want to print it, then, well, perhaps you should consider not asking perl to print it.
| [reply] [d/l] |
Just use concatenation if you want to capture all the lines.
my $output;
$PatternToMatch="^SELECT";
$tmpfile="pattern.txt";
open(MYFILE, "$tmpfile")|| die "Cannot create $tmpfile\n";
while (<MYFILE>) {
if (/$PatternToMatch/)
{
#print "$_";
$output .=$_;
}
}
| [reply] [d/l] |