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; } }

In reply to Re: reference versus bless by arcnon
in thread reference versus bless by arcnon

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.