Perl Programming

CSE3395




Scalar Values


E-mail this post



Remember me (?)



All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...



In perl, you don't need to initialise and even declare variables.

Typing is relaxed and late bound.
There is a special value 'undefined' undef

Scalar variables must start with a $
$apples
$text2
$_ <- a variable you don't have to assign it to anything, but you can always find the result of the last thing that happened.
One of the most elegant features of the language?

Perl doesn't usually care if a scalar contains a number or a string.

"cat" . "fish" produces "catfish"

> and gt test for 'greater than' in scalars. One for numbers, one for strings.

String literals
Double quotes "blah" - delimited. Usual C backslash rules apply.
In double quotes "hello $name", $name is a variable.

single 'blah'
variables do not interpolate.

Turns out this is useful

print "The sum is $total\n";
subs the current value for total.

print "today is the ${day}th\n";

undef is neither number nor string.

$line = ;
chomp $line;

and now it's in the $_ variable.

False
undef
""
0

True
everything else

if(){}
elsif(){}
else{}

Standard way of processing a text screen

while (defined ($input = ))
{
chomp $input;
push @lines, $input;
}

unless and untill IS THE SAME AS
if(!condition) and while(!condition)

last
next
redo


0 Responses to “Scalar Values”

Leave a Reply

      Convert to boldConvert to italicConvert to link

 


Previous posts

Archives

Links