Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Teaching Perl

by Corion (Patriarch)
on Sep 04, 2012 at 11:09 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-16 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found