recursive search

2005-12-02 Thread The Ghost
I want to know how many new line chars there are in all files in a directory (and it's subdirectories). What's the best way? Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: recursive search

2005-12-02 Thread Jeff 'japhy' Pinyan
On Dec 2, The Ghost said: I want to know how many new line chars there are in all files in a directory (and it's subdirectories). What's the best way? You'll want to use File::Find (a standard module) to do your directory recursion for you. For each file you get to, open it, count its newli

Re: recursive search

2005-12-02 Thread Chris Devers
On Fri, 2 Dec 2005, The Ghost wrote: > I want to know how many new line chars there are in all files in a > directory (and it's subdirectories). What's the best way? I'm sure this isn't how you want to do it, but this might work: $ cat `find . -type f` | wc -l It'll choke if you have too

RE: recursive search

2005-12-02 Thread Charles K. Clarkson
The Ghost wrote: : I want to know how many new line chars there are in all files : in a directory (and it's subdirectories). What's the best way? A lot depends on your idea of "best". It might be that the best way is to hand the project off to someone else and reap

RE: recursive search

2005-12-02 Thread Thomas Bätzler
The Ghost <[EMAIL PROTECTED]>asked: > I want to know how many new line chars there are in all files > in a directory (and it's subdirectories). What's the best way? Use File::Find to iterate over the files and then sum up the newlines you find in each file. Counting the newlines in a single file

Re: recursive search

2005-12-02 Thread Jennifer Garner
#!/usr/local/bin/perl # # recurs.pl # # This script executes recursively on subdirs the command you supply as a parameter # # Run "program -h" to see the run options # # Last modified: Apr 10 1997 # Author: Bekman Stas <[EMAIL PROTECTED]>; # <[EMAIL PROTECTED]>; $|

RE: recursive search

2005-12-02 Thread Charles K. Clarkson
Jennifer Garner wrote: [snip] : # Last modified: Apr 10 1997 [snip] Please do not provide outdated, buggy solutions to a beginners list. We are trying to do much more than just solve problems. We are (hopefully) fostering good programming skills first and

Re: recursive search

2005-12-02 Thread Shawn Corey
The Ghost wrote: So far I did this: #!/usr/bin/perl use File::Find; my $totalLines; find(\&wanted, '@directories'); sub wanted { unless ($_=~m/.html|.mas|.pl|.txt$/i) {return 0;} #filter the kinds of files you want open FILE, "<$File::Find::name"; print "$_: ";

Re: Flushing Buffers (WAS: recursive search)

2005-12-02 Thread Shawn Corey
Jennifer Garner wrote: $|=1; Be careful with this one. The documentation for it makes it sound like it's a good idea to set this but doing so turns buffering OFF, not ON. Normally you leave this alone, even for pipes and sockets; Perl does the right thing in almost every case. See: perldo

Re: Flushing Buffers (WAS: recursive search)

2005-12-02 Thread The Ghost
So far I did this: #!/usr/bin/perl use File::Find; my $totalLines; find(\&wanted, '@directories'); sub wanted { unless ($_=~m/.html|.mas|.pl|.txt$/i) {return 0;} #filter the kinds of files you want open FILE, "<$File::Find::name"; print "$_: "; my @lines=;

Re: Flushing Buffers (WAS: recursive search)

2005-12-02 Thread John W. Krahn
The Ghost wrote: > So far I did this: > > #!/usr/bin/perl That should be followed by these two lines: use warnings; use strict; > use File::Find; > my $totalLines; > find(\&wanted, '@directories'); Do you actually have a directory in the current directory named '@directories'? > sub

Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John Doe
The Ghost am Freitag, 2. Dezember 2005 19.30: Hi, In addition to John W. Krahn's good advices: > So far I did this: > > #!/usr/bin/perl > > use File::Find; > my $totalLines; > find(\&wanted, '@directories'); > sub wanted { >unless ($_=~m/.html|.mas|.pl|.txt$/i) {return 0;} #fil

Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John W. Krahn
John Doe wrote: > The Ghost am Freitag, 2. Dezember 2005 19.30: > >> open FILE, "<$File::Find::name"; > > Always check if operations succeeded: > >open (FILE, '<', $File::Find::name) > or die "couldn't open $File::Find::name: $!"; Thanks, don't know how I missed that. :-) Jo

Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John W. Krahn
John Doe wrote: > The Ghost am Freitag, 2. Dezember 2005 19.30: > >> print "$_: "; >> my @lines=; > > and close opened files: > > close FILE or die "couldn't close $File::Find::name: $!"; > >> print "$#lines\n"; >> $totalLines+=$#lines; #wanted's value is ignored

Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John Doe
John W. Krahn am Samstag, 3. Dezember 2005 15.27: > John Doe wrote: > > The Ghost am Freitag, 2. Dezember 2005 19.30: > >> print "$_: "; > >>my @lines=; > > > > and close opened files: > > > > close FILE or die "couldn't close $File::Find::name: $!"; > > > >>print "$#lines\n