Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Answer: Why does my subroutine not receive the scalar parameter as $_?

( #192726=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > Why does my subroutine not receive the scalar parameter as $_? contributed by BrowserUk

In addition, you have trouble brewing once you fix that problem. You are defining your $months hash as a hash reference instead of a hash, and that breaks in the loop that follows. The relevant part of you code (with corrections) is:

my %months = ( ## Change $ to % and { to ( --- no reason t +o use a reference here. 'JAN' => '31', 'FEB' => "$feb", 'MAR' => '31', 'APR' => '30', 'MAY' => '31', 'JUN' => '30', 'JUL' => '31', 'AUG' => '31', 'SEP' => '30', 'OCT' => '31', 'NOV' => '30', 'DEC' => '31', ); ## Changed { to ) my @month_keys = (keys %months); my $tot_days = $dd; for (my $i = 0; $month_keys[$i] ne $mon; $i++) { # Added my

Also, in future, it is better to ask your questions in the Seeker of Perl Wisdom section rather than here in the Q&A section. This is reserved for generic Q&A's, rather than specific questions like your.

Comment on Answer: Why does my subroutine not receive the scalar parameter as $_?
Select or Download Code
Re: Answer: Why does my subroutine not receive the scalar parameter as $_?
by belg4mit (Prior) on Aug 26, 2002 at 23:41 UTC
    Actually this is one of the best Q&'A's I've seen. If you think about it, even as an experienced perl person, it's a good question. One could quite reasonably expect this behavior. And of course the answer is...
    local $_ = shift || $_;
    Which I found myself using a bit recently.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (17)
As of 2014-10-24 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (132 votes), past polls