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

Re: perl open mode

by Sidhekin (Priest)
on Oct 24, 2007 at 00:22 UTC ( #646789=note: print w/replies, xml ) Need Help??

in reply to perl open mode

As you are reading from the file handle in list context, you advance its position until eof.

Then you print. At the former eof.

(If you had opened with +>>, you would not have been able to read anything without seeking first.)

Update: For what you want, and with a tiny bit more clarity:

open (A, '+<', "somefile.html") or die $!; s/a/b/g for my @records = <A>; seek(A, 0, 0); print A @records;

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^2: perl open mode
by snopal (Pilgrim) on Oct 24, 2007 at 03:16 UTC

    That works if the replacement is character for character. You may be surprised by the results if the replacements are shorter than the original value.

    open (A, '+<', "somefile.html") or die $!; s/a/b/g for my @records = <A>; seek(A, 0, 0); ### truncate (A, 0) or die "can not truncate file to zero length\n"; ### print A @records;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://646789]
[Your Mother]: Don't think so.
[Your Mother]: Windows doesn't even recognize them as far as that goes.
[Lady_Aleena]: Your Mother, thanks. I had a feeling it would be no.
[Your Mother]: :P
[Lady_Aleena]: Your Mother, it is a good thing I am no on Windows.
[Lady_Aleena]: s/no/not/;
[Lady_Aleena]: My blasted web host will not put perl 5.22 in /usr/bin/perl, it is in /usr/local/cpanel/ 3rdparty/bin/perl

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-04-28 06:25 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (519 votes). Check out past polls.