output:#!/usr/local/bin/perl -w use strict "vars"; use strict "subs"; sub inter(\%) { printf "$_[0]\n"; printf "@_\n"; printf "$_[0]->{a}\n"; printf "$_[0]{a}\n"; } printf "ONE\n"; my %c = (a=>"a",b=>"b"); inter(%c); printf "TWO\n"; my $ref = "inter"; $ref->(%c); printf "THREE\n"; $ref->(\%c);
Questions:ONE HASH(0x622430) HASH(0x622430) a a TWO a a a b b Use of uninitialized value in concatenation (.) or string at /home/smk +/prog/pl/interesting.pl line 10. Use of uninitialized value in concatenation (.) or string at /home/smk +/prog/pl/interesting.pl line 11. THREE HASH(0x622430) HASH(0x622430) a a
tointer(%c)
then I get a compilation error as follows:inter(\%c)
Why is this?Type of arg 1 to main::inter must be hash (not reference constructor) +at /home/smk/prog/pl/interesting.pl line 18, near "%c)" Execution of /home/smk/prog/pl/interesting.pl aborted due to compilati +on errors.
2. Why does the argument have to be a reference again if the function itself is being called by reference? (block THREE)
3. In block TWO, it looks like the function is treating the argument as an array.
4. Finally, inside the function, in the final two printfs, I am using different notations, one if $_[0] was a hash, and another if it was a reference. Both work similarly. How can this be explained?
Thanks a lot!
In reply to references and functions by jignasu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |