[Omaha.pm] Converting an array of strings into a scalar

Andrew.Hadenfeldt at alltel.com Andrew.Hadenfeldt at alltel.com
Tue Feb 22 09:20:12 PST 2005


Two ideas:

1. $body = join(undef, at 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 at pm.org [mailto:omaha-pm-bounces at pm.org]On Behalf
Of Ryan Stille
Sent: Tuesday, February 22, 2005 11:00 AM
To: omaha-pm at 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 at 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. 



More information about the Omaha-pm mailing list