Relevant code snippets:
use strict; use warnings; ... foreach my $date (@dates) { foreach my $line (@{$maint_hash{$address}}) { my (@alljobs,@alljobids,@received); my %rtoa; runsingle($line,$date,\*OUT); } } ... } sub runsingle { ... some code that actually populates the declared variables... printjob($fh,$h,@foo); ... } sub printjob { my $fh=$_[0]; my $h=$_[1]; shift @_; shift @_; foreach my $key (@_) { print $fh $h->open('tr'); my $key2=$rtoa{$key}; print $fh $h->td(${$alljobs[$key2]}[2],${$alljobs[$key2]}[3],${ +$alljobs[$ key2]}[4]); my ($chopdate,$choptime,$junk)= split " ",${$received[$key]}[4] +; $chopdate=~s/-201.//; print $fh $h->td("Ran at $choptime",$chopdate,${$received[$key] +}[3]); print $fh $h->close('tr'); } print $fh $h->close('table'); }

When I run this code, it complains that global symbols "%rtoa" and "@alljobs" require an explicit package name. The complaints are coming from inside the printjob subroutine. The variables are declared with "my" in the inner loop inside the main program, which means that their scope is limited to that inner loop. The ONLY place runsingle is called from is inside that inner loop, and the ONLY place printjob is called from is inside runsingle, so I'd think both printjob and runsingle should see those variables as "global".

Moving the declaration inside the runsingle subroutine doesn't change the behavior.

I don't understand why it's complaining. Would some kind soul explain it to me, please?

I could get around the error by passing those arrays and hashes as parameters... but as you can see from the printjob code, the arrays are actually multidimensional, so the resulting code would be hairy and hard to maintain.

UPDATE: nevermind, got it to work by declaring the variables inside a block that contains both subroutines. It's not elegant, but it'll do.


In reply to Global symbol requires explicit package name by cunningrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.