kidd has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks...
I have kind of a question...I have this code that pushes lines to an array if a certain condition is true:
This checks each line to see if it has the word perl in it...if it has it pushes the whole line to the @search array. My problem is that sometimes the text doesnt have the word..so I need to know if @search has any content... How can I do this? I already triedmy (@search); my $query = "perl"; open(FILE, "myfile.txt"); flock(FILE, 1); my @lines = <FILE>; close(FILE); foreach my $lines(@lines){ chomp($lines); push(@search, $lines) if grep { /$query/ } $lines; }
But it doesnt seem to work... Any help is gladly accepted... Thanksif(@search){ print "Hey...I found something\n" }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Checking Arrays
by grep (Monsignor) on Aug 18, 2002 at 21:57 UTC | |
Re: Checking Arrays
by adrianh (Chancellor) on Aug 18, 2002 at 23:56 UTC | |
Re: Checking Arrays
by jmcnamara (Monsignor) on Aug 19, 2002 at 14:17 UTC | |
Re: Checking Arrays
by Anonymous Monk on Aug 19, 2002 at 03:03 UTC | |
by grep (Monsignor) on Aug 19, 2002 at 03:55 UTC | |
by vek (Prior) on Aug 19, 2002 at 13:39 UTC | |
by Abigail-II (Bishop) on Aug 19, 2002 at 13:43 UTC |
Back to
Seekers of Perl Wisdom