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

Hugh Jarce hjarce2001 at yahoo.com
Tue Feb 22 12:33:41 PST 2005


--- Andrew.Hadenfeldt at alltel.com wrote:
> Two ideas:
>
> 1. $body = join(undef, at filecontents);

Untested, but I'd worry about that undef generating a warning,
so I suggest:

$body = join("", @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>;
> }

Shorter is:

my $body = do { local $/; <FH> };

See: http://www.perlmonks.org/?node_id=50532

Hugh


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Omaha-pm mailing list