Difference between revisions of "perl notes"
From thelinuxwiki
| (One intermediate revision by one user not shown) | |||
| Line 7: | Line 7: | ||
<source lang="python">our $color='purple';</source> | <source lang="python">our $color='purple';</source> | ||
| − | ===interpolation===double | + | ===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 | 20 | ||
$amount\n | $amount\n | ||
| − | </source> | + | |
| + | ===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