Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.


Comment on Re^2: Teaching Perl
Re^3: Teaching Perl
by Anonymous Monk on Sep 04, 2012 at 11:37 UTC
Re^3: Teaching Perl
by SuicideJunkie (Priest) 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 :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2014-09-02 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (24 votes), past polls