logo       

On using $_ in subroutines: msg#00364

perl-beginners

Subject: On using $_ in subroutines



Is it not possible to use $_ in subroutines?

For example, my temptation was to do this:

**************************************
sub isDate {

$_ = shift;
if (m!\d{2}/\d{2}/\d{2}!) { return 1; }
else { return 0; }


}
**************************************

... but by modifying $_ I was clobbering $_ elsewhere in the larger program!
Oddly, perl won't let me do "my ($_) = shift;", so I'm stuck having to use
another variable.

Why can't we do that? Is using $_ in subroutines discouraged??

TIA.

- Bryan



--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise