in reply to lexical scope in if/elsif tests
#!/usr/bin/perl use warnings; use strict; my (%foos, %bars); my %targethash =( foo => \%foos, bar => \%bars, ); while( my $line = <DATA> ) { chomp $line; my ($name, $key, $val ) = $line =~ /^(\w+) ([^:]*):([^:]*)$/ ; if (! $name ){ warn qq( "$line" is the wrong format.\n ); }elsif (my $target = $targethash{$name} ){ $target->{$key} = $val; } else { warn "Line: $. has Invalid name '$name'\n"; } } __DATA__ foo key1:val1 bar key2:val2 foo key3:val3 qux key6:val6 bar key4:val4 3 bad:val 4bad:syntax
Syntactic sugar causes cancer of the semicolon. --Alan Perlis
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: lexical scope in if/elsif tests
by AR (Friar) on Apr 05, 2010 at 19:41 UTC | |
by NetWallah (Canon) on Apr 05, 2010 at 22:27 UTC |