in reply to exit a loop

read next and last.
You should get code similar to this:
#UNTESTED use strict; use warnings; my %files = ( FOO => { A => 2 }, BAR => { B => 3 } ); MAIN: while (<FH>) { my ($col1, $col2) = split m/\s+/; foreach my $file (keys %files) { if (exists $files{$file}{$col2} ) { #do something; next MAIN; } } }

Also please use strict; and use warnings; you'll save yourself a lot of grief.

UPDATE:

Although it might be even cleaner (clearer and more maintainable) by creating a sub.

##ALSO UNTESTED while (<FH>) { my ($col1, $col2) = split m/\s+/; stuff_i_need_do($col1) if ( check_for_condition(\%files,$col2) ); } sub check_for_condition { my $files = shift || return undef; my $col = shift || return undef; foreach my $file ( keys %{$files} ) { return 1 if (exists $files{$file}{$col2} ); } return undef; } sub stuff_i_need_to_do { my $stuff = shift; #do something; }


grep
One dead unjugged rabbit fish later

Replies are listed 'Best First'.
Re^2: exit a loop
by Anonymous Monk on Nov 09, 2006 at 16:37 UTC
    i think thats doing the job. Thanks for your help