Perl: Difference between revisions

From wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
=Things that do work=
=Things that do work=
Searching and matching is explained in [[Regular Expressions]].


Print out the contents of $variable in a structured format.
Print out the contents of $variable in a structured format.
Line 34: Line 36:
:Return formatted string. format is e.g. "%.3f". Check [[Python:Strings#Advanced]] for all formats.
:Return formatted string. format is e.g. "%.3f". Check [[Python:Strings#Advanced]] for all formats.


Searching is explained in [[Regular Expressions]].
;$exitcode = system("a command")
:Executed the command in a subprocess and return the exitcode
 
;$output = `a command`
:Execute the command and return all command output

Revision as of 06:21, 9 August 2018

Things that do work

Searching and matching is explained in Regular Expressions.

Print out the contents of $variable in a structured format.

use Data::Dumper;
print Dumper($variable);

if-then-else:

if < expr > {
 <codeblock>
} elsif < expr ) {
 <codeblock>
} else {
 <codeblock>
}
print Dumper($variable);
$var += <value>
Add <value> to $var (works for -, *, / too)
$string .= $addstring
Concatenate $string and $addstring
$string =~ s/<regexp>/<newvalue>/[g]
Substitute <regexp> with <newvalue> in $string. The g modifier makes the all occurrences of <regexp> are substituted.
$newstring = substr($string,start,length)
Return substring of $string
sprintf(format,$string)
Return formatted string. format is e.g. "%.3f". Check Python:Strings#Advanced for all formats.
$exitcode = system("a command")
Executed the command in a subprocess and return the exitcode
$output = `a command`
Execute the command and return all command output