Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Reference to a single array item in an array of hashes?

by tedrek (Pilgrim)
on Apr 05, 2004 at 23:10 UTC ( #342784=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Reference to a single array item in an array of hashes?
in thread Reference to a single array item in an array of hashes?

I fixed a few things. But you shouldn't be getting that error unless you are trying to use $job outside of the loop.

I tried to swear at perl and it compiled!
  • Comment on Re: Re: Re: Reference to a single array item in an array of hashes?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Reference to a single array item in an array of hashes?
by ogxela (Novice) on Apr 05, 2004 at 23:19 UTC

    Teach me not to list enough code. It's actually erroring a little later in the loop. Here's the full loop:

    my $i = 0; my @jobTimes = ('') x $numTimes; #initialize array foreach my $job (@jobTimes) { $job = { start => param("JobStart$i"), end => param("JobEnd$i"), }; $job{'start'} =~ s/^0+//; $job{'end'} =~ s/^0+//; $i++; }

    It's giving the "Global Symbol "%job" requires explicit package" error on the regexpen.

    --Alex

      Ah yes that would explain it. $job is a scalar variable holding a reference to the hash, as such you need to dereference it when accessing a specific field of the hash. Like so $job->{start} =~ s/^0+//;


      HTH
      I tried to swear at perl and it compiled!

        Thanks, that worked. I've only recently had to start using references in my code, so I apprectiate your help.

        --Alex

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-09-27 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?