CLAIRIFICATION TO MY FIRST POST
I guess maybe a good answer must be constituted from code.
I am just using a reference to my data structure. Is there an advantage to changing it to a blessed reference? most of my accessors are generic but a few are specialized. I seek your thoughts and or possible change ideas.
As you can see I put the data into a array then reference it to a hash so I can get at it easily then return the whole thing as a reference. The reason for the array is so I can loop through it to write out the converted data in case your wondering. Also I am following a (MVC) model, view, controller programming style. This is part of the data model.
main.pl
my $buffer = Data::File::Open('all.bin');
my %Header = Data::Struct::Define::Header::Get($buffer);
my $objREF_wp = Data::Struct::Wp::wpData(substr($buffer, $Header{ws}{s
+tart}, $Header{ws}{offset}));
$value = Data::Struct::Wp::n_1_1($objREF_wp);
Wp.pm
sub wpData{
my $buffer = shift;
my $binString = unpack('b*', substr($buffer, 0));
my @data;
my %objREF;
my $count = 0;
open(F, "Waypoints.txt") or die $!;
my @funct = <F>;
close(F);
foreach my $line (@funct) {
$line=~s/\r|\n//g;
my @element = split(/,/, $line);
my $value = substr($binString, $element[1], $element[2]);
#### NO BYTES SWAPPING FOR THIS STRUCT
$data[$count] = $value;
$objREF{$element[0]} = \$data[$count];
$objREF{array} = \@data;
$count++;
}
$objREF{static} = "yes";
$objREF{instream} = "$binString";
$objREF{size} = "81";
$objREF{end} = substr($binString, (((81 * 8) - (length(join('', @d
+ata)))) - 1));
return \%objREF;
}
sub n_1_1{
##### IN: [obj-ref,new value or nothing to return value]
my $objREF = shift;
if (@_){
my $value = shift;
my $bitstream = ${$objREF->{n_way}};
substr($bitstream,0,1) = $value;
${$objREF->{n_way}} = $bitstream;
}
else{
my $bitstream = ${$objREF->{n_way}};
my $value = substr($bitstream, 0, 1);
return $value;
}
}
|