RE: reading perl variables from a separate file

by "Wiswell, Virginia" <Virginia.Wiswell(at)dowjones.com>

 Date:  Tue, 25 Jan 2000 16:23:55 -0500
 To:  "'Steve Segarra'" <ssegarra(at)mitre.org>,
hwg-techniques <hwg-techniques(at)hwg.org>
  todo: View Thread, Original
i do this all the time by 'require'ing the data file in the perl script.

so if you have

    @array1 = (0,0,0,0);
    @array2 = (1,1,1,1);
    ...
    @arrayN = (N,N,N,N);

in a file called data.txt, just put this line in the perl script where
you want the arrays to appear:

require 'path/to/data.txt';

the perl interpreter will insert

    @array1 = (0,0,0,0);
    @array2 = (1,1,1,1);
    ...
    @arrayN = (N,N,N,N);

directly in the script as if you had typed it there yourself. you
can manipulate the data anyway you want:

print "$array1[2]";

produces 

0

hth,

virginia
http://www.windvoice.com

> perl?  I know
> how to read the contents of a file, but is it possible to store the
> variables in a seperate file?  For example:
> 
> A file "data" contains:
>     @array1 = (0,0,0,0);
>     @array2 = (1,1,1,1);
>     ...
>     @arrayN = (N,N,N,N);
> 
> and the script would open this file and read the variables 
> from it, not
> read them as scalars.

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.