I've got some code that I've been trying to get to work but am failing pretty miserably at. I'm beginning to think it's just not possible to do this. Attached is a (possibly overly) simplified snippet of code
my @sciDbRows; my @hkDbRows; my @ancDbRows; my %dbFileArray = ( 'sci' => \@sciDbRows, 'hk' => \@hkDbRows, 'anc' => \@ancDbRows ); sub open1 { my $dbPath = '/home/user/SciPtrLoc.db'; use Fcntl 'O_RDWR', 'O_CREAT'; tie @sciDbRows, 'Tie::File', $dbPath, mode => O_RDWR | +O_CREAT or die; } sub write1 { my $part = 'sci'; my $ref = $dbFileArray{ 'sci' }; my @rows = @$ref; my $oneRec = "asdfg"; push(@rows, $oneRec); # does NOT work push(@{$dbFileArray{ $part }}, $oneRec); #does work $oneRec = "qwerty"; push(@sciDbRows, $oneRec); # does work } open1(); write1();
So I can push onto my tied file in some situations, but I'd like to get a better understanding what @{$dbFileArray{ $part }} actually is (an array? an array reference?) and also why I can't seem to assign it to a shorter and friendlier variable name, like @rows, so that later I can write
instead of$rows[$index] = "new value";
@{$dbFileArray{ $part }}[$index] = "new value";
In reply to Looking for some insight on Tie::File by jweller1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |