jjhorner has asked for the wisdom of the Perl Monks concerning the following question:
One of my Windows using compatriots was lamenting the lack of a grep-like program for his Win32 workstation. He wanted to be able to check is .c files for strings.
I coded this up, and it works, but it has one drawback: he can't specify the extension of the file to search.
Any ideas? I'm not a Win32 programmer, but I looked through the Learning Perl on Win32 book and didn't find anything.
Here is my current code:
#!/usr/bin/perl -w use strict; use File::Find; my ($string, @files); ($string, @files) = @ARGV; @files = "." unless @files; find sub { unless (-x) { if (open (FILE, "$_")) { while (my $line = <FILE>) { print "$_: $line" if $line =~ /$string/i; } close FILE; } else { warn "Can't open $_: $!"; next; } } }, @files;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file wildcards in Win32
by httptech (Chaplain) on Jun 16, 2000 at 19:46 UTC | |
|
Re: file wildcards in Win32
by athomason (Curate) on Jun 16, 2000 at 20:09 UTC | |
|
Another alternative: Cygwin (was: cygwin)
by visnu (Sexton) on Jun 16, 2000 at 20:33 UTC | |
|
RE: file wildcards in Win32
by Ovid (Cardinal) on Jun 16, 2000 at 20:39 UTC | |
|
RE: file wildcards in Win32
by barZion (Beadle) on Jun 16, 2000 at 21:42 UTC | |
by flyfishin (Monk) on Jun 17, 2000 at 00:08 UTC | |
|
Re: file wildcards in Win32
by buzzcutbuddha (Chaplain) on Jun 16, 2000 at 23:16 UTC | |
by Ovid (Cardinal) on Jun 16, 2000 at 23:32 UTC | |
by buzzcutbuddha (Chaplain) on Jun 17, 2000 at 01:21 UTC |