diarmuid has asked for the wisdom of the Perl Monks concerning the following question:
The subroutine builds an array of a hashes (easy), however I have tried to assign an array to one of those hashes and I'm having no luck. Any ideas? I'm pretty sure it something to do with the way I'm assigning to the hash or reading from the hash Here's the code.
PS If anyone spots room for improvement in my code please point it out. It's the only way I'll learn :-) Diarmuidsub Parse_Constraint_File { croak("Parse_Constraint_File <filename>") unless(my $filename = shif +t); my $setup_hash_ref = shift; my $open_command = ($filename =~ /\.gz$/) ? "gzip -dc $filename|" : +$filename; my $rec={}; my @path_details=[]; my $i=0; open(CONST,"$open_command") || croak("Can't open $filename"); while(<CONST>){ # find out the important info: if(/Startpoint: ([\w\/]+)$/) { $rec->{'startpoint'} = $1 }; if(/Endpoint: ([\w\/]+)$/) { $rec->{'endpoint'} = $1 }; if(/Path Group: (\w+)$/) { $rec->{'path_group'}= $1 }; if(/Path Type: (\w+)$/) { $rec->{'path_type'}= $1 }; if(/^\s+Point/.../^\s+slack/ && $setup_hash_ref->{'detail'}){ push @path_details,$_; } if(/^\s+slack [\w\(\)]+\s+(-?[\d\.]+)$/) { #last field is reached $rec->{'slack'} = $1; $rec->{'path_details'} = [ @path_details ]; # if we set a startpoint the only pick those paths if (defined($setup_hash_ref->{'startpoint'}) && defined($setup_hash_ref->{'endpoint'})){ if($rec->{'startpoint'} =~ /$setup_hash_ref->{'startpoint'}/ & +& $rec->{'endpoint'} =~ /$setup_hash_ref->{'endpoint'}/){ $timing_paths[$i++] = $rec; print @path_details; } }else{ # otherwise take all points $timing_paths[$i++] = $rec; } @path_details=[]; $rec={}; } } return @timing_paths; close CONST;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: references hashes arrays fun ... again :-(
by premchai21 (Curate) on Aug 09, 2001 at 19:02 UTC | |
by diarmuid (Beadle) on Aug 09, 2001 at 19:45 UTC | |
by Hofmator (Curate) on Aug 09, 2001 at 19:56 UTC | |
|
Re: references hashes arrays fun ... again :-(
by rchiav (Deacon) on Aug 09, 2001 at 19:08 UTC | |
by davorg (Chancellor) on Aug 09, 2001 at 19:29 UTC | |
|
Re: references hashes arrays fun ... again :-(
by dragonchild (Archbishop) on Aug 09, 2001 at 19:16 UTC | |
|
Re: references hashes arrays fun ... again :-(
by snax (Hermit) on Aug 09, 2001 at 19:50 UTC | |
|
Re: references hashes arrays fun ... again :-(
by diarmuid (Beadle) on Aug 09, 2001 at 19:03 UTC |