Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Open/Save

by ambs (Pilgrim)
on Mar 30, 2005 at 16:04 UTC ( #443534=note: print w/replies, xml ) Need Help??


in reply to Open/Save

You can open a file for output as:
open OUT, ">output.txt" or die "Can't open file\n"; print OUT foo close OUT
and you can read as:
open IN, "output" or die "Can't open file\n"; while(<IN>) { # do something with $_ } close IN;
Don't know if this is exactly what you want.

Alberto Simões

Replies are listed 'Best First'.
Re^2: Open/Save
by Anonymous Monk on Mar 31, 2005 at 14:49 UTC
    You forgot semicolons after some statements. Anyway, in modern Perl it's written like that:
    { open my $fh, '>', 'filename.ext'; print $fh 'foo'; close $fh; }; { open my $fh, '<', 'filename.ext'; while (<$fh>) { # $_ }; close $fh; };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-10-17 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (71 votes). Check out past polls.

    Notices?