Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by BrowserUk (Patriarch)
on Aug 25, 2002 at 23:03 UTC ( [id://192726]=note: print w/replies, xml ) Need Help??


in reply to Why does my subroutine not receive the scalar parameter as $_?

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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://192726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-23 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found