Acme-InputRecordSeparatorIsRegexp
view release on metacpan or search on metacpan
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
$line = <$fh>;
# import binmode and use :irs pseudo-layer
use Acme::InputRecordSeparatorIsRegexp 'binmode';
open my $fh, '<', 'ambiguous.txt';
binmode $fh, ':irs(\r\n|\r|\n)';
$line = <$fh>;
=head1 DESCRIPTION
In the section about the L<"input record separator"|perlvar/"$/">,
C<perlvar> famously quips
=over 4
Remember: the value of $/ is a string, not a regex. B<awk>
has to be better for something. :-)
=back
This module provides a mechanism to read records from a file
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
open my $fh_reg, "<", "some_text_file";
open my $fh_pkg, "<:irs(\d)", "some_text_file";
$rs = $fh_reg->input_record_separator; # "\n"
$rs = input_record_separator($fh_reg); # "\n"
$rs = $fh_pkg->input_record_separator; # '\d'
$rs = input_record_separator($fh_pkg); # '\d'
With two or more arguments, sets the input record separator for
the file handle as the regular expression indicated by the second
argument (any argument after the second is ignored). For regular
file handles, a side effect is that the file handle will be tied
to this package
print ref(tied *$fh_reg); # ""
$fh_reg->input_record_separator(qr/\r\n|\r|\n/);
print ref(tied *$fh_reg); # "Acme::InputRecordSeparatorIsRegexp"
If you are just looking for the functionality of setting different
input record separators on different file handles but don't care about
applying regular expressions to determine line endings, this function
( run in 1.153 second using v1.01-cache-2.11-cpan-39bf76dae61 )