Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: C-Style Struct?

by Arunbear (Parson)
on Aug 08, 2012 at 17:24 UTC ( #986324=note: print w/ replies, xml ) Need Help??


in reply to Re: C-Style Struct?
in thread C-Style Struct?

Your code example doesn't allow access by name, so what's the advantage of it?


Comment on Re^2: C-Style Struct?
Re^3: C-Style Struct?
by Anonymous Monk on Aug 08, 2012 at 18:30 UTC

    You could add accessors to the object. Like this:

    sub count { my $self = shift; return $self->[0] unless @_; $self->[0] = shift; } # ... $cc->count(42); print $cc->count;
Re^3: C-Style Struct?
by xiaoyafeng (Chaplain) on Aug 08, 2012 at 23:57 UTC
    changed it, Thanks for your reminding.;)




    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

      But now I can see no advantage to using your example over just using a hash ;)

        But now I can see no advantage to using your example over just using a hash ;)

        No, My way is using a perl object to create a struct, every struct created by this has the same elements and spawned by the same creator.
        my %hash_1 = (number => 123, name => aa, stuff => \@xx); my %hash_2 = (number => 124, name => bb, stuff => \@yy); my %hash_3 = (number => 125, name => cc, stuff => \@zz); #if you chang +e struct, you have to change every instance. ..... ..... ..... my $aa = C_struct->new(123,'aa', [1,2,3]); my $bb = C_struct->new(234,'bb', [2,3,4]); #every instance is spawned +by the same object.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-11-24 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls