Child pages
  • Perl Scripting
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Perl Scripting

we looked at a few differences between shell and Perl:

  • command line Perl (perl -de 1| perl -ne '...' f1 f2... | perl -pi.bak -e '...' f1 f2 ...)
  • secure temporary files (File::Temp qw/tempfile/; ) - install libfile-temp-perl package
  • advanced finding with File::Find
  • command line options with Getopt::Long
Final Script - for testing broken symbolic links
#!/usr/bin/perl -w
use strict;

use File::Find;
use Getopt::Long;

my %OPTIONS;
GetOptions(\%OPTIONS,
	   "dir=s",
    );

die "Must give --dir"
    unless exists $OPTIONS{dir};

#
# to allow mutliple directories: test.pl --dir=/home/manu --dir=/home/jasons ...
#
my @files;
if (ref $OPTIONS{dir}) {
    @files = @{ $OPTIONS{dir} };
} else {
    @files = $OPTIONS{dir};
}
find(\&wanted, @files);

sub wanted {
    -l && !-e && print "bogus link: $File::Find::name\n";
}
  • No labels