Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-12-04 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (25 votes). Check out past polls.

    Notices?