R
Rahul
Greetings,
In a loop if I use 'print "sth", next;', only next is executed and
"sth" is not printed. However when I use 'print ("sth"), next;', "sth"
is printed as expected but with a warning stating that print was
interpreted as a function. My question is : when i use the former style
of calling the print function why does it not print "sth"?
perldoc perlfunc mentioned that print returns a boolean value. Why does
the print "sth" statement fail to execute when I use a ',' and a 'next'
after it?
my test script is as follows
#!/usr/bin/perl
use strict;
use warnings;
my $result = 0;
for (1..10){
print "$result ";
#$result = print ("$_ "), next; #prints 1 1 1 2 1 3... as expected
$result = print "$_ ", next; #prints 0 0 0 0 0 0... why?
}
TIA.
regards,
rahul
In a loop if I use 'print "sth", next;', only next is executed and
"sth" is not printed. However when I use 'print ("sth"), next;', "sth"
is printed as expected but with a warning stating that print was
interpreted as a function. My question is : when i use the former style
of calling the print function why does it not print "sth"?
perldoc perlfunc mentioned that print returns a boolean value. Why does
the print "sth" statement fail to execute when I use a ',' and a 'next'
after it?
my test script is as follows
#!/usr/bin/perl
use strict;
use warnings;
my $result = 0;
for (1..10){
print "$result ";
#$result = print ("$_ "), next; #prints 1 1 1 2 1 3... as expected
$result = print "$_ ", next; #prints 0 0 0 0 0 0... why?
}
TIA.
regards,
rahul