Well I clearly I still dont understand how references and hashes fully.I am writing a module with a subroutine in it.

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.

sub 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;
PS If anyone spots room for improvement in my code please point it out. It's the only way I'll learn :-) Diarmuid

In reply to references hashes arrays fun ... again :-( by diarmuid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.