Unable to change a variable (newbie)

  • Thread starter Orest Kinasevych
  • Start date
O

Orest Kinasevych

I have three perl CGI scripts that successfully pass variables to each
other.

In one of the scripts I created a variable ($user_dir) that contains the
name of a temporary directory that one of the other scripts will create.

I would like to name that directory after the session ID that was passed
from the PHP page that called the CGI. Something like this:


$user_dir = "/tmp/".$sessionid;


But that isn't working at all. What is working is this
("0688b79939fdeb65effac2314a1f934e" being my current session ID):


$user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e";


Meaning that the value of $user_dir is indeed passed to the script that
creates the directory and that script correctly creates the directory
named "/tmp/0688b79939fdeb65effac2314a1f934e".

However, when I try to set the variable as shown earlier:


$user_dir = "/tmp/".$sessionid;


the variable $user_dir doesn't appear to be set, that is, the script
that creates the directory doesn't create one at all.

Testing $sessionid == "0688b79939fdeb65effac2314a1f934e" evaluates to
true. If I do a print $user_dir, $user_dir shows the expected value.

I am fairly adept at PHP but am a Perl newbie. I'm guessing that there
might be something here having to do with "pass-by-reference" (from what
I've gleaned from online documentation) but I can't quite figure it out.



A few more details:

The $user_dir variable assignment occurs within header.cgi. header.cgi
is called from upload.cgi and progress.cgi using a require statement:

require ("./header.cgi");

Bottom line is this:

a) if ($sessionid == "0688b79939fdeb65effac2314a1f934e") # evaluates to true

b) $user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e" # works when used
to create a directory by that name

c) $user_dir = "/tmp/".$sessionid # does not work


One last piece of info:

The set of statements used to create the directory looks like this:

unless (-d "$user_dir")
{
mkdir ("$user_dir", 0777);
chmod (0777, "$user_dir");
}



Thanks for any assistance/tips/pointers!

- Orest
 
A

Andrew Perrin

Orest Kinasevych said:
[snip]
I would like to name that directory after the session ID that was
passed from the PHP page that called the CGI. Something like this:


$user_dir = "/tmp/".$sessionid;

Just FYI, there's no need for the concatenation; you can use:

$user_dir = "/tmp/$sessionid";
But that isn't working at all. What is working is this
("0688b79939fdeb65effac2314a1f934e" being my current session ID):


$user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e";


Meaning that the value of $user_dir is indeed passed to the script
that creates the directory and that script correctly creates the
directory named "/tmp/0688b79939fdeb65effac2314a1f934e".
Correct.


However, when I try to set the variable as shown earlier:


$user_dir = "/tmp/".$sessionid;


the variable $user_dir doesn't appear to be set, that is, the script
that creates the directory doesn't create one at all.

Testing $sessionid == "0688b79939fdeb65effac2314a1f934e" evaluates to
true.

Irrelevant, since the == operator is testing for numerical
equality. Try $sessionid eq "0688b79939fdeb65effac2314a1f934e".
If I do a print $user_dir, $user_dir shows the expected value.

Tehn why do you say above that $user_dir doesn't appear to be set?
Clearly it is getting set, and your problem lies elsewhere.
[snip]
Bottom line is this:

a) if ($sessionid == "0688b79939fdeb65effac2314a1f934e") # evaluates to true

b) $user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e" # works when
used to create a directory by that name

c) $user_dir = "/tmp/".$sessionid # does not work

Something else is wrong, assuming a) is still true when you use eq
instead of ==. Once $user_dir is correctly set, there's no difference
between the two forms.
 
O

Orest Kinasevych

[snip]
I would like to name that directory after the session ID that was
passed from the PHP page that called the CGI. Something like this:


$user_dir = "/tmp/".$sessionid;


Just FYI, there's no need for the concatenation; you can use:

$user_dir = "/tmp/$sessionid";

But that isn't working at all. What is working is this
("0688b79939fdeb65effac2314a1f934e" being my current session ID):


$user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e";


Meaning that the value of $user_dir is indeed passed to the script
that creates the directory and that script correctly creates the
directory named "/tmp/0688b79939fdeb65effac2314a1f934e".

Correct.


However, when I try to set the variable as shown earlier:


$user_dir = "/tmp/".$sessionid;


the variable $user_dir doesn't appear to be set, that is, the script
that creates the directory doesn't create one at all.

Testing $sessionid == "0688b79939fdeb65effac2314a1f934e" evaluates to
true.


Irrelevant, since the == operator is testing for numerical
equality. Try $sessionid eq "0688b79939fdeb65effac2314a1f934e".

If I do a print $user_dir, $user_dir shows the expected value.


Tehn why do you say above that $user_dir doesn't appear to be set?
Clearly it is getting set, and your problem lies elsewhere.

[snip]
Bottom line is this:

a) if ($sessionid == "0688b79939fdeb65effac2314a1f934e") # evaluates to true

b) $user_dir = "/tmp/0688b79939fdeb65effac2314a1f934e" # works when
used to create a directory by that name

c) $user_dir = "/tmp/".$sessionid # does not work


Something else is wrong, assuming a) is still true when you use eq
instead of ==. Once $user_dir is correctly set, there's no difference
between the two forms.

Thanks -- you confirmed what I thought was the case and helped me
clarify the question for myself.

Although progress.cgi and upload.cgi each call header.cgi, they do so
separately and the $sessionid variable is set separately within each of
them. That means that header.cgi gets a different $sessionid value from
progress.cgi than it does from upload.cgi -- my print $user_dir;
statement was occurring within progress.cgi (showing me correct values)
while $upload.cgi was providing an incorrect value to header.cgi.

(Nothing like a pad of paper to help figure out the sequence!)

Thanks again.

- Orest
 

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
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top