- Perldoc – http://perldoc.perl.org/
- Perl FAQ – http://faq.perl.org/
- Perl Monks – http://www.perlmonks.org/
- Randal Schwartz’s collections of his columns: http://www.stonehenge.com/merlyn/columns.html
- The Linux Magazine Perl columns – http://www.stonehenge.com/merlyn/LinuxMag/
- The Perl Journal Perl columns – http://www.stonehenge.com/merlyn/PerlJournal/
- The SysAdmin/PerformanceComputing/UnixReview Perl columns – http://www.stonehenge.com/merlyn/UnixReview/
- The WebTechniques Perl columns – http://www.stonehenge.com/merlyn/WebTechniques/
- “Higher-Order Perl” book online: http://hop.perl.plover.com/book/
- About.com> Perl – http://perl.about.com/
- Perl Circus – http://www.perlcircus.org/
- Accumulated Perl Tips and Tricks – http://perl-tricks.blogspot.com/
- Perl 6 Tricks and Treats – http://szabgab.com/perl6_tricks_and_treats.html
- The top 10 tricks of Perl one-liners – http://blog.ksplice.com/2010/05/top-10-perl-one-liner-tricks/
- Perl tips – http://www.edlin.org/perl/
- Perl tricks by NEIL KANDALGAONKAR – http://montreal.pm.org/tech/neil_kandalgaonkar.shtml
- 20 Perl Tips And Tricks – http://www.programmersheaven.com/2/20-PERL-Tips
- PerlMeme – http://perlmeme.org/ | HowTos – http://perlmeme.org/howtos/
- Alex Batko’s pages on Perl – http://www.cs.mcgill.ca/~abatko/computers/programming/perl/
- Perl core development – http://dev.perl.org/
- Bytes.com’s Perl answers – http://bytes.com/topic/perl/answers/
- Perl tips at DevDaily – http://www.devdaily.com/perl/
- Perl Regular Expressions by Example – http://www.somacon.com/p127.php
Hashes
- “Perl Hash Howto” by Alex Batko – http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/
- PERL Hashes – http://www.tizag.com/perlT/perlhashes.php
- Perl hash print – how to print the elements of a hash in Perl – http://www.devdaily.com/blog/post/perl/how-print-values-items-elements-perl-hash
- PERL Hash Variable – http://www.tutorialspoint.com/perl/perl_hashes.htm
Files
- “How to Read and Write Files in Perl” (About.com > Perl) – http://perl.about.com/od/perltutorials/a/readwritefiles.htm
Chomp()
- “Using the Perl chomp() function” – http://perlmeme.org/howtos/perlfunc/chomp_function.html
- chomp() changes [in Perl 6] – http://dev.perl.org/perl6/rfc/58.html
- http://perldoc.perl.org/functions/chomp.html
- “Removing new line character from a string” – http://bytes.com/topic/perl/answers/728645-removing-new-line-character-string
Control structures
- “For Loop – Beginning Perl Tutorial, Control Structures” – http://perl.about.com/od/perltutorials/a/forloop_2.htm
Tidbits
Rename files
Alex Batko says (at http://www.cs.mcgill.ca/~abatko/computers/programming/perl/):
Here is a brilliant program for renaming one or more files according to a specified Perl expression. I found it on page 706 of Programming Perl (3rd edition).
#!/usr/bin/perl $op = shift; for( @ARGV ) { $was = $_; eval $op; die if $@; rename( $was, $_ ) unless $was eq $_; } In the code above, the second last line calls the built-in function “rename”, not the program itself (which is named “rename.pl”). Below are a few examples of use. % rename.pl 's/\.htm/\.html/' *.htm # append an 'l' % rename.pl '$_ .= ".old"' *.html # append '.old' % rename.pl 'tr/A-Z/a-z/' *.HTML # lowercase % rename.pl 'y/A-Z/a-z/ unless /^Make/' * # lowercase |
Printing hashes
Starting with an input file with data in two columns separated by coma (,):
#/bin/perl -t my %TempHash = (); my $InputFile = shift; print "Input file = ",$InputFile,"\n"; my ($line,$column1,$column2,); #reading input file to generate hash open (INPUTSTREAM, '<', $InputFile) || die ("Could not open $InputFile"); while ( $line = ) { chomp; #print $line; ($column1, $column2) = split ',', $line; $TempHash{$column1}=$column2; #print $column1," ==> ",$TempHash{$column1}; } close (INPUTSTREAM); ## printing hash - way #1 print "The following are in the DB: ",join(', ',values %TempHash),"\n"; ## printing hash - way #2 while (($key, $value) = each %TempHash) { print "$key ==> $value"; } ## printing hash - way #3 foreach $key (sort keys %TempHash){ print "$key ==> $TempHash{$key}"; } |
Removing white spaces
Sources:
- Perl trim function to strip whitespace from a string – http://www.somacon.com/p114.php
# Declare the subroutines sub trim($); sub ltrim($); sub rtrim($); # Perl trim function to remove whitespace from the start and end of the string sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } # Left trim function to remove leading whitespace sub ltrim($) { my $string = shift; $string =~ s/^\s+//; return $string; } # Right trim function to remove trailing whitespace sub rtrim($) { my $string = shift; $string =~ s/\s+$//; return $string; } # Here is how to output the trimmed text "Hello world!" print trim($string)."\n"; print ltrim($string)."\n"; print rtrim($string)."\n"; |
Related: Regular Expressions – https://eikonal.wordpress.com/2010/04/02/regular-expressions/ | Command line based text replace – https://eikonal.wordpress.com/2010/07/13/command-line-based-text-replace/