Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: UN*X ls, sed, cat... in Perl

by graff (Chancellor)
on Apr 17, 2005 at 04:58 UTC ( #448583=note: print w/ replies, xml ) Need Help??


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

I was just curious why you would do this:

@files = reverse (sort { $files{$a} <=> $files{$b} } keys %files);
instead of this:
@files = sort { $files{$b} <=> $files{$a} } keys %files;
As for the "2A" example, you could simplify that to a single system call:
my $redirect = ( $TRACE < 2 ) ? '>' : '| tee'; system( "sed s/{author}.*//g <$file $redirect ${file}1.txt";
The trick there is that when you pipe to "tee filename", output is written to both stdout and to filename; and the stdout from "system()" is the same as the perl script's STDOUT, so you'll see it.


Comment on Re: UN*X ls, sed, cat... in Perl
Select or Download Code
Re^2: UN*X ls, sed, cat... in Perl
by ady (Deacon) on Apr 17, 2005 at 12:19 UTC
    Good questions...
    Your code for reversing the sort result list is clearly preferable.
    Your switch of redirection depending on trace level is also a nice twist.
    I've adopted both of your improvements here graff.
    Thanks! -- Allan

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://448583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2015-07-04 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls