in reply to Data Structures
$Easting{$Line}{$Station}
That implies you intend to have 3 hashes, one for each of x, y & z. Parallel data structures are not (generally) a good idea as they can get out of sync and you're stuffed. Going by the line diagram, you'd be better off with something that allowed you to do:
my %line = ( lineNameA => { StationA => [ xxx.xx, yyy.yy, zzz.zz ], StationB => [ xxx.xx, yyy.yy, zzz.zz ], ... }, lineNameB => { ... ); my( $x, $y, $z ) = $line{ $lineName }{ $stationName }; # Or use constant{ X => 0, Y => 1, Z => 2 }; my $y = $line[ $lineNo ][ $staionNo ][ Y ];
That's assuming the the identifiers are names not numbers.
If they are numbers, or names of the form "line_003" and "station_12", (low, mostly sequential number postfixes ),
then you'd save some memory and be a tad quicker to use arrays instead of hashes:
my @line = ( [ ## $line[ 0 ] [ xxx.xxx, yyy.yyy, zzz.zzz ], ## $line[0][0] (station 0) [ xxx.xxx, yyy.yyy, zzz.zzz ], ## (station 1) [ xxx.xxx, yyy.yyy, zzz.zzz ], ... ], [ ## Line[ 1 ] [ xxx.xxx, yyy.yyy, zzz.zzz ], ## Line[ 1 ][ 0 ] [ xxx.xxx, yyy.yyy, zzz.zzz ], [ xxx.xxx, yyy.yyy, zzz.zzz ], ... ], ... ); my( $x, $y, $z ) = $line[ $lineNo ][ $stationNo ]; # Or use constant{ X => 0, Y => 1, Z => 2 }; my $y = $line[ $lineNo ][ $staionNo ][ Y ];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Data Structures
by alexm (Chaplain) on May 02, 2008 at 10:51 UTC | |
by BrowserUk (Patriarch) on May 02, 2008 at 11:22 UTC | |
Re^2: Data Structures
by YYCseismic (Beadle) on May 02, 2008 at 15:55 UTC | |
by BrowserUk (Patriarch) on May 02, 2008 at 16:26 UTC | |
by YYCseismic (Beadle) on May 02, 2008 at 16:44 UTC | |
by BrowserUk (Patriarch) on May 02, 2008 at 17:14 UTC | |
by YYCseismic (Beadle) on May 02, 2008 at 21:26 UTC | |
by YYCseismic (Beadle) on May 02, 2008 at 19:42 UTC | |
by BrowserUk (Patriarch) on May 02, 2008 at 21:07 UTC | |
by Anonymous Monk on May 04, 2008 at 17:41 UTC |