Perl Language
Specialvariabler
Sök…
Anmärkningar
GÖRA: Lägg till mer innehåll.
Specialvariabler i perl:
1. $_ : Standardinmatnings- och mönstersökningsutrymme.
Exempel 1:
my @array_variable = (1 2 3 4);
foreach (@array_variable){
print $_."\n"; # $_ will get the value 1,2,3,4 in loop, if no other variable is supplied.
}
Exempel 2:
while (<FH>){
chomp($_); # $_ refers to the iterating lines in the loop.
}
Följande funktioner använder $_ som standardargument:
abs, alarm, chomp, chop, chr, chroot, cos, defined, eval,
evalbytes, exp, fc, glob, hex, int, lc, lcfirst, length, log,
lstat, mkdir, oct, ord, pos, print, printf, quotemeta, readlink,
readpipe, ref, require, reverse (in scalar context only), rmdir,
say, sin, split (for its second argument), sqrt, stat, study,
uc, ucfirst, unlink, unpack.
2. @_ : Den här arrayen innehåller argumenten som skickas till subroutine.
Exempel 1:
example_sub( $test1, $test2, $test3 );
sub example_sub {
my ( $test1, $test2, $test3 ) = @_;
}
I en @_ innehåller matrisen @_ argumenten som skickas till den subroutinen. Inuti en subrutin är @_ default för arrayoperatörens pop and shift .
Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow