Berkeley CSUA MOTD:Entry 13650
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2024/12/24 [General] UID:1000 Activity:popular
12/24   

1998/2/10-11 [Computer/SW/Languages/Perl] UID:13650 Activity:high
2/10    Perl is a great language. However, how do you pass by reference
        a complex data structure? I am able to pass by reference a simple
        list when my subroutine refers to $_[$num], but when I have to
        pass a hash of hash and hash of list, I don't know how to change
        the referenced value anymore! Please help, thanks.
        \_ See "perldoc perldsc" for examples and an explanation.
        \_ list of hash and list of list are easier to demonstrate:
                %h1 = %h2 = %h3 = ();
                $loh = (\%h1, \%h2, \%h3);
                ($h1ref, $h2ref, $h3ref) = @$loh;
           similarly:
                @l1 = @l2 = @l3 = ();
                $lol = (\@l1, \@l2, \@l3);
                ($l1ref, $l2ref, $l3ref) = @$lol;
           get it?
           \_ Yes, that I get, but how about hash of list and hash of hash?
                perldoc perldsc does not explain any of this. Thanks.
                \_ IT"S THE SAME WAY:  %obj = ('alphabets' => ['a', 'b', 'c'],
                                               'numbers' => [1, 2, 3],
                                               'subs' => [ &get, &put, &set ]);
                \_ elements of hashes and lists must be scalars.  This means
                  that you have to have lists of hash refs and hashes whose
                  values are refs of whatever thingies you want.  Boy this
                  is confusing, but I hope I answered your question.
                  \_ oh man, took me a whole week to figure this out. pUrl
                     sucks!!!!!!!!!!!! Now I have to create a totally separate
                     class to handle pass by reference a "slightly" more
                     complicated data structure.
                     \_ Nothing wrong with the lanauge.  You just suck because
                        you didn't RTFM *before* you spent a week writing
                        total crap code.  "WAAAH! I DIDN'T READ THE MANUAL
                        SO IT SUKZ!!!!!"
                        \_If it takes more than 'awk', just write it in
                          C.  -meyers