473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1786
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jacob | last post by:
I just wrote a function that draws a fractal by recursively calling itself, and ran into an odd (odd from my point of view anyway) problem. I've managed to solve (or rather, circumnavigate) the...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
13
by: Jean Pierre Daviau | last post by:
I am a newbe not only in C but in programming. I am actually reading K&R. This is why I tried to run your application. It seems not to be running on my system. There is maybe a copy/paste...
3
by: windandwaves | last post by:
Hi Folk I have the following array: $m = array(); $m = array("lodgings", "rooms"); $m = array("location", "there and away"); $m = array("functions", "events and groups"); $m =...
0
by: silvrique | last post by:
I am totally lost. I have an xml script example as follows: <?xml version="1.0" encoding="utf8" ?> <starter> <second> <name>Silver</name> </second> </starter>
4
by: Ole | last post by:
Hi there, I think I'm lost in the XML attribute jungle in my attempt to serialize/deserializing data that must be persistant, and any help is highly appriciated. I need to save this class in...
3
by: c++dummy | last post by:
I got this project for my class and I'm totally lost as to how to copy the 1d array with the bone name into a 2d array using this supposed strncpy function I'm supposed to create. I believe the...
2
by: vunet.us | last post by:
Please, explain an interesting phenomenon, if you can. I have an array of references to an HTML element: <div id='container'> <div id='someId1'></div> <div id='someId2'></div> </div> ........
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.