Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl High School Graduation

by rinceWind (Monsignor)
on May 20, 2002 at 09:57 UTC ( [id://167795]=note: print w/replies, xml ) Need Help??


in reply to Perl High School Graduation

I agree totally with Zaxo here. References are very important, and should be done first, and in a great deal of detail.

This is the order in which I would attempt explaining references:

  • Argument passing and returning. Passing a list, and returning a list.
  • Passing modifiable variables (pass by reference).
  • Passing and returning whole arrays and hashes by reference.
  • Anonymous arrays and hashes.
  • Multi-dimensional arrays.
  • Arrays of hashes, hashes of hashes, hashes of arrays.
  • Introduce polymorphism and reflection - the ref function.
  • Data::Dumper
  • Plenty of exercises on references, then students should be ready for tackling perl objects and classes.
hth

--rW

Replies are listed 'Best First'.
Re: Re: Perl High School Graduation
by hsweet (Pilgrim) on May 21, 2002 at 01:35 UTC

    I feel another question coming on...Let me see if I understand the things you mention

    • argument passing as in passing arguments to subroutines?
    • Is pass by reference the same thing as passing a reference to a subroutine? I'm not clear on the exact meaning
    • ok with the next few. But what does Data::Dumper do?
      argument passing as in passing arguments to subroutines?
      Absolutely. Make sure that the students understand that they pass a list and can optionally return a list. Explain about the flattening effect of &foo(@a,@b); and explain that they are about to see a way of passing the arrays separately. If you have any advanced students, explain about wantarray.
      Is pass by reference the same thing as passing a reference to a subroutine?
      I take it you mean (passing a reference) to a subroutine, not passing a (reference to a subroutine). If so, yes, indeed. This is the same as in the C language - except that in C you are dealing with pointers (real addresses), whereas perl has references which essentially do the same job.

      Pass by reference: In the calling code, you have a real scalar (or array or hash) e.g. @foo. You pass a reference to it

      &mumble(\@foo);
      Now the code inside mumble can modify elements inside @foo:
      sub mumble { my ($bar) = @_; ... $bar->[1]++; #increments second member of array }
      But what does Data::Dumper do?
      Data::Dumper is a useful module that reverse engineers perl data structures into human readable perl code. To reconstruct the data structures, this can be done with an eval - this is one of many ways to do persistence in Perl.

      Further reading: perldoc perlsub gives more on subroutines and parameter passing. The Camel book: "Programming Perl" is an invaluable reference. Also, Sriram Srivanam's "Advanced Perl Programming" has an excellent chapter on references.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found