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
Code Block |
---|
title | Final Script - for testing broken symbolic links |
---|
borderStyle | solid |
---|
|
#!/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";
}
|