$_ is the "default input and template input field". In other words, if you read from the file descriptor at the top of the while loop or run the foreach loop and do not name the loop variable, $_ configured for you.
However, if you write a foreach loop and name the loop variable, $ _ is not configured. This may be justified by the following code:
1. #!/usr/bin/perl -w 2. @array = (1,2,3); 3. foreach my $elmnt (@array) 4. { 5. print "$_ "; 6. }
Output "Using uninitialized value in concatenation (.)"
However, if you replace line 3 with:
foreach (@array)
The output is "1 2 3" as expected.
Now in your case it is always better to specify the loop variable in the foreach loop to make the code more readable (perl is already cursed to be less readable), thus, there will also be no need for an explicit assignment to the $_ variable and the resulting determination problems.
sud03r
source share