Andrew McDonough

Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.


Getting Input

my $myvar = ; chomp($myvar);

Command Line Arguments

  • @ARGV is initialised as the array of arguments
  • $#ARGV is the subscript of the last element

Executing Shell Commands

Backticks are used to execute commands and return the input to the perl script e.g. $result = $command; exec is used to launch a command when the output is to be directed to STDOUT e.g. exec $command;


A Perl Script to find possible matches for a file and open choice of match in Vim


my $file = $ARGV[0]; my $locate = locate $file; my @matches = split(“\n”, $locate); my $i=1; foreach my $match (@matches) { print ”($i) $match\n”; $i++; } my $choice = || 1; chomp($choice); my $toOpen = $matches[$choice-1]; $command = “vi $toOpen”; exec $command;


Andrew McDonough

Andrew McDonough is a consultant CTO and software developer, currently based between Berlin and London.

Follow Andrew on Twitter or Connect on LinkedIn