[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



--- Andrew.Hadenfeldt@alltel.com wrote:
> Two ideas:
>
> 1. $body = join(undef,@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