To edit the page, the password is go
List of perl magic stuff
- The $#array construction returns the subscript, or index, of the last element of the array.
- Read a file with http://www.perlmonks.org/?node_id=261917][config variables -
## slurp - read a file into a scalar or list
sub slurp {
my $file = shift;
local *F;
open F, "< $file" or die "Error opening '$file' for read: $!";
if(not wantarray){
local $/ = undef;
my $string = <F>;
close F;
return $string;
}
local $/ = "";
my @a = <F>;
close F;
return @a;
}
$pie = 'pecan';
cake = 'fairy';
Convert from binary to ASCII
perl -e '$s=$ARGV[0];$l=length $s;@a=pack "B$l",$s;print "@a\n"' "0101010101010"
Convert from ASCII to binary
perl -e '$s=$ARGV[0];$l=(length $s)*8;@a=unpack "B$l",$s;print "@a\n"' "this is a test"
