in reply to 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?

Using that code gives an error "Global symbol "$job" requires explicit package name".

I tried changing it to this:

foreach my %job (@jobTimes)
but it didn't like that either. Syntax error.

Replies are listed 'Best First'.
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

    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!

      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!