Acme-InputRecordSeparatorIsRegexp
view release on metacpan or search on metacpan
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
=head1 tie STATEMENT
A typical use of this package might look like
my $fh = Symbol::gensym;
tie *$fh, 'Acme::InputRecordSeparatorIsRegexp', $record_sep_regex;
open $fh, '<', $filename;
where C<$record_sep_regexp> is a string or a C<Regexp> object
(specified with the
L<< C<qr/.../>|"Quote and quote-like operators"/perlop >> notation)
containing the regular expression
you want to use for a file's line endings. Also see the convenience
method L<"open"> for an alternate way to obtain a file handle with
the features of this package.
=head1 FUNCTIONS
=head2 open
Another way of using this package to attach a regular expression
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
autochomp(tied(*$fh), 0); # disable
This function can also be called as a method on the I<tied>
file handle.
(tied *$fh)->autochomp(1); # enable
$fh->autochomp(0); # not OK, must use tied handle
Enabling C<autochomp> with this function on a regular file handle
will tie the file handle into this package using the current
value of C<$/> as the handle's record separator. If you are
just looking for autochomp functionality and don't care about
applying regular expressions to determine line endings, this
function provides an (inefficient) way to do that to
arbitrary file handles.
The default attribute value is false.
=head2 binmode FILEHANDLE, LAYER
Overrides Perl's builtin L<binmode|perlfunc/"binmode"> function.
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
Returns the current setting, or changes the setting, of a file handle's
input record separator, I<including file handles that have not
already been tied to this package>. This overcomes a limitation
in L<IO::Handle::input_record_separator|IO::Handle/"METHODS">
where input record separators are not supported on a per-filehandle
basis.
With no arguments, returns the input record separator associated
with the file handle. For regular file handles, this is always
the current value of L<< C<$/>|perlvar/"$INPUT_RECORD_SEPARATOR" >>.
use Acme::InputRecordSeperatorIsRegexp ':all';
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'
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
=head1 METHODS
=head2 chomp
my $chars_removed = (tied *$fh)->chomp($line_from_fh);
my $chars_removed = (tied *$fh)->chomp(@lines_from_fh);
Like the builtin L<< C<chomp>|"chomp"/perlvar >> function,
but removes the trailing string from lines that correspond to
the file handle's custom input record separator regular
expression instead of C<$/>. Like the builtin C<chomp>,
returns the total number of characters removed from
all its arguments. See also L<"autochomp">.
=head1 INTERNALS
In unusual circumstances, you may be interested in some of the
internals of the tied file handle object. You can set the values
of these internals by passing additional arguments to the
C<tie> statement or passing a hash reference to this package's
L<"open"> function, for example:
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
=head1 AUTHOR
Marty O'Brien, C<< <mob at cpan.org> >>
=head1 BUGS, LIMITATIONS, AND OTHER NOTES
Because this package must often pre-fetch input to determine where
a line-ending is, it is generally not appropriate to apply this
package to C<STDIN> or other terminal-like input.
Changing C<$/> will have no affect on a file handle that has
already been tied to this package.
Calling L<< C<chomp>|"chomp"/perlfunc >> on a return value from this
package will operate with C<$/>, B<not> with the regular expression
associated with the tied file handle. Use the construction
C<< tied(*$fh)->chomp(...) >> to perform the chomp operation on
a filehandle that has customized its input record separator with
this package. Or see the L<< C<autochomp>|"autochomp" >> method
to automatically get chomped input.
Please report any bugs or feature requests to
C<bug-acme-inputrecordseparatorisregexp at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-InputRecordSeparatorIsRegexp>.
I will be notified, and then you'll
lib/Acme/InputRecordSeparatorIsRegexp.pm view on Meta::CPAN
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Acme-InputRecordSeparatorIsRegexp>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Acme-InputRecordSeparatorIsRegexp>
=item * Search CPAN
L<http://search.cpan.org/dist/Acme-InputRecordSeparatorIsRegexp/>
=back
=head1 ACKNOWLEDGEMENTS
L<perlvar|perlvar/"$INPUT_RECORD_SEPARATOR">
=head1 LICENSE AND COPYRIGHT
( run in 0.793 second using v1.01-cache-2.11-cpan-e1769b4cff6 )