What does this mean : '$_' ?

Showing Answers 1 - 4 of 4 Answers

Lucy

  • Jul 22nd, 2007
 

It is a default variable which hold automatically the list of arguments passed to subroutines within parentheses.

  Was this answer useful?  Yes

prabhath_01

  • May 31st, 2008
 

It is called as default variable in Perl.
It hold the current value in any block ie., 'for' or 'while'.
Eg.,

******************************************
print "n", $_ for (1..10);   # $_ represents current value in each iteration for loop

o/p:
1
2
3
4
5
6
7
8
9
10

******************************************
my %hash = ( a => 100, b => 200, c => 300);
print "n", $_ for keys(%hash);

o/p:

a
b
c

***************************************

  Was this answer useful?  Yes

The most commonly used global scalar variable is the $_ variable. Many Perl functionsand operators modify the contents of $_ if you do not explicitly specify the scalarvariable on which they are to operate.The following functions and operators work with the $_ variable by default:l. The pattern-matching operator2. The substitution operator3. The translation operator4. The <> operator, if it appears in a while or for conditional expression5. The chop function6. The print function7. The study function

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.