http://www.perlmonks.org?node_id=991597


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