I'm not sure exactly what you are trying to say.
When the foreach is done, the value of $_ seems
to revert to the value it had prior to the foreach
(but I don't think that is guaranteed or documented).
Example:
@calc=(2,4,6,8);
$_=3;
for(@calc){
$total+=$_;
}
print "value is $_, total is $total\n";
prints "value is 3, total is 20" (on Windoze 98SE w/AS build 806).
$_ is aliased to the successive elements of @calc
as the loop progresses. You should not expect $_
to be set to the last element of the array when
the loop terminates normally. Is that what you
were expecting?
I fixed it
it seams that in a previous line I had
my @list = @{ shift(@_) };
my $value = shift(@_);
so I changed that to
my @list = @{ shift() };
my $value = shift();
maybe the first case when I used @_ that set perl default variable $_ to
a fixed value but when I removed @_ that freed it again.
if I am not correct please correct me and explain why that had happend.
thanks
As to the above comments, I'm afraid they make no sense to me at all.
What relation does @list and $value have to the foreach loop code? None
that's discernable to me. Just as @_ has nothing to with $_. There
should be no difference between "shift()" and "shift(@_)", since @_ is
the default argument for shift if the argument is omitted. It is
unclear what you were expecting and why you were expecting it. Could
you try again with a clear description, such as a short complete
standalone program anyone can copy/paste/execute (like the one I put in
above) that will illustrate your problem?