Home > Archive > PERL Beginners > March 2004 > Re: Execute include and return variables
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Execute include and return variables
|
|
| Alok Bhatt 2004-03-30, 9:36 am |
|
> Hi all:
Hi Tomas,
> I cannot include a file so it can return all the
> variables I assigned.
> #FILE1.pl
> $var1= "tom";
> #FILE2.pl
> do FILE1.pl
> #open $prog,'FILE1.pl' or die $!,
> #use 'FILE1.pl'
> #import 'FILE1.pl'
In FIle2:
do "FILE1.pl" (use double quotes)
If you want to use "use <xxxx>", rename xxxx to
file1.pm and use "use file1", instead of "use
file1.pm".
Hope that helps.
:-)
Alok
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html
| |
| R. Joseph Newton 2004-03-30, 10:36 am |
| Alok Bhatt wrote:
> Hi Tomas,
>
> In FIle2:
> do "FILE1.pl" (use double quotes)
>
> If you want to use "use <xxxx>", rename xxxx to
> file1.pm and use "use file1", instead of "use
> file1.pm".
>
> Hope that helps.
> :-)
> Alok
There is a larger conceptual issue here. I think the OP is starting out on the
wrong track with this approach. Declaring variables in remote files is just not
a good idea. Perl has evolved, and evolved much better ways to handle
containment.
I would ask what purpose is he trying to achieve by doing this.Generally, when
people declare variables in included files, they are trying to create global
variables. I think it is better to steer him towards safer ways of sharing data
between parts of a program.
Besides, double quotes are not neccesary:
rags.pl:
#!perl -w
$badly_named_variable = 5;
Greetings! E:\d_drive\perlStuff>perl
do 'rags.pl';
print "$badly_named_variable\n";
^Z
5
Though you could not get away with junk like this using strict.
Joseph
| |
| R. Joseph Newton 2004-03-30, 11:32 am |
| Tomas Corral wrote:
> Hi all:
Hi Tomas,
Please start a new message to the group when you have a new subject. Your
message was lost in a thread concerning Network Shiffer Modules.
>
>
> I cannot include a file so it can return all the variables I assigned.
>
> #FILE1.pl
> $var1= "tom";
>
> #FILE2.pl
> do FILE1.pl
> #open $prog,'FILE1.pl' or die $!,
> #use 'FILE1.pl'
> #import 'FILE1.pl'
>
> print("var1=$var1");
>
> I hanged arround perldoc perlfunc and google and... I guess I need help
Don't do this. This is not a productive use for your efforts. If you explain
why you would want to declare a variable in some other file, we can point you
toward better ways to accomplish your purpose.
Joseph
|
|
|
|
|