Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Treating the file contents of a text file as a string

by mwah (Hermit)
on May 22, 2008 at 08:16 UTC ( #687892=note: print w/replies, xml ) Need Help??


in reply to Treating the file contents of a text file as a string

From analyzing your question I'd assume that you try to handle the content of each file as a string for itself (no concatenation).

About one month ago you asked almost the same question w/different wording.

Please do give us some more words of "problem description" next time ;-)

(My interpretation of your question follows:)

my ($filename1, $filename2) = qw( adaykin1.txt adaykin2.txt ); my @string; for my $fn ($filename1, $filename2) { # iterate over given file +names open my $fh, '<', $fn or die "$fn - $!"; # open each file local $/; push @string, <$fh> # read it into one string } # print $string[0]; # first file as one big string print $string[1]; # second file as one big string ...

Regards

mwa

Replies are listed 'Best First'.
Re^2: Treating the file contents of a text file as a string
by adaykin31 (Novice) on May 22, 2008 at 17:14 UTC
    Well it wasn't the same question. Read the last one again and you'll see. What I meant in this question was to read every single character in a file and save every single character in the file into one string. And yes the File::Slurp was exactly what I was looking for this time. Code is working perfectly now, thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-04-11 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?