lost array element in 5.8

F

Farhad

Hi,

in the following example there is a output difference in version 5.00 and
5.8 of Perl. In case of a missmatch in element 2, the whole element gets
lost instead of an "undef" value. Does anybody know why in version 5.8 we
lost the element and is that an error in Perl interpreter or does it work as
designed.

Thanks
Farhad

----------------------------------

#!/usr/local/bin/perl -w

my $var="Test";
my @list=('a', # Element 1
$var=~m/\n/, # Element 2
$var=~m/es/ # Element 3
);

print scalar(@list)." (should be 3)\n";

push @list, {
'd' => $var=~m/\n/, # Element 4
};


print scalar(@list)." (should be 4)\n"
 
S

Steve Grazzini

Farhad said:
my $var="Test";
my @list=('a', # Element 1
$var=~m/\n/, # Element 2
$var=~m/es/ # Element 3
);

print scalar(@list)." (should be 3)\n";

No, it should be 2. m// in list context returns an empty list when
the match fails.
 
J

Jim

Hi Farhad,

i believe 5.8 works as designed.

try running your script in the debugger:
perl -d yourscriptname.pl

step through the commands using s, the first time, then return.

in the debugger, try:
p $var =~ /\n/
and
p $var =~ /es/

also, play with:
x @list

i do not see why $var would match a newline.

hope this helps, good luck.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top