in reply to Treating file lines in a text file as a string
use strict; my @lines; # read the whole file into an array { # we use a block here so the lexical filehandle variable goes automa +tically out of scope and gets closed open my $filehandle, '<', 'path/to/my/file'; @lines = <$filehandle>; } # do something with the lines in @lines #now save the array to disk { # we use a block here so the lexical filehandle variable goes automa +tically out of scope and gets closed open my $filehandle, '>', 'path/to/my/file'; print $filehandle @lines; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Treating file lines in a text file as a string
by adaykin31 (Novice) on Apr 26, 2008 at 03:37 UTC |