in reply to Looking for some insight on Tie::File

Hello jweller1, and welcome to the Monastery!

The second method described by trizen above is the best option:

my $ref = $dbFileArray{ 'sci' }; ... push @$ref, $oneRec;

Just to confuse things :-), from Perl version 5.14 onwards you can omit the dereference:

no warnings 'experimental::autoderef'; ... my $ref = $dbFileArray{ 'sci' }; ... push $ref, $oneRec;

— but as that’s still “experimental,” it’s probably more trouble than it’s worth.

I'd like to get a better understanding what @{$dbFileArray{ $part }} actually is (an array? an array reference?)

%dbFileArray is a hash, so $dbFileArray{ $part } is the value associated with the key $part. In this case, $part contains the string 'sci', and the hash entry for that key was previously set via this assignment:

my %dbFileArray = ( 'sci' => \@sciDbRows, ... );

so the value returned by the hash lookup $dbFileArray{ $part } is \@sciDbRows, a reference to an array.

Now, the important syntax to master here is @{...}, which is a dereferencing construct. It takes an array reference, and dereferences it to get the array it refers to. So in this case the expression @{$dbFileArray{ $part }} resolves to the array @sciDbRows. And that’s how pushing to @{$dbFileArray{ $part }} works — it’s really pushing to the array @sciDbRows.

Note that this has nothing to do with the fact that @sciDbRows has been tied to a file. (BTW, in simplifying the example code you forgot to use Tie::File.) The key to understanding what’s going on here is to get a thorough grasp of references in Perl. Begin by studying perlreftut, then look at perllol and perldsc. I found Perl references hard to grasp at first, but with a bit of study and a fair amount of practice their use has become almost second nature. (Well, mostly!)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,