Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I always find myself wanting to use an equivalent to grep on windows and seek a perl solution. I tracked down a script on the net and gave it some polishing up. It seems to behave.
#!/usr/bin/env perl use strict; use warnings; use Cwd; use File::Find; =pod =head1 DESCRIPTION Usage: perl grep1.pl frobnitz txt =cut my $search_pattern=$ARGV[0]; my $file_pattern =$ARGV[1]; find(\&d, cwd); sub d { my $file = $File::Find::name; $file =~ s,/,\\,g; return unless -f $file; return unless $file =~ /$file_pattern/; open my $fh, $file or print "couldn't open $file\n" && return; while (<$fh>) { if (my ($found) = m/($search_pattern)/o) { print "found $found in $file\n"; last; } } close $fh; }
My question is what this line is doing:
$file =~ s,/,\\,g;Also accepting any criticisms/improvements.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grep for windows
by RonW (Parson) on Oct 15, 2016 at 02:41 UTC | |
|
Re: grep for windows
by Athanasius (Cardinal) on Oct 15, 2016 at 03:05 UTC | |
|
Re: grep for windows
by BrowserUk (Patriarch) on Oct 15, 2016 at 00:53 UTC | |
by Aldebaran (Curate) on Oct 23, 2016 at 07:58 UTC | |
|
Re: grep for windows
by VinsWorldcom (Prior) on Oct 15, 2016 at 00:55 UTC | |
by Discipulus (Canon) on Oct 19, 2016 at 19:57 UTC | |
|
Re: grep for windows
by clueless newbie (Curate) on Oct 15, 2016 at 00:53 UTC | |
by Anonymous Monk on Oct 15, 2016 at 06:34 UTC | |
by Anonymous Monk on Oct 15, 2016 at 07:15 UTC | |
by Anonymous Monk on Oct 15, 2016 at 08:39 UTC | |
|
Re: grep for windows
by NetWallah (Canon) on Oct 15, 2016 at 18:08 UTC | |
|
Re: grep for windows (perlpowertools)
by Anonymous Monk on Oct 15, 2016 at 01:48 UTC |