//
://=
://=
is the assignment operator version of //
//
and //=
appeared with Perl 5.10.0. To quickly check whether they are supported, try these :
my $i = $undefinedVariable // 2; print $i;
'my $i //= 2; print $i;
'$
, %
, @
or &
changes the meaning of thingsNothing is ever obvious for everybody.
Notation | Variable type | Details |
---|---|---|
$myVariable |
scalar | |
@myVariable |
array | aka list in Python. Items are referenced by their (0-indexed) position in the array. |
%myVariable |
hash | aka associative array or "key-value" pairs (details) |
cpanminus (aka App::cpanminus) is a script to get, unpack, build and install modules from CPAN and does nothing else. It's dependency free (can bootstrap itself), requires zero configuration, and stands alone. When running, it requires only 10MB of RAM.
To install it (as root) :
--> Working on App::cpanminus Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7044.tar.gz ... OK Configuring App-cpanminus-1.7044 ... OK Building and testing App-cpanminus-1.7044 ... OK Successfully installed App-cpanminus-1.7044 1 distribution installed
Nenm::Utils : download from https://github.com/perldork/Nenm--Utils, then copy it in the PERL libs tree (/usr/local/lib/perl/5.10.1/Nenm/Utils.pm)
xxx is up to date
Variable Name | Usage | Details |
---|---|---|
Error management | ||
$@ |
error code / message detected by the PERL interpreter | The variables $@ , $! , $^E and $? contain information about different types of error conditions that may appear during execution of a Perl program. The variables are shown ordered by the "distance" between the subsystem which reported the error and the Perl process. (source) |
$! |
error code / message detected by the C library | |
$^E |
error code / message detected by the operating system | |
$? |
error code / message detected by an external program | |
Other stuff | ||
$#myArray |
index of the last element of the array myArray | Since Perl arrays start at element 0, this number will be one less than the length of the array. |
$& | the string that was matched by the last successful pattern match | |
$/ |
the input record separator. | defaults to \n |
$_ |
each element of LIST, alias to the list value | |
$_[n] |
the nth argument passed to the subroutine | starts at 0 |
@_ |
array containing all the arguments sent to a subroutine |
|
#!/usr/bin/perl -w use strict; my $key; my $value; my $hashTable = { name => 'Jeff', age => 23 };$
-named, data between curly brackets foreach $key (keys %$hashTable) { $value = $hashTable->{$key}; de-referenced with the->
operator print "$key :\t$value\n"; } print "\n"; my %hashTable2 = ( firstname => 'Bob', how_old => 22 );%
-named, data between parenthesis foreach $key (keys %hashTable2) { $value = $hashTable2{$key}; no de-reference operator needed print "$key :\t$value\n"; }
age : 23 name : Jeff firstname : Bob how_old : 22
my %config = ( objects => {...}, commands => {...}, misc => {...}, ); foreach my $topic (keys %config) { # parse the indices of '%config'. the current index at each iteration is stored into $topic print '$topic : '.$topic.EOL; # since we're parsing a hash of hashes, $config{$topic} is a hash itself (casted to use the 'keys' function) foreach my $data (keys %{$config{$topic}}) { print '$data : '.$config{$topic}{$data}.EOL; } } print $config{'hosts'}{'outputFile'};