| 1 | 1 | new file mode 100644 | 
| ... | ... | @@ -0,0 +1,62 @@ | 
| 0 | +# https://github.com/dbbolton | |
| 1 | +# | |
| 2 | +# Below are some useful Perl-related aliases/functions that I use with zsh. | |
| 3 | + | |
| 4 | + | |
| 5 | +# Aliases ################################################################### | |
| 6 | + | |
| 7 | +# perlbrew ######## | |
| 8 | +alias pbi='perlbrew install' | |
| 9 | +alias pbl='perlbrew list' | |
| 10 | +alias pbo='perlbrew off' | |
| 11 | +alias pbs='perlbrew switch' | |
| 12 | +alias pbu='perlbrew use' | |
| 13 | + | |
| 14 | +# Perl ############ | |
| 15 | + | |
| 16 | +# perldoc` | |
| 17 | +alias pd='perldoc' | |
| 18 | + | |
| 19 | +# use perl like awk/sed | |
| 20 | +alias ple='perl -wlne' | |
| 21 | + | |
| 22 | +# show the latest stable release of Perl | |
| 23 | +alias latest-perl='curl -s http://www.perl.org/get.html | perl -wlne '\''if (/perl\-([\d\.]+)\.tar\.gz/) { print $1; exit;}'\' | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | +# Functions ################################################################# | |
| 28 | + | |
| 29 | +# newpl - creates a basic Perl script file and opens it with $EDITOR | |
| 30 | +newpl () { | |
| 31 | + # set $EDITOR to 'vim' if it is undefined | |
| 32 | + [[ -z $EDITOR ]] && EDITOR=vim | |
| 33 | + | |
| 34 | + # if the file exists, just open it | |
| 35 | + [[ -e $1 ]] && print "$1 exists; not modifying.\n" && $EDITOR $1 | |
| 36 | + | |
| 37 | + # if it doesn't, make it, and open it | |
| 38 | + [[ ! -e $1 ]] && print '#!/usr/bin/perl'"\n"'use strict;'"\n"'use warnings;'\ | |
| 39 | + "\n\n" > $1 && $EDITOR $1 | |
| 40 | +} | |
| 41 | + | |
| 42 | + | |
| 43 | +# pgs - Perl Global Substitution | |
| 44 | +# find pattern = 1st arg | |
| 45 | +# replace pattern = 2nd arg | |
| 46 | +# filename = 3rd arg | |
| 47 | +pgs() { # [find] [replace] [filename] | |
| 48 | + perl -i.orig -pe 's/'"$1"'/'"$2"'/g' "$3" | |
| 49 | +} | |
| 50 | + | |
| 51 | + | |
| 52 | +# Perl grep, because 'grep -P' is terrible. Lets you work with pipes or files. | |
| 53 | +prep() { # [pattern] [filename unless STDOUT] | |
| 54 | + perl -nle 'print if /'"$1"'/;' $2 | |
| 55 | +} | |
| 56 | + | |
| 57 | +# say - append a newline to 'print' | |
| 58 | +say() { | |
| 59 | + print "$1\n" | |
| 60 | +} | |
| 61 | + |