in reply to Re^2: Search Directory
in thread Search Directory

The code still does the line print "$_\n";
even if if($_ eq $img_name) this condition is true.
I would like the code to exit the foreach completely.
Thanks.

Replies are listed 'Best First'.
Re^4: Search Directory
by Grundle (Scribe) on Feb 01, 2005 at 18:45 UTC
    There is nothing wrong with the code. I did a UNIT TEST just to make sure. Try running the following and you will notice that it exits out and does not print when the

    if($_ eq $img_name)

    statement is reached.

    @array = (0, 1, 2, 3, 4, 5); foreach(@array){ if($_ eq 3){ last; } print "$_\n"; } #this will output #0 #1 #2
    Try checking to make sure $img_name is what you think it is, or it may be that the defined $img_name is not contained within the file and therefore no match will be made?