Including files (again)

  • Thread starter Marie-Régine SAPIR
  • Start date
M

Marie-Régine SAPIR

Hi,

I've read the perl monks tutorial on including files and I think I understood most of it. But I would still like to include a file, so I'm going to ask anyway ;-)

The file I'd like to include is sort of like an argument to the script - there are a whole bunch of them and I'd I like to be able to say:
$ my-script.plx <file> <more arguments>
(Or more likely, in the shell:
$ for i in *some-pattern* ; do my-script.plx $i <further args> ; done)

Usually when I do this the file is very simple, but in this case it has structure, so I coded that in perl like:

%hash1 = (fruits => ["apple", "pear"],
things => ["table", "chair"]
);

%hash2 = (fruits => ["pear", "banana"]
countries => ["Turkey"]
);

Using pure text and parsing it with split,... instead of Perl code seems like quite a hassle I'd like to avoid.

Is there any way to do this in Perl? The one thing I didn't understand is what "eval" does, and I couldn't get the syntax right. Does anyone have a hint for me?

I'd also welcome ideas on how to re-design this, if it's the case that I'm being blind as to a much easier way ;-)
 
T

Tad J McClellan

%hash1 = (fruits => ["apple", "pear"],
things => ["table", "chair"]
);

%hash2 = (fruits => ["pear", "banana"]
countries => ["Turkey"]
);

Using pure text and parsing it with split,... instead of Perl code seems like quite a hassle I'd like to avoid.

Is there any way to do this in Perl?


perldoc -q persist

How do I keep persistent data across program calls?

The one thing I didn't understand is what "eval" does


There are 2 wildly different Perl functions that are both named "eval".

The first question to answer is whether we are discussing "eval block"
or "eval string"...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top