On Jun 18, 5:54 pm, [EMAIL PROTECTED] (John Degen) wrote: > >----- Original Message ---- > >From: Paul Lalli <[EMAIL PROTECTED]> > >To: [EMAIL PROTECTED] > >Sent: Monday, June 18, 2007 6:47:05 PM > >Subject: Re: Command line usage > > >On Jun 18, 10:50 am, [EMAIL PROTECTED] (John Degen) wrote: > > >> I think I'm out of luck with this OS;) Your suggestion for creating a > >> backup > >> file gave the same result: no error, no change in the files. The output of > >> 'perl -le"print for @ARGV" *' is * and the other is *.*. Funny though that > >> sed *does* work. > > >Ah. Well there's your problem. The command line interpreter you're > >running doesn't expand wildcards. That's why Perl wasn't giving you > >any errors - it had nothing to do because there was no file named "*" > >that it could find... You'll have to expand the wildcard from within > >Perl. > > >perl -pi.bkp -e"BEGIN { @ARGV = glob($ARGV[0]); } s/old/new/;" * > > >Hope this helps, > >Paul Lalli > > Thank you all for your responses. Paul's suggestion above is the winner. The > command works, creates a neat backup file and does what it's told. I'll be > checking the docs to see *why* it works:)
Normally your command line interpreter would expand "*" into a list of files, and perl would store them in @ARGV, e.g., $ARGV[0] = "a.txt"; $ARGV[1] = "b.txt"; $ARGV[2] = "c.txt"; Instead, yours is not expanding, but simply passing "*" unchanged, but perl still stores it in @ARGV, which looks like $ARGV[0] = "*"; So in the BEGIN block (which executes before the -p flag starts reading files), Paul's code passes $ARGV[0] to the glob() function, which is perl's way of expanding "*" into a list of files. Assigning that output to @ARGV (overwriting $ARGV[0] in the process) yields, e.g., $ARGV[0] = "a.txt"; $ARGV[1] = "b.txt"; $ARGV[2] = "c.txt"; Q.E.F. -- Brad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/