On Thu, Jun 28, 2001 at 08:50:12PM -0400, F.H wrote:
I'm not sure if the lack of indentation is in your original code or not, but
in case it is, for the sanity of people that need to read your code (like
us!) please indent, and indent consistently.
Also, always use warnings and strict when debugging your code.
> my %state;
> %state = (
> CHICAGO => ["MAIN", "BROADWAY", "OAK"],
> LA => ["DELTA", "GAMMA"],
> BOSTON => ["FIRST", "MAIN"],
> BURLINGTON => ["SECOND", "ONE"],
> SEATTLE => ["GREAT","MAIN"],
> );
>
>
>
> SWITCH:{ while ($line = <DATA>){
> #next if /^\s*$/;
> @line = split /\s*,\s*/, $line;
> $city = $line[3];
> #print @line;
> #print "CITY : $city\n";
> foreach $street (@{ $state{$city} } ){
> print $street, "\n";
> if ( $street ne "MAIN"){
> next SWITCH;
> }
> }
>
> }
> }
next in a bare block is just like last. I'm not sure what your intent here
is; perhaps you meant redo.
You probably shouldn't be using a bare block as a looping construct. What
is the intent of your code, what do you want it to do if $street eq 'MAIN'
or $street ne 'MAIN'?
Perhaps you can learn from and adapt this:
#!/usr/bin/perl -w
use strict;
my %state = (
CHICAGO => [qw(MAIN BROADWAY OAK)],
LA => [qw(DELTA GAMMA )],
BOSTON => [qw(FIRST MAIN )],
BURLINGTON => [qw(SECOND ONE )],
SEATTLE => [qw(GREAT MAIN )],
);
print("Does the city have a main street?\n");
CITY: foreach my $city (keys %state) {
foreach my $street (@{ $state{$city} }) {
if ($street eq 'MAIN') {
print "$city: yes\n";
next CITY;
}
}
print "$city: no\n";
}
outputs:
Does the city have a main street?
SEATTLE: yes
BURLINGTON: no
BOSTON: yes
LA: no
CHICAGO: yes
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--