in reply to Re: Ending a 'next unless' loop...
in thread Ending a 'next unless' loop...

There is one problem I see with this approach.

Unless I'm missing something I think you meant

open(EMPLOYEES,'test.txt') or die; while (my $line = <EMPLOYEES>) { #remove the carriage return chomp $line; #splits the line between tabs and get the different elements my ($name, $city, $language) = split /\t/, $line; next unless $language =~ /$search/; print "$name can speak " . ($search) . " and lives in " . ($city) . ".\n"; } print "Sorry, your query produced no results.\n" if (eof(EMPLOYEES)) +;

But the bigger problem using the eof approach is that if the match is last line of the file - you'll get the match printed and the 'Sorry' message.



grep
One dead unjugged rabbit fish later

Replies are listed 'Best First'.
Re^3: Ending a 'next unless' loop...
by ikegami (Patriarch) on Oct 04, 2006 at 05:24 UTC

    Unless I'm missing something I think you meant

    For some odd reason, I thought <EMPLOYEES> contained the query results. Don't try to make sense of it for I was completely wrong.