Difference between revisions of "perl notes"
From thelinuxwiki
(Created page with "==variables== local <source lang="python">my $color='green';</source> global <source lang="python">our $color='purple';</source> <source lang="python"></source>") |
|||
(3 intermediate revisions by one user not shown) | |||
Line 6: | Line 6: | ||
global | global | ||
<source lang="python">our $color='purple';</source> | <source lang="python">our $color='purple';</source> | ||
+ | |||
+ | ===interpolation=== | ||
+ | double yield get the value of a variable, single quotes treat variable names as text | ||
+ | <source lang="python"> | ||
+ | my $amount = 20; | ||
+ | print "$amount\n"; | ||
+ | print '$amount\n'; | ||
+ | </source> | ||
+ | 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 | ||
+ | <source lang="python">length("hahahalol")</source> | ||
+ | 8 | ||
+ | |||
+ | case change (uc or lc) | ||
+ | print(uc("foo bar"),"\n") | ||
+ | FOO BAR | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
<source lang="python"></source> | <source lang="python"></source> |
Latest revision as of 12:33, 10 May 2021
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