perl notes

From thelinuxwiki
Jump to: navigation, search

variables

local

my $color='green';

global

our $color='purple';

interpolation

double yield get the value of a variable, single quotes treat variable names as text

my $amount = 20;
print "$amount\n";
print '$amount\n';

output

20
$amount\n

strings

useful Perl string functions

lc	Returns a lowercase version of string
length	Returns the number of characters of a string
sprintf Formats string to be used with print()
substr	Gets or modifies a substring in a string
uc	Returns the uppercase version of the string

examples...

length

length("hahahalol")

8

case change (uc or lc) print(uc("foo bar"),"\n") FOO BAR