Programming Fundamentals/Variables/Perl: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 04:02, 21 November 2016

variables.pl

print "Variables and Data Types\n";
$i = 12345;
$f = 1.23456789012345;
$s = "string";

print "int: $i\n";
print "float: $f\n";
print "string: $s\n";
print "\n";

print "Constants\n";
print "Perl doesn't support constants.\n";
print "\n";

print "Arithmetic Operators\n";
$a = 3;
$b = 2;
print "a = $a\n";
print "b = $b\n";
print "a + b = " . ($a + $b) . "\n";
print "a - b = " . ($a - $b) . "\n";
print "a * b = " . ($a * $b) . "\n";
print "a / b = " . ($a / $b) . "\n";
print "\n";

print "Assignment Operators\n";
$a += $b;
print "a += b is $a\n";
$a -= $b;
print "a -= b is $a\n";
$a *= $b;
print "a *= b is $a\n";
$a /= $b;
print "a /= b is $a\n";
print "\n";

print "String Concatenation\n";
$s1 = "Hello";
$s2 = "world";
print $s1 . " " . $s2 . "!\n";
print "\n";

print "User Input\n";
print("What is your name? ");
$name = <STDIN>;
chomp($name);
print "Hello $name!\n";

Try It

Copy and paste the code above into one of the following free online development environments or use your own Perl compiler / interpreter / IDE.

See Also