[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] shift; vs my $temp = shift;



On Wed, 22 Nov 2000 04:42:46 -0500, Scott R. Godin wrote:

>I had to change 
>sub size_calc {
>    shift;
>    ($_ <= 1024) ? return $_ . "k" : return sprintf('%.2f', ($_/1024)) .
>"MB"; 
>}
>
>to
>
>sub size_calc {
>    my $mapsize = shift;
>    ($mapsize <= 1024) ? return $mapsize . "k" : return sprintf('%.2f',
>($mapsize/1024)) . "MB";
>}
>
>and I have no idea why. Any ideas?

You have no idea why? Doing.

shift() gets an item and you throw it away. shift() does NOT store it
into $_, as you seem to assume. $_ is still what it was when you called
this sub.

This would work, too:

	sub size_calc {
	    local $_ = shift;
	    ... #same as rest of v1.
	}

	
-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org