$grid->get_line(257)->get_station('257_5')->Elevation;
####
$grid->{ 257 }{ 257_5 }[ Elevation ];
##
##
$grid->get_line($lineID)->get_station($stationID)->Elevation;
##
##
$grid->{ $lineId }{ $stationID }[ Elevation ];
##
##
my $seismic = Seismic->new( 'seismic.dat' );
for my $lineID ( keys %{ $seismic } ) {
for my $stn ( values %{ $seismic->{ $lineID } } ) {
$stn->[ Easting ] -= $stn->[ Easting ] * 0.00001;
$stn->[ Northing ] -= $stn->[ Northing ] * 0.000002;
$stn->[ Elevation ] += 1;
$stn->[ Other ] = int(
( $stn->[ Easting ]
* $stn->[ Northing ]
* $stn->[ Elevation ]
) / 3.0
);
}
}
##
##
## You didn't provide a constructor from a file
## But you could have.
my $grid = Seismic::Grid->new( 'seismic.dat' );
for my $line_id ( $grid->line_ids ) {
my $line = $grid->get_line( $line_id );
for my $stn_id ( $line->station_ids } ) {
my $station = $line->get_station($station_id);
$station->set_Easting(
$station->get_Easting
- ( $station->get_Easting * 0.00001 )
);
$station->set_Northing(
$station->get_Northing
- ( $station->get_Northing * 0.000002 )
);
$station->set_Elevation(
$station->get_Elevation() - 1
);
## You didn't provide this attribute, presumably
## cos like me you didn't know what is was
## but you could have
$station->set_Other(
int(
( $station->get_Easting()
* $station->get_Northing()
* $station->get_Elevation()
) / 3.0
);
}
}
##
##
package Seismic;
use Exporter;
use constant {
Easting => 0,
Northing => 1,
Other => 2,
Elevation => 3
};
our @ISA = qw[ Exporter ];
our @EXPORT = qw[ Easting Northing Other Elevation ];
sub new {
my( $class, $filename ) = @_;
my %lines;
open my $in, '<', $filename or die "$filename : $!";
while( <$in> ) {
my( $line, $stn, $x, $y, $other, $z ) =
unpack 'A8xA8xA8xA8xxA15xa4', $_;
$lines{ $line }{ $stn } = [ $x,$y, $other, $z ];
}
close $in;
return bless \%lines, $class;
}
1;