Thanks everyone for your replies! :-) For completeness, here are some slurping examples, incorporating various suggestions:
my $data = do { open my $fh, '<', $file or die "$file: $!"; local $/; <$fh> };
my $data = do { open my $fh, '<:raw:encoding(UTF-8)', $file or die "$file: $!"; local $/; <$fh> };
my $data; { open my $fh, '<', $file or die "$file: $!"; local $/; $data = <$fh> };
my $data = do { local (*ARGV,$/); @ARGV=$file; <> };
Minor edits for clarity.
Update 2: Actually, I made a mistake in the last example when I first fixed it, it is now tested and correct.
In reply to Re: Any downsides to this slurp idiom? (updated)
by haukex
in thread Any downsides to this slurp idiom?
by haukex
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |