in reply to When does $_ get used?

$_ is used if a variable is used in the function. while (shift @array) tests whether shift @array is true. It doesn't go through the values of @array.
foreach (@array){} says go through each value of @array. $_ stands for the current element for each step in the foreach.

$_ is used if the function in question searches through the the values of an @array or keys %hash.

If it doens't search through the values, then it doesn't use $_.

----------------------------
Wiz, The VooDoo Doll
Head Master of 12:30 Productions
----------------------------

Replies are listed 'Best First'.
Re: (elbie) When does $_ get used?
by elbie (Curate) on Jul 26, 2001 at 22:01 UTC
    I'm sorry I confused the issue. My question wasn't "why doesn't while assign a value to $_" but "why doesn't shift?"

    Certainly while( <> ) { ... } works as I expected it to. While talking it over with other helpful monks via the Chatterbox, I found that the individual functions will say if they use $_ in their descriptions.

    That being said, is there a good reason why shift (for example) doesn't assign a value to $_ unless another variable is explicitly used?

      Because, for one thing, it's useful to call shift in void context to remove an array element with no other side-effects. Clobbering $_ in these cases would make it less useful.