[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] search string



I've put together the following search string script (below). When it 
finds the string it prints out the whole line that the string was found 
in. What I've been trying to do for the last 3 days is to get the results 
written to a new variable so I can use later in my script. 

FOR EXAMPLE:

I have 'print ("$line\n");' written in my nested, within a while, if 
statement and then again out side as the last call, the script currently 
only prints outs the results once but not the second time, by the final 
print statement. How can I assign the search output to a new variable so 
that I could print it out the second time, or use for what would actually 
be the next part of my script?

#!perl

$file = "myfile.dat";

print ("search?\n");
$search = <STDIN>;
chop ($search);

open (INFILE, $file) ||
        die ("Can't open input file!\n");
while ($line = <INFILE>) {
        if ($line =~ /$search/i) {
                print ("$line\n");

        }

}

print ("$line");

Zach-
fisk@homarus.ccsu.ctstateu.edu