473,322 Members | 1,241 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,322 software developers and data experts.

retrieving data from array changes it???

Hi all,

just stumbeled over a strange behaviour of perl: When trying to
retrieve a non-existing value from a perl array, e.g. by saying

my $a = [1,2];
my $b = $$a[3][0];

then $a is modified to [1,2,[]].

Is this a feature I just don't understand or is it really a bug (as I
would suppose)?

Thanx in advance,

thoin
Jul 19 '05 #1
3 1464
thoin wrote:
just stumbeled over a strange behaviour of perl: When trying to
retrieve a non-existing value from a perl array, e.g. by saying

my $a = [1,2];
my $b = $$a[3][0];

then $a is modified to [1,2,[]].
Suppose you mean [1,2,undef,[]].
Is this a feature I just don't understand or is it really a bug (as
I would suppose)?


I think it's called autovivification. One place where it is commented
on is

perldoc -f exists

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<mK********************@newsb.telia.net>...
thoin wrote:
just stumbeled over a strange behaviour of perl: When trying to
retrieve a non-existing value from a perl array, e.g. by saying

my $a = [1,2];
my $b = $$a[3][0];

then $a is modified to [1,2,[]].


Suppose you mean [1,2,undef,[]].


Yes, of course I do mean that :-)
Is this a feature I just don't understand or is it really a bug (as
I would suppose)?


I think it's called autovivification. One place where it is commented
on is

perldoc -f exists


Phew, nice to see that it will be fixed in the future. I mean, nice to
see that I was right supposing this behaviour to be kind of wrong.

Thanks a lot for your hint!

Thoin
Jul 19 '05 #3
In article <94**************************@posting.google.com >, thoin
<ca******@web.de> wrote:
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message
news:<mK********************@newsb.telia.net>...
thoin wrote:
just stumbeled over a strange behaviour of perl: When trying to
retrieve a non-existing value from a perl array, e.g. by saying

my $a = [1,2];
my $b = $$a[3][0];

then $a is modified to [1,2,[]].


Suppose you mean [1,2,undef,[]].


Yes, of course I do mean that :-)
Is this a feature I just don't understand or is it really a bug (as
I would suppose)?


I think it's called autovivification. One place where it is commented
on is

perldoc -f exists


Phew, nice to see that it will be fixed in the future. I mean, nice to
see that I was right supposing this behaviour to be kind of wrong.

Thanks a lot for your hint!

Thoin


The only thing "perldoc -f exists" says might be fixed in the future is
that "exists $$a[3][0]" may not create $$a[3] if it doesn't already
exist. The statement "$b = $$a[3][0]" will definitely create $$a[3] if
it doesn't exist now and forever more in the future.

FYI: this newsgroup is defunct. Please try comp.lang.perl.misc in the
future.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
6
by: Belmin | last post by:
I have an array. The array key is the id of the item (for example categories, 91 is the ID of the category) all ID are not exactly in date order, but they're added to the array in date order, how...
0
by: VM | last post by:
In my Windows application, I load an ascii file into a tableX and set the datagrid.DataSource = tableX. The problem begins when I try to retrieve the data from the grid in order to process the...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
2
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. ...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
9
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows()...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.