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.