View Full Version : Passing Variables.....
How can i pass a variable from 1.pl to 2.pl.????
the 1.pl code is:
$tim = "hello";
print "<a href='2.pl'>2.pl</a>";
and 2.pl code is:
print "$tim";
I would like to pass $tim to 2.pl
How can i do this WITHOUT a form?
chrisvmarle
11-19-2002, 09:10 AM
You could write it to a file and then read it from that file again.
If you have multiple users using these perlscripts you probably want to give them an unique id and write the variables to a file with their unique id.
Mzzl, Chris
Mouldy_Goat
11-20-2002, 12:14 AM
You can pass the variable around in the url, as in:
$tim = "hello";
print "<a href='2.pl?$tim'>2.pl</a>";
And then in 2.pl:
$tim = $ENV{'QUERY_STRING'};
print $tim;
Normally though the normal way of passing data around is through cookies or hidden form fields. Writing data to a file when it's only something temporary that you want to be available to multiple scripts isn't always a great idea. For instance, what if in between accessing 1.pl and 2.pl a different user comes along and accesses 1.pl - the information in 1.pl will be overwritten. As chrisvmarle says, you can get round this, but then your going out of your way for a problem which needn't exist.
However, it all depends on what exactly you're trying to do. Here I think I'd use a hidden form field, or add it to the URL of the 2.pl link. Just an idea, there's loads of ways to do it.
Hope that helps.
I shall go with the first post.
But is there a way that i can delete the file after 30minutes????
Any help will be appretiated
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.