How to convert from a filehandle to a string?

B

Bryan

Hi,

I have a filehandle, $file.

I can do something like this:
while (<$file>) {
print $_;
# or
$string .= $_;
}

But is there a way to stuff the whole file to a string in one shot? I
tried:
$string = <$file>;

But no dice.

Thanks,
B
 
M

Michele Dondi

Subject: How to convert from a filehandle to a string?

This doesn't make sense.
I have a filehandle, $file.

I can do something like this:
while (<$file>) {
print $_;
# or
$string .= $_;
}

But is there a way to stuff the whole file to a string in one shot? I
tried:
$string = <$file>;

Read about $/ in

perldoc perlvar

or resort to Uri's File::Slurp.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top