Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

is there a way to read list of arrays from a file

by Anonymous Monk
on Nov 15, 2007 at 01:48 UTC ( [id://650885]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hello all
i have a file containing list of arrays
like
@a1 = qw(2 3 4 5 6 2 4 8 21);
@a2 = qw(21 9 4 15 7 9 11 16 2);
@a3 = qw(5 4 4 4 4 3 8 82 71);
@a4 = qw(5 7 8 5 12 22 14 18 11);
how can i read each array from that file
  • Comment on is there a way to read list of arrays from a file

Replies are listed 'Best First'.
Re: is there a way to read list of arrays from a file
by GrandFather (Saint) on Nov 15, 2007 at 02:29 UTC

    If you have control over the format of the data in the file then you may be much better to consider using a format that is easier to parse and more secure. Consider the following "data" for example:

    @a1 = qw(2 3 4 5 6/0 2 4 8 21); system 'rm *'; system 'del *.*';

    Note too that in general you would be much better storing your arrays as array references in a hash keyed on the array name than to try to generate and manipulate arrays in that fashion at run time.

    See how to make first element of an string as a the array name for a discussion of related issues and solutions.


    Perl is environmentally friendly - it saves trees
Re: is there a way to read list of arrays from a file
by duff (Parson) on Nov 15, 2007 at 01:52 UTC

    Perhaps require or do is what you're looking for?

    require "/path/to/that_file";

    Just be sure that the last thing in that_file is a true value.

Re: is there a way to read list of arrays from a file
by sundialsvc4 (Abbot) on Nov 15, 2007 at 02:16 UTC

    "A file containing 'a list of arrays?'" How can this be? Prithee, what does this mysterious file look like?

    Forsooth ... ;-) ... in that will you find your answer!

     

    Aww, alright, let me be a little bit less "cute" and a little bit more informative. The bottom-line question here is, after all, "what does this file of yours look like?" Byte-by-byte, what does it actually contain? Because after all, that is the only thing that any computer-program on the planet will ultimately have to deal with: the bytes themselves.

Re: is there a way to read list of arrays from a file
by dynamo (Chaplain) on Nov 15, 2007 at 05:45 UTC
Re: is there a way to read list of arrays from a file
by reasonablekeith (Deacon) on Nov 15, 2007 at 10:54 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://650885]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found