470,619 Members | 1,863 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,619 developers. It's quick & easy.

lost array element in 5.8

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"

Jul 19 '05 #1
2 1724
Farhad <fa************@dresdner-bank.com> wrote:
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.

--
Steve
Jul 19 '05 #2
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

"Farhad" <fa************@dresdner-bank.com> wrote in message news:<bk*********@news-1.bank.dresdner.net>...
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"

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jacob | last post: by
13 posts views Thread by Jean Pierre Daviau | last post: by
3 posts views Thread by windandwaves | last post: by
reply views Thread by silvrique | last post: by
4 posts views Thread by Ole | last post: by
3 posts views Thread by c++dummy | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.