Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: process array with while loop

by jdporter (Paladin)
on Nov 09, 2006 at 17:52 UTC ( [id://583173]=note: print w/replies, xml ) Need Help??


in reply to process array with while loop

Simply tie *FH, 'Tie::Handle::Array' => \@a;
As in:

my @a = qw( alpha beta gamma delta epsilon ); tie *FH, 'Tie::Handle::Array' => \@a; while (<FH>) { print "$_\n"; }

Oh yeah — You'll need Tie::Handle::Array. The following is a minimal implementation:

{ package Tie::Handle::Array; sub TIEHANDLE { my( $pkg, $ar ) = @_; bless { A => $ar, I => 0, }, $pkg; } sub EOF { my $self = shift; $self->{I} > $#{ $self->{A} } } sub READLINE { my $self = shift; $self->EOF and return(); $self->{A}[ $self->{I}++ ] } }
We're building the house of the future together.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://583173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 01:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found