Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

•Re: Editing Files In Place

by merlyn (Sage)
on Jun 13, 2002 at 00:00 UTC ( [id://174072]=note: print w/replies, xml ) Need Help??


in reply to Editing Files In Place

{ local $^I = ".bak"; local *ARGV; @ARGV = ".fetchmailrc"; while (<>) { s/^(here)/$username\n$1/i; print; } }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: &bull;Re: Editing Files In Place
by belg4mit (Prior) on Jun 13, 2002 at 00:13 UTC
    Oooh purdy. It'd always bugged me that one "had" to use -i. It's bit unfortunate you have to go the whole ARGV/STDIN route, but that's better than forking. thanks!

    --
    perl -pew "s/\b;([mnst])/'$1/g"

      the whole ARGV/STDIN
      Excuse me? There's no use of STDIN in that program. An empty diamond is the same as <ARGV>, not <STDIN>.

      And beginning Perl hackers who confuse the two will eventually get burned. My rule is to never use <> (aka <ARGV>) if you ever print some kind of prompt, and I flunk any use to the contrary in code review. Work it out for yourself to see why. The proper use for interaction where you prompt and read input is <STDIN>.

      -- Randal L. Schwartz, Perl hacker

        Well yes, I new it was the ARGV filehandle, but I tend to think of waka waka as STDIN. If @ARGV is empty waka waka reads from STDIN.

        (I'd even contemplated writing magic ARGV but decided against it ;-)

        --
        perl -pew "s/\b;([mnst])/'$1/g"

Re: &bull;Re: Editing Files In Place
by bunnyman (Hermit) on Aug 25, 2003 at 21:49 UTC

    I just tried this on perl 5.005_02 and I found that it would not work with local *ARGV but local @ARGV worked.

    I assume localizing the ARGV filehandle somehow broke the <ARGV> magic. It works correctly on perl 5.6.0.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://174072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found