Search code examples
perlactiveperl

Combine multiple statements into an expression in Perl?


Is it possible to combine multiple statements into a single expression? A block could do this but I am wondering whether they could also be packaged into a expression.


Solution

  • That's exactly do BLOCK's purpose.

    For example,

    my $file = do {
       open(my $fh, '<', $qfn) or die $!;
       local $/;
       <$fh>
    };