From:                   Ben Curran <[EMAIL PROTECTED]>

> Trying to alter the value of $testfile depending on how many arguments
> are given, using the following:
> 
> if (@ARGV == 2) {
> chdir $ARGV[0];
> my $testfile = $ARGV[1];
> }
> else {
> my $testfile = $ARGV[0];
> }
> 
> 
> I figured out what was wrong, i.e. I can't use my $testfile within the
> if, giving me :
> 
> my $testfile;
> if (@ARGV == 2) {
> chdir $ARGV[0];
> $testfile = $ARGV[1];
> }
> else {
> $testfile = $ARGV[0];
> }
> 
> which works. 
> 
> Why though? Isn't the first complitation run through the script by the
> interpreter, a syntax check? why would it pick up my $tesfile twice?

The 
        my $variable;
declares the $variable to be "local" to the current BLOCK. Now the 
syntax of the if statement is

        if ( condition ) BLOCK else BLOCK

So if you declare a variable in one of those blocks it EXISTS only in 
that block. Not elsewhere.

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
                                        --- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to