P
Paul E. Schoen
I am trying to understand scalar variables, and I found the following:
http://www.tutorialspoint.com/perl/perl_scalars.htm
Here is an excerpt:
#!/usr/bin/perl
$number = "5";
$exponent = "2 ** 8";
$string = "Hello, PERL!";
$float = 12.39;
# We can also assign a scalar an empty (undefined) value:
$nothing = undef;
# Printing all the above values
print "$number\n";
print "$exponent\n";
print "$string\n";
print "$float\n";
print "There is nothing: $nothing\n";
This will give following result
5
2 ** 8
Hello, PERL!
12.39
There is nothing:
My question is whether $number, $exponent, and $float are actually numbers
or character strings, particularly those that are enclosed in quotes. Thus,
what would be the result of:
$mynum = $number * $float;
print "$mynum";
print $mynum;
$mynum = 2 ** 8;
print "$mynum"
And what happens if you add characters and variables in a print statement?
print "This is a number$mynum2";
The information in the FAQ did not seem to address this except as follows:
my $string = '0644';
print $string + 0; # prints 644
print $string + 44; # prints 688, certainly not octal!
It seems like the printf and sprintf functions work as I would expect,
printf "0%o %d", $number, $number;
But what happens if you use the following:
$number = "0123";
$number = "A123";
$number = "one";
$number = 123;
$number = 123 + 4.56;
$number = "123 + 4.56";
$number = "123" + "4.56";
Sorry for the noobish questions, but I am used to C and Delphi Pascal,
where I am familiar with the syntax.
Thanks,
Paul
http://www.tutorialspoint.com/perl/perl_scalars.htm
Here is an excerpt:
#!/usr/bin/perl
$number = "5";
$exponent = "2 ** 8";
$string = "Hello, PERL!";
$float = 12.39;
# We can also assign a scalar an empty (undefined) value:
$nothing = undef;
# Printing all the above values
print "$number\n";
print "$exponent\n";
print "$string\n";
print "$float\n";
print "There is nothing: $nothing\n";
This will give following result
5
2 ** 8
Hello, PERL!
12.39
There is nothing:
My question is whether $number, $exponent, and $float are actually numbers
or character strings, particularly those that are enclosed in quotes. Thus,
what would be the result of:
$mynum = $number * $float;
print "$mynum";
print $mynum;
$mynum = 2 ** 8;
print "$mynum"
And what happens if you add characters and variables in a print statement?
print "This is a number$mynum2";
The information in the FAQ did not seem to address this except as follows:
my $string = '0644';
print $string + 0; # prints 644
print $string + 44; # prints 688, certainly not octal!
It seems like the printf and sprintf functions work as I would expect,
printf "0%o %d", $number, $number;
But what happens if you use the following:
$number = "0123";
$number = "A123";
$number = "one";
$number = 123;
$number = 123 + 4.56;
$number = "123 + 4.56";
$number = "123" + "4.56";
Sorry for the noobish questions, but I am used to C and Delphi Pascal,
where I am familiar with the syntax.
Thanks,
Paul