From f643ad1551b65e4bd0e5b40d5959629803a3b959 Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Sat, 1 Sep 2012 10:50:02 +0200 Subject: [PATCH] A: Added examples. --- examples/find-perl-binary.pl | 35 ++++++++++++++++++++++++++++++++ examples/ls.pl | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 examples/find-perl-binary.pl create mode 100755 examples/ls.pl diff --git a/examples/find-perl-binary.pl b/examples/find-perl-binary.pl new file mode 100755 index 0000000..2763aba --- /dev/null +++ b/examples/find-perl-binary.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Basename; +use File::DirWalk; + +my $dw = new File::DirWalk(); + +$dw->onDirEnter(sub { + my ($path) = @_; + + print "$path\n"; + + if (basename($path) =~ /sbin|lib|share|local|include|libexec|X11/) { + return PRUNE; + } + + return SUCCESS; +}); + +$dw->onFile(sub { + my ($path) = @_; + + print "$path\n"; + + if (basename($path) eq "perl") { + return ABORTED; + } + + return SUCCESS; +}); + +$dw->walk("/usr"); diff --git a/examples/ls.pl b/examples/ls.pl new file mode 100755 index 0000000..f0cce26 --- /dev/null +++ b/examples/ls.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Cwd; + +use File::Basename; +use File::DirWalk; + +my $dw = new File::DirWalk(); + +my $size = 0; + +$dw->setDepth(1); + +$dw->onBeginWalk(sub { + my ($path) = @_; + + if ($dw->filesInDir() > 0) { + print $dw->currentBasename() . "\n"; + + $size += -s $path; + } + + return SUCCESS; +}); + +$dw->onDirLeave(sub { + print $dw->filesInDir(), " files ($size bytes)\n"; + return SUCCESS; +}); + +if (-e $ARGV[0]) { + $dw->walk($ARGV[0]); +} else { + my $cwd = getcwd(); + $dw->walk($cwd); +}