Dear Monks,
Below some code, where i've (out of habit) used a couple of UN*X utilities to ease the job; Now i may have to deploy this code on MSWin PCs (without these utils, -- and i don't want to bundle freeware versions of the utils with the code).
So i've written some Perl alternatives for the "inlined" ls, sed and cat calls, but these are certainly not the only - and probably not the best - way to skin these cats. Any suggestions for improvement ?
Best regards,
Allan Dystrup
============================================================
Below some code, where i've (out of habit) used a couple of UN*X utilities to ease the job; Now i may have to deploy this code on MSWin PCs (without these utils, -- and i don't want to bundle freeware versions of the utils with the code).
So i've written some Perl alternatives for the "inlined" ls, sed and cat calls, but these are certainly not the only - and probably not the best - way to skin these cats. Any suggestions for improvement ?
#___________________________________________________________ #1A: Read files sorted ascending on timestamp @files = `ls -t -1 -r $dir`; # strip ./../ & process .msg/.txt #1B: Same using plain vanilla Perl ... foreach my $g qw(msg txt) { push @files, glob("$dir\\*.$g"); } my %files = map { $_, -M} @files; @files = reverse (sort { $files{$a} <=> $files{$b} } keys %files); #___________________________________________________________ #2A: Strip $author} line system "sed s/{author}.*//g <$file >${file}1..txt"; ($TRACE>=2) and system "cat ${file}1.txt"; #2B: Same using plain vanilla Perl ... open (FH, "<${file}.txt") or die "Can't open ${file}.txt: $!\n"; open (FH1, ">${file}1.txt") or die "Can't create ${file}1.txt: $!\n"; while (<FH>) { next if (/{author}/); print FH1; ($TRACE>=2) and print; } close (FH) or die "Can't close ${file}.txt: $!\n"; close (FH1) or die "Can't close ${file}1.txt: $!\n"; #___________________________________________________________ #3A: ($TRACE>=2) and system "cat VSort.txt"; #3B: Same using plain vanilla Perl ... if ($TRACE>=2) { open (FH, "<$file") or die "Can't open $file: $!\n"; while (<FH>) { print; } close(FH) or die "Can't close $file: $!\n"; }
Best regards,
Allan Dystrup
============================================================
As the eternal tranquility of Truth reveals itself to us, this very place is the Land of Lotuses
-- Hakuin Ekaku Zenji
-- Hakuin Ekaku Zenji
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: UN*X ls, sed, cat... in Perl
by dbwiz (Curate) on Apr 16, 2005 at 08:02 UTC | |
Re: UN*X ls, sed, cat... in Perl
by cog (Parson) on Apr 16, 2005 at 13:31 UTC | |
Re: UN*X ls, sed, cat... in Perl
by tlm (Prior) on Apr 16, 2005 at 14:55 UTC | |
Re: UN*X ls, sed, cat... in Perl
by graff (Chancellor) on Apr 17, 2005 at 04:58 UTC | |
by ady (Deacon) on Apr 17, 2005 at 12:19 UTC | |
Re: UN*X ls, sed, cat... in Perl
by ady (Deacon) on Apr 16, 2005 at 14:25 UTC | |
Re: UN*X ls, sed, cat... in Perl
by mattr (Curate) on Apr 17, 2005 at 11:58 UTC |
Back to
Cool Uses for Perl