| Processing XML with Perl |    | Michel Rodriguez | 
 ![]() Control Structures  |     |  ![]() Object-Oriented Perl  |  
Perl Idioms
Reading a file line by line
while(<>) { process( $_) };  |  
Storing the lines of a file in an array
open( FILE, "<file") or die "cannot open file: $!"; my @lines= <FILE>;  |  
Sorting a hash
# sort the keys alphanumerically
foreach ( sort keys %hash) { process( $_, $hash{$_}); }
# sort the keys numerically
foreach my $key ( sort { $a <=> $b} keys %hash) { process( $key, $hash{$key}); }
  |  
 ![]() Regular Expressions  |     |  ![]() Object-Oriented Perl  |  
 

