Using Simple Patterns
To match a pattern (regular expression) against the contents of $_
, simply put the pattern between a pair of forward slashes (/), like we do here:
$_ = "yabba dabba doo";
if (/abba/) {
print "It
… Read the rest To match a pattern (regular expression) against the contents of $_
, simply put the pattern between a pair of forward slashes (/), like we do here:
$_ = "yabba dabba doo";
if (/abba/) {
print "It
… Read the rest To access an element of a hash, use syntax that looks like this:
$hash{$some_key}
This is similar to what we used for array access, but here we use curly braces instead of square brackets around the subscript(key). … Read the rest
There has been a lot of time that i encountered a paste issue in vim insert mode. When copying some plain text and then go to terminal vim, set vim in insert mode, press Command+V, i always get extra characters … Read the rest
chomp($line = <STDIN>);
# read the next line and chomp it
Since the line-input operator will return undef
when you reach end-of-file, this is handy for dropping out of loops:
while (defined($line = <STDIN>)) {
print
… Read the rest As other languages do, Perl has the ability to make subroutines, which are user-defined functions. The subroutine name comes from a separate namespace, so Perl won』t be confused if you have a subroutine called &fred
and a scalar called $fred
… Read the rest
A list is an ordered collection of scalars. An array is a variable that contains a list. In Perl, the two terms are often used as if they』re interchangeable. But, to be accurate, the list is the data, and … Read the rest