Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!elroy.jpl.nasa.gov!usc!isi.edu!venera.isi.edu!jas From: jas@ISI.EDU (Jeff Sullivan) Newsgroups: comp.lang.perl Subject: Learning perl -- generlized file loading w/var assignment Message-ID: <16785@venera.isi.edu> Date: 15 Feb 91 19:04:40 GMT Sender: news@isi.edu Distribution: comp Organization: USC-ISI Lines: 70 I'm just learning perl, and in doing so, am trying to put together the beginnings of a project that will be a kind of parser/server. To that end, I have created a set of files which each contain a list of commands or terms which I want the user to be able to abbreviate. I then want to be able to read in this list of files and assign each file its own associative array filled out by abbrev.pl. However, my test doesn't seem to work. Here's a sample of the code: #!/usr/bin/perl # Load abbreviation package require "abbrev.pl"; #Set abbreviation eval line (run for each abbr file.). #$filestub will be set to the root of the file name, which is always #of the form -LIST. $eval_line = "%$filestub = ();\n&abbrev(*$filestub, @tmp);\n"; #Alternative method to set eval_line. #$eval_line = <<'End_of_Eval_Line'; #%$filestub = (); #&abbrev(*$filestub, @tmp); #End_of_Eval_Line #Load abbreviation files. foreach $filename ("ATTR-LIST", "HELP-LIST", "TYPE-LIST", "CMD-LIST") { # Open the file for input open(TMP, "$filename") || die "Can't load $filename: $!"; $filename =~ /(\w+)-LIST/; $filestub = $1; #Slurp in the whole file, one line per element of @tmp @tmp = ; # close the file close TMP; #Initialize the associative array. %abbr = (); #Fill in the array of abbreviations. eval $eval_line; } while (<>) { chop; $long = $cmd{$_}; print "$long\n" if length($long); } The last bit is pulled vrom the example using abbrev.pl. The $cmd{} array (should) be created by the eval_line when $filename is "CMD-LIST" and $filestub is "CMD". Right? jas -- -------------------------------------------------------------------------- Jeffrey A. Sullivan | Senior Systems Programmer jas@venera.isi.edu | Information Sciences Institute jas@isi.edu | University of Southern California