http://qs1969.pair.com?node_id=324694


in reply to Re: Re: Variable declaration on one line
in thread Variable declaration on one line

I'm assuming you mean: my $var = ''; and my $var; In the first example you declare the scalar variable and initialize it to the empty string. In the second example you only declare the scalar variable.

There is not one specific type set to the scalar (i.e. integer, character, etc.). Perl figures out what you want based on the context of use.

use strict; use warnings; my ($i, $j) = (1, 2); my $k = ''; print $i + $j ."\n"; print $i + $k ."\n";
The first print statement adds the two values and it is easy to see this because they are both integers at that point. The second print statement will convert $k to a number and then add $i. Since you are using $k in an arithmetic operation, Perl knows that $k should be a number. Perl is very context sensitive. It is very important to learn how things behave in different contexts.

Replies are listed 'Best First'.
Re: Re: Re: Re: Variable declaration on one line
by Anonymous Monk on Jan 28, 2004 at 17:16 UTC
    Wow, thanks for all the info!