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

hi... actually i wanna save the whole output in a variable. so that i can use it later.

Replies are listed 'Best First'.
Re^4: Output in variable
by Sombrerero_loco (Beadle) on Jan 22, 2009 at 12:01 UTC
    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";
      }
    
      Tanx Sombrerero loco.... its working :)
Re^4: Output in variable
by Bloodnok (Vicar) on Jan 22, 2009 at 11:57 UTC
    What, you mean like ...
    $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 :-))