Tie::Diamond - Iterate the diamond operator via a Perl array
This document describes version 0.06 of Tie::Diamond (from Perl distribution Tie-Diamond), released on 2014-05-17.
use Tie::Diamond; tie my(@ary), "Tie::Diamond" or die; while (my ($idx, $item) = each @ary) { ... } # to autochomp lines ... tie my(@ary), "Tie::Diamond", {chomp=>1} or die;
This class lets you iterate the diamond operator via a Perl array. Currently the only useful thing you can do with the array is just iterate it using each(), as shown in Synopsis. To be more exact, the class currently only implements FETCH() and FETCHSIZE().
The array backend does not slurp all lines into memory (or store past lines at all, actually), so it's safe to iterate over gigantic input.
Options are passed as a hashref. Known keys:
chomp => BOOL (default 0)
If set to true, lines will be chomp()-ed.
utf8 => BOOL (default 0)
If set to true, will issue a 'use open qw(:std :utf8)' pragma so that input is read as UTF-8 data.
So you can iterate using each(), basically, or to be compatible with a normal Perl.
One of my modules, Data::Unixish, has functions that accept array. It can either an actual Perl array (to iterate over a in-memory structure), or a tied array (to iterate lines from STDIN/files). The functions do not need to care; they can just use each().
@other = @ary; # or print @ary
Currently no. And anyway, if you want to slurp all lines, you might as well just do:
@other = <>; # or print <>
and skip this class altogether.
Iterator::Diamond
Tie::File
Syntax::Feature::EachOnArray if you are using Perl older than 5.12.
Please visit the project's homepage at https://metacpan.org/release/Tie-Diamond.
Source repository is at https://github.com/sharyanto/perl-Tie-Diamond.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Tie-Diamond
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Steven Haryanto <stevenharyanto@gmail.com>
This software is copyright (c) 2014 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Tie::Diamond, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Diamond
CPAN shell
perl -MCPAN -e shell install Tie::Diamond
For more information on module installation, please visit the detailed CPAN module installation guide.