This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Path: nntp.stanford.edu!newsfeed.stanford.edu!skynet.be!newspeer.clara.net!news.clara.net!server3.netnews.ja.net!ucl.ac.uk!not-for-mail From: "George Karpodinis" <ucesgka@ucl.ac.uk> Newsgroups: comp.lang.perl.misc Subject: Re: perl -lpi.bak -e "s/old/new/g" *.* broken on NT? Date: Tue, 18 Jul 2000 12:41:13 +0100 Organization: University College London Lines: 31 Sender: ucesgka@host62-6-123-230.host.btclick.com Message-ID: <8l1o06$m2u$1@uns-a.ucl.ac.uk> References: <8kl8rh$r6$1@nnrp1.deja.com> NNTP-Posting-Host: host62-6-123-230.host.btclick.com X-Trace: uns-a.ucl.ac.uk 963928902 22622 62.6.123.230 (18 Jul 2000 14:01:42 GMT) X-Complaints-To: usenet@ucl.ac.uk NNTP-Posting-Date: 18 Jul 2000 14:01:42 GMT X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Xref: nntp.stanford.edu comp.lang.perl.misc:327555 If you run the following program: perl -e "print join ',' => @ARGV" *.* you'll see that $ARGV[0] is the string "*.*". To get around this, you might want to consider doing: perl -pi.bak -e "BEGIN { @ARGV = map /[*?]/ ? glob($_) : $_, @ARGV } s/foo/bar/ig" That will modify @ARGV at the beginning, changing any element with a * or ? in it into the corresponding list of files matching the glob. Credit goes to Jeff "japhy" Pinyan(japhy@pobox.com) who answered the same question for me. George <atramos_us@my-deja.com> wrote in message news:8kl8rh$r6$1@nnrp1.deja.com... > > > My fovorite Perl one-liner (multi-file global search/replace) > fails on NT with an "Invalid Argument" error. > > Is there something I need to reconfigure? > > > Sent via Deja.com http://www.deja.com/ > Before you buy. Path: nntp.stanford.edu!newsfeed.stanford.edu!newsfeedZ.netscum.dQ!netscum.int!npeer.kpnqwest.net!nmaster.kpnqwest.net!blackbush.xlink.net!news-kar1.dfn.de!news-han1.dfn.de!news.rz.tu-clausthal.de!news.harz.de!news.harz.de!radiogaga!radiogaga.harz.de!martin From: martin@radiogaga.harz.de (Martin Vorlaender) Newsgroups: comp.lang.perl.misc Subject: Re: perl -lpi.bak -e "s/old/new/g" *.* broken on NT? Distribution: world Message-ID: <39827f94.524144494f47414741@radiogaga.harz.de> Date: Sat, 29 Jul 2000 08:54:12 +0200 Reply-To: martin@radiogaga.harz.de Organization: home References: <8kl8rh$r6$1@nnrp1.deja.com> <8l1o06$m2u$1@uns-a.ucl.ac.uk> <8l5enm$hrq$1@nnrp1.deja.com> X-Newsreader: TIN [version 1.2 PL2] X-Posting-Software: UUPC/extended 1.13f inews (25Nov98 07:59) Lines: 82 Xref: nntp.stanford.edu comp.lang.perl.misc:330391 atramos_us@my-deja.com wrote: : "George Karpodinis" <ucesgka@ucl.ac.uk> wrote: : > <atramos_us@my-deja.com> wrote... : > > My fovorite Perl one-liner (multi-file global search/replace) : > > fails on NT with an "Invalid Argument" error. : > : > If you run the following program: : > : > perl -e "print join ',' => @ARGV" *.* : > : > you'll see that $ARGV[0] is the string "*.*". To get around this, ... : : Thanks for the reply! : : I'm pretty sure though older versions of Perl compiled : for NT did the globbing automatically. I think it was : a pre-ActiveState build. Maybe the DJGPP one. The workaround below was suggested by Gurusamy Sarathy. I use it on all CP/M+ machines I install Perl on. cu, Martin [-- snip(pet) --] =pod =head2 Why won't my perl understand wildcards in arguments? The default command shells on DOS descendant operating systems (such as they are) usually do not expand wildcard arguments supplied to programs. They consider it the application's job to handle that. This is commonly achieved by linking the application (in our case, perl) with startup code that the C runtime libraries usually provide. However, doing that results in incompatible perl versions (since the behavior of the argv expansion code differs depending on the compiler, and it is even buggy on some compilers). Besides, it may be a source of frustration if you use such a perl binary with an alternate shell that *does* expand wildcards. Instead, the following solution works rather well. The nice things about it: 1) you can start using it right away 2) it is more powerful, because it will do the right thing with a pattern like */*/*.c 3) you can decide whether you do/don't want to use it 4) you can extend the method to add any customizations (or even entirely different kinds of wildcard expansion). C:\> copy con c:\perl\lib\Wild.pm =cut # Wild.pm - emulate shell @ARGV expansion on shells that don't use File::DosGlob 'glob'; @ARGV = map { my @g = File::DosGlob::glob($_) if /[*?]/; @g ? @g : $_; } @ARGV; 1; =pod ^Z C:\> set PERL5OPT=-MWild C:\> perl -le "for (@ARGV) { print }" */*/perl*.c p4view/perl/perl.c p4view/perl/perlio.c p4view/perl/perly.c perl5.004_02/win32/perlglob.c perl5.004_02/win32/perllib.c perl5.004_03/win32/perlglob.c perl5.004_03/win32/perllib.c perl5.004_531/win32/perlglob.c perl5.004_531/win32/perllib.c Note there are two distinct steps there: 1) You'll have to create Wild.pm and put it in your perl lib directory. 2) You'll need to set the PERL5OPT environment variable. If you want argv expansion to be the default, just set PERL5OPT in your default startup environment. -- One OS to rule them all | Martin Vorlaender | VMS & WNT programmer One OS to find them | work: mv@pdv-systeme.de One OS to bring them all | http://www.pdv-systeme.de/users/martinv/ And in the Darkness bind them.| home: martin@radiogaga.harz.de