jweller1 has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for some insight on Tie::File
by Athanasius (Archbishop) on Jan 09, 2016 at 03:30 UTC | |
|
Re: Looking for some insight on Tie::File
by trizen (Hermit) on Jan 08, 2016 at 23:36 UTC | |
by stevieb (Canon) on Jan 09, 2016 at 00:42 UTC | |
by Anonymous Monk on Jan 09, 2016 at 00:49 UTC | |
by Anonymous Monk on Jan 09, 2016 at 00:51 UTC | |
by stevieb (Canon) on Jan 09, 2016 at 00:55 UTC | |
by Anonymous Monk on Jan 09, 2016 at 01:27 UTC | |
|