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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.