Arrays |
push @arr, $x |
Add to end of array |
|
$x = pop @arr; |
Remove last element of array, put in $x |
|
shift @arr; (See also unshift) |
Remove first element of an arrray, put in $x |
|
$size = scalar @arr; |
Number of things in the array |
|
See also: split, join, splice, sort |
split string->array, join array->string, delete part of array, sort array in many ways |
scalar variables |
while (defined ($x=<>)) {code} |
False if variable has never been set (or when you try to read past the end of an input file) |
|
length($x) |
Length of a string |
|
chomp($line); |
Remove a newline at the end of a string |
|
$short=substr ($long, 2, 5) |
Characters 3-7 of $long (first char is 0!) |
Hashes |
@key = keys %hash |
The lookup terms in the hash |
|
if (exists $hh{“Hsp”}) {...} |
See whether hash %hh has a value for key Hsp |
Input/Output and Files |
open(HANDLE, ">outfile") or die “Can’t open $outfile: $!\n” |
Open outfile for writing, and associate it with filehandle HANDLE. Use “ |
|
print $x; print HANDLE $x; |
Prints to standard output (screen), Print to filehandle HANDLE |
|
warn “Something wrong\n”; |
Prints to standard error (screen) |
|
$x=<HANDLE> |
Read a line from filehandle HANDLE, put in $x |
|
close(HANDLE); |
Stop reading/writing a previously opened file |
Exit |
exit; |
Exits the program |
|
die "Something broke!\n"; |
exits the program with error message |
>> Operators and Loops |
>> Matching and Regular Expressions |
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by Suha