Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm facing a peculiar problem. If i run the follwoing lines of code I get the output.
my $type="w"; &print_summary; sub print_summary { if($type=~/w/) { print "hello\n"; } }
output: hello
But if try to run like this:
sub print_summary { if($type=~/w/) { print "hello\n"; } } my $type="w"; &print_summary;
It doesn't give me any output. What could be the reason behind this as in both cases the varibale is declared before the function call is made?
20060505 Janitored by Corion: Added formatting, code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with function
by Corion (Patriarch) on May 05, 2006 at 13:36 UTC | |
|
Re: Problem with function
by jonadab (Parson) on May 05, 2006 at 13:47 UTC | |
by ruzam (Curate) on May 05, 2006 at 15:45 UTC | |
by jonadab (Parson) on May 05, 2006 at 21:23 UTC | |
|
Re: Problem with function
by japhy (Canon) on May 05, 2006 at 13:46 UTC | |
|
Re: Problem with function
by blazar (Canon) on May 05, 2006 at 13:39 UTC | |
|
Re: Problem with function
by billh (Pilgrim) on May 05, 2006 at 15:05 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |