Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: took out 'use Carp', we're going to assume all code samples use Carp.

...

Code Block
bgColor#ffcccc
langperl
use Carp;

my $dir = $ARGV[0];
open( my $listing, "-|", "ls -F $dir") or croak "error executing command: stopped";
while (<$listing>) {
  print "Result: $_";
}
close( $listing);

...

Code Block
bgColor#ccccff
langperl
use Carp;

my $file;
my $dir = $ARGV[0];
croak "Argument contains unsanitary characters, stopped" if ($dir =~ m|[^-A-Za-z0-9_/.~]|);
open( my $listing, "-|", "ls -F $dir") or croak "error executing command: stopped";
while (<$listing>) {
  print "Result: $_";
}
close( $listing);

...

Code Block
bgColor#ccccff
langperl
use Carp;

my %choices = (BIN => "~/bin",
               LIB => "~/lib",
               SRC => "~/src");
my $choice = $choices{$ARGV[0]};
croak "Invalid argument, stopped" if (!defined $choice);
open( my $listing, "-|", "ls -F $choice") or croak "error executing command: stopped";
while (<$listing>) {
  print "Result: $_";
}
close( $listing);

...