Re: Adding a line in a file inside many directories



usenet@xxxxxxxxxxxxxxx wrote:
On Jun 28, 12:00 pm, vedpsi...@xxxxxxxxx (Ved) wrote:
Now I have to print a single line at say line number 20 in each of 150
number of kat.s file.

Hey, another chance to show off my favorite Perl module, IO::All.

Situation is bit complex (atleast for a beginer like me).

Actually it is so simple (with IO::All) that you're gonna think I'm
pulling your leg...

#!/usr/bin/perl
use strict;
use warnings;
use IO::All;

my $dir = '/tmp/clpm'; #root directory of data
my $line = 19; #print line 20 (first line is line zero)
my $file = 'kat.s'; #match this filename

map {print "@$_[$line]\n"}
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);

Instead of using map in a void context:

print "@$_[$line]\n" for
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);

Or just call print once with a large list:

print map "@$_[$line]\n",
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.



Relevant Pages

  • Re: debugger exiting
    ... strict and warnings pragmas. ... I think portraying Perl as a command-line tool limits it to fewer platforms than ... work only as a Unix shell command line. ...
    (perl.beginners)
  • Re: dns querry script.
    ... use warnings; ... use strict; ... C:\Dload> perl dns.pl ...
    (comp.lang.perl.misc)
  • Re: Any way to access global variable in Perl script from one module file?
    ... use strict; ... use warnings; ... a separate process has a completely separate memory space. ... There is probably no reason to create a new perl ...
    (comp.lang.perl.misc)
  • Re: Debug Help Please
    ... In Perl there is the expression TIMTOWTDI which means that you will probably get different opinions on "The Right Way" to do something in Perl. ... use strict; ... That is a specious argument because you can disable specific strictures or warnings in local scope: ... for all Failures ...
    (perl.beginners)
  • Re: Align Text
    ... On Dec 21, 2003, at 10:47 PM, Bill Jastram wrote: ... use strict; ... use warnings; ... These promise Perl you'll play by the good programmer rules, ...
    (perl.beginners)