[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Omaha.pm] Converting an array of strings into a scalar
Two ideas:
1. $body = join(undef,@filecontents);
2. If @filecontents originally came from a file handle then you can just read it in "slurp mode" (see 'perldoc perlvar' for $/):
open(FH,"blah");
{
local($/);
undef $/;
$body=<FH>;
}
-Andy
-----Original Message-----
From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org]On Behalf
Of Ryan Stille
Sent: Tuesday, February 22, 2005 11:00 AM
To: omaha-pm@pm.org
Subject: [Omaha.pm] Converting an array of strings into a scalar
I have an array of lines, each one containing a newline character at the
end. I want to convert this to a scalar variable that I will pass on to
something else.
I was using
$body = "@filecontents";
But that ends up adding a space to the beginning of each line except the
first one. So I changed it to this:
$body = '';
foreach $line (@filecontents) {
$body .= $line;
}
But I wonder if there is a more elegant way?
-Ryan
_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm
******************************************************************************************
The information contained in this message, including attachments, may contain
privileged or confidential information that is intended to be delivered only to the
person identified above. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, ALLTEL requests
that you immediately notify the sender and asks that you do not read the message or its
attachments, and that you delete them without copying or sending them to anyone else.