Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: accessing data structure

by jbert (Priest)
on Nov 16, 2007 at 13:42 UTC ( [id://651197]=note: print w/replies, xml ) Need Help??


in reply to accessing data structure

As well as reading up on references, please make your code run under use strict; and use warnings;.

This would have been useful in this case because you would have got the warning:

Global symbol "@results" requires explicit package name at - line 2.
which would have given you a hint that you had messed up, writing @{results} instead of @{$results} (or just @$results).

strict and warnings are really useful and save a lot of time for you and for people answering questions, too.

Replies are listed 'Best First'.
Re^2: accessing data structure
by CColin (Scribe) on Nov 16, 2007 at 14:34 UTC
    Hi, I had read up on references and also had strict and warnings on. I don't take posting to this august list so lightly, but references aren't so easy in Perl, at any rate that's the way it is for me. Never attribute to indolence what can first be explained by ignorance... Thanks anyway to the person who spotted the issue.
      Sorry if I seemed rude, I didn't mean to cause any offence.

      My reference to references (ha!) was in the context of the previous reply. I hope that helps change the tone a little (without that, it does seems ruder to me).

      I don't understand how you got the results you did with strict on, this code fails to execute for me (compilation error):

      #!/usr/bin/perl use strict; my @dereferenced_array = @{results}; print "not reached\n"; # doesn't execute
      perl 5.8.8, linux.
        No offence taken. As for reproducing the error, I was getting all sorts of warnings on different iterations of trying different ways of dereferencing, didn't reproduce them since I knew there was something basic I was not doing but couldn't spot it despite several hours staring at it - luckily it was spotted quickly by you good monks. You're right I should have been fuller in the reply and included error messages also.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://651197]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-25 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found