FyD wrote:
Dear All,

I have two perl scripts: - The first one:
sub Tt {
$TTT = uc($TTT); if(($TTT ne "ON") && ($TTT ne "OFF")){ print "ERROR: Check variable TTT";} else { print "It is a Test...";} } # ---MAIN---
$TTT = "OFF";
Tt();


If I use  $TTT = "OFF", I get 'It is a Test...' and if I use $TTT="O" I get
'ERROR: Check variable TTT'. This, it is normal for me.

- The second script using 'strict' this time:
use strict;
sub Tt {
my $TTT; $TTT = uc($TTT); if(($TTT ne "ON") && ($TTT ne "OFF")){ print "ERROR: Check variable TTT";} else { print "It is a Test...";} }
# ---MAIN---
my $TTT = "OFF";
Tt();


If I use $TTT = "OFF" I get time 'ERROR: Check variable TTT', Why ?

Thanks, Francois


Because $TTT is undef. When you declare $TTT i Tt perl creates a new variable and hides away the $TTT from the "main" part of your script to be restored when Tt returns.

Change 'my $TTT;' in Tt to my '$TTT = shift;' and call Tt like this 'Tt($TTT)'.

You should *always* use, use strict;.

--
Flemming Greve Skovengaard            The killer's breed or the Demon's seed,
a.k.a Greven, TuxPower                The glamour, the fortune, the pain,
<[EMAIL PROTECTED]>           Go to war again, blood is freedom's stain,
4112.38 BogoMIPS                      Don't you pray for my soul anymore.


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to