Difference between revisions of "perl notes"

From thelinuxwiki
Jump to: navigation, search
 
Line 8: Line 8:
  
 
===interpolation===
 
===interpolation===
double quotes get the value of a variable
+
double yield get the value of a variable, single quotes treat variable names as text
 
<source lang="python">
 
<source lang="python">
 
my $amount = 20;
 
my $amount = 20;
Line 14: Line 14:
 
print '$amount\n';
 
print '$amount\n';
 
</source>
 
</source>
 +
output
 
  20
 
  20
 
  $amount\n
 
  $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