in reply to Parsing a config file
If you don't control it, I would change how you're doing it.
use strict; my $config = '/var/www/cgi-bin/prt.cfg'; open( FH, '<', $config ) or die "Cannot open '$config': $!\n"; my @servers; my ($in_server, @temp); while ( <FH> ) { next if /^#|\s/; chomp; if (/<server.*?>/i) { die "Entering server when in server\n" if $in_server; $in_server = 1; } elsif (/<\/server.*?>/) { die "Entering server when in server\n" if !$in_server; $in_server = 0; push @servers, [ @temp ]; @temp = (); } elsif ( $in_server ) { push @temp, $_; } } close FH; use Data::Dumper; print Dumper( \@servers );
This can be seen as a very simple state machine.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|