Differences
This shows you the differences between two versions of the page.
perl [2008/11/17 20:34] a + An interactive perl shell |
perl [2009/05/25 00:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== An interactive perl shell ===== | ||
- | <code perl|f perlsh.pl> | ||
- | #!perl | ||
- | |||
- | use strict; | ||
- | no strict ' | ||
- | no strict ' | ||
- | use warnings; | ||
- | |||
- | use Data:: | ||
- | $Data:: | ||
- | |||
- | $| = 1; | ||
- | |||
- | # an alias for exit() | ||
- | sub quit { exit; } | ||
- | |||
- | my ($ver, | ||
- | $maj += 0; | ||
- | $min += 0; | ||
- | print +(split '/', | ||
- | |||
- | $, = ','; | ||
- | $THE_PROMPT = '% '; | ||
- | print $THE_PROMPT; | ||
- | while (<>) { print eval; print +($@ || " | ||
- | </ | ||
- | |||
- | usage: | ||
- | < | ||
- | $ alias perlsh=' | ||
- | $ perlsh | ||
- | perl.exe 5.10.0 | ||
- | % @l=qw(the quick brown fox jumps over the lazy dog) | ||
- | the, | ||
- | % @sorted_by_length = map {$_-> | ||
- | the, | ||
- | </ | ||
- | |||
- | |||
- | ===== Optimizing Perl ===== | ||
- | |||
- | First run the script with profiling enabled: | ||
- | |||
- | perl -d:DProf myscript.pl | ||
- | |||
- | then run the profile-dumper: | ||
- | |||
- | | ||
- | |||
- | ===== Copy (duplicate) a two-dimensional array in Perl ===== | ||
- | |||
- | | ||
- | |||
- | ===== CPAN modules fail to compile ===== | ||
- | |||
- | Then you're probably on a RedHat >= v9 system. | ||
- | Do this: | ||
- | |||
- | export LANG=C | ||
- | |||
- | and retry. | ||
- | |||
- | ===== Get a Perl-module from CPAN ===== | ||
- | |||
- | The easy way which also automatically fetches all modules needed by the module: | ||
- | |||
- | perl -MCPAN -e ' | ||
- | |||
- | e.g.: | ||
- | |||
- | perl -MCPAN -e ' | ||
- | |||
- | |||