Kind Monks,

I've read the chapters on this in Beginning Perl and some of the tutorials on this site, but I'm just not getting it. I need to use an external file as a lookup table. It's a simple hash. No subroutines, just the hash. When I turn Off "use strict;" in my main program, it runs and returns values for me. But not using strict is Bad and Evil and I want to do this right. More importantly, I want to understand why it's right and where I can go to read more until the light does come on. Looking at the examples I can find, they all seem to be Object Oriented, focusing on using subroutines, and much more complex than this simple thing I'm trying to do.

Here's my program:

#! /usr/bin/perl use strict; use warnings; require "/usr/local/include/dpcs_stdlib.pl"; require "/usr/local/include/dpcs_delim.pl"; use lookup; open INFILE, "rentroll.txt" or die "Could not open rentroll.txt $!"; open OUTFILE, ">parsed.rnt.txt" or die "could not open parsed.rnt.txt +for write $!"; my $line= q{}; my @Page = (); #my $lastLine = q{Ending Balance:}; #my $new_rec = 0; #my $cnt = 0; #my (@pos_nums, @neg_nums); while ($line = <INFILE>) { chomp $line; push @Page, $line; if ($line =~/^Development:/) { my $devel = substr($line,13); print OUTFILE "Development = $devel\n"; my $check = $devel_table{$devel}; print OUTFILE "check = $check\n"; if ($check =~ "M") { print OUTFILE "Middletown\n"; } elsif ($check =~ "H") { print OUTFILE "Hamilton\n"; } else { print OUTFILE "Community not in lookup table\n"; } } #last if ($line =~ /$lastLine/); }

And my lookup.pm:

#!/usr/bin/perl use strict; use warnings; #require Exporter; #our %devel_table; #our @EXPORT = qw(%devel_table); #our @ISA = qw(Exporter); our %devel_table; %devel_table = ("Townhomes West" => "M", #lots more values in here, of course "Winding Creek Family" => "H", "Dayton Lane Gardens" => "H"); 1;

The error I get when I turn strict on in the main program is this:

Variable "%devel_table" is not imported at .//sopw.pl line 29. Global symbol "%devel_table" requires explicit package name at .//sopw +.pl line 29. Execution of .//sopw.pl aborted due to compilation errors.

I believe it has something to do with how I'm not exporting the information correctly, but as I said, the only examples I find are for exporting subroutines, not a hash by itself. Having the lines above commented in or out makes no difference to how the program runs, with or without strict.

Thanking you in advance for leading me back to the right path,
NovMonk


In reply to Understanding using external program data by NovMonk

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.