Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: inplace file editing

by ZZamboni (Curate)
on Jun 11, 2001 at 05:38 UTC ( [id://87385]=note: print w/replies, xml ) Need Help??


in reply to inplace file editing

I think the difference does not have to do with the use of $^I, but with how $/=undef behaves when reading from the magic <> file handle. The following program:
$^I=""; undef $/; while(<>) { print "hello:\n" }
Behaves the same if I comment out the $^I line: it prints "hello" twice, except that when $^I="" it is printed to the file I give as argument, obliterating it. Printing $_ on each iteration shows that $_ contains '' (empty string) on the second iteration, so my guess is that setting $/ to undef somehow changes the way in which perl reads from <>, but I don't really have an answer...

--ZZamboni

Replies are listed 'Best First'.
Re: Re: inplace file editing
by Anonymous Monk on Jun 11, 2001 at 11:40 UTC
    sorry, what i meant to say was
    $ARGV[0]="test"; $^I=""; undef $/; while(<>) { print STDOUT "hello\n" }
    (which stops hello getting printed to the file)...but it still prints twice. can ANYONE help?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2025-06-16 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.