Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 ?

#___________________________________________________________ #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

In reply to UN*X ls, sed, cat... in Perl by ady

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (3)
    As of 2021-04-16 20:00 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found