in reply to Re: Output in variable
in thread Output in variable

Right now i am printing the output directly by print "$_". but i wanna save this output in a variable. how can i do this ???

Replies are listed 'Best First'.
Re^3: Output in variable
by JavaFan (Canon) on Jan 22, 2009 at 12:01 UTC
    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.
      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 .=$_; } }