Perl Language Reading a file's content into a variable Slurp file in one-liner


Example

Input record separator can be specified with -0 switch (zero, not capital O). It takes an octal or hexadecimal number as value. Any value 0400 or above will cause Perl to slurp files, but by convention, the value used for this purpose is 0777.

perl -0777 -e 'my $file = <>; print length($file)' input.txt

Going further with minimalism, specifying -n switch causes Perl to automatically read each line (in our case — the whole file) into variable $_.

perl -0777 -ne 'print length($_)' input.txt