Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Teaching Perl

by Corion (Pope)
on Sep 04, 2012 at 11:09 UTC ( #991597=note: print w/replies, xml ) Need Help??

in reply to Re: Teaching Perl
in thread Teaching Perl

IMO nested data structures are always difficult, but Perl adds more difficulty early on. The only easy data structure you can pass around is the flat list, or some scalars in front of a flat list. Creating a complex data structure is "just some syntax", but accessing data in it requires learning about references and dereferencing.

Python for example makes accessing complex data structures easier, because it does not flatten argument lists. There is the nasty surprise later on, when you realize that you need the equivalent of Storable::dclone, because in Python just like in Perl, all complex elements of hashes and arrays are still references. But you don't need to know that just to pass parameters more complex than a list to a function, and retrieve them in that function.

Replies are listed 'Best First'.
Re^3: Teaching Perl
by SuicideJunkie (Vicar) on Sep 04, 2012 at 18:10 UTC

    Personally, I just pass around a reference to the complex data structure. And to keep it all dead simple, I declare the complex data structure as a reference to start with. That way there are no extra copies being made passing around the data structure is exactly the same as using it, and I don't fall out of practice with dereferencing.

    It is indeed a bit of a climb, but once you get around to figuring out references, everything becomes easier :)

Re^3: Teaching Perl
by Anonymous Monk on Sep 04, 2012 at 11:37 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991597]
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-04-26 06:20 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (468 votes). Check out past polls.