bivouac has asked for the wisdom of the Perl Monks concerning the following question:
I think the next world for me to conquer in Perl is references; I really seem to struggle with the concept and the use.
I've been reading the perldoc reftut and the concept still escapes me.
What I am understanding is that when you pass a reference to a function, you're not passing a copy of the referant but the referant itself (I think, like I said I don't get references too well). With the code I'm enclosing below, how could I play around with the concept of changing something via the use of a reference and a function and then see the results of the change in the main block of data.
#!/usr/bin/perl -w use strict; my %horoscopes = ( 'homer' => 'pisces', 'marge' => 'sagitarius', 'bart' => 'cancer', 'libra' => 'libra', ); my $reference = \%horoscopes; capitalize($reference); sub capitalize { foreach (keys(%{$reference})) { tr/[a-z]/[A-Z]/; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pass by reference
by Zaxo (Archbishop) on Nov 07, 2003 at 18:36 UTC | |
|
Re: pass by reference
by Limbic~Region (Chancellor) on Nov 07, 2003 at 18:31 UTC | |
|
Re: pass by reference
by Zed_Lopez (Chaplain) on Nov 07, 2003 at 20:08 UTC | |
|
Re: pass by reference
by shockme (Chaplain) on Nov 07, 2003 at 18:26 UTC | |
|
Re: pass by reference
by Taulmarill (Deacon) on Nov 07, 2003 at 18:32 UTC |