Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > retrieving data from array changes it???

Reply
Thread Tools

retrieving data from array changes it???

 
 
thoin
Guest
Posts: n/a
 
      03-01-2004
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
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-01-2004
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

 
Reply With Quote
 
 
 
 
thoin
Guest
Posts: n/a
 
      03-02-2004
Gunnar Hjalmarsson <> wrote in message news:<mKK0c.50876$>...
> 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
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      03-02-2004
In article < >, thoin
<> wrote:

> Gunnar Hjalmarsson <> wrote in message
> news:<mKK0c.50876$>...
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving and copying element from array Simon Harrison Ruby 10 01-15-2011 03:36 PM
Using/retrieving the internal array of elements from a vector Vince C. C++ 3 07-16-2007 09:56 PM
Data/File Structure and Algorithm for Retrieving Sorted Data Chunk Efficiently Jane Austine Python 14 10-09-2004 05:54 PM
- Re: Data/File Structure and Algorithm for Retrieving Sorted Data Chunk Efficiently Jane Austine Python 2 10-05-2004 01:54 PM
reload SQL Data when Data Changes Chris Coho, Jr ASP General 0 07-14-2003 08:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57