On Sun, Aug 29, 2010 at 09:41, Kaushal Shriyan <[email protected]> wrote:
snip
> Thanks a lot Chas. Understood now.
> Also what does $_ default variable means exactly, any example would
> really help me understand it
snip
The default variable is set or read by many Perl 5 functions. For
instance, if you use the readline operator (<>) in a while loop's test
it sets $_ and print uses $_ if no arguments are passed to it, so
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
print;
}
__DATA__
foo
bar
baz
will print the lines "foo\n", "bar\n", and "baz\n". $_ is also the
default target for regexes, so
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>) {
next unless /b/;
print;
}
__DATA__
foo
bar
baz
Will print "bar\n" and "baz\n", but not "foo\n" because it does not
match the regex.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/