in reply to Tie::File doesn't save
If the output file doesn't already exist, your code silently fails to tie the file,
From perldoc Tie::File
# create the file if it does not exist use Fcntl 'O_RDWR', 'O_CREAT'; tie @array, 'Tie::File', $file, mode => O_RDWR | O_CREA +T;
And had you checked the return value from tie, as in:
You would have seen:tie (@Card, 'Tie::File', $filecard, mode => O_RDWR ) or die $!;
which is why we should always check the return code of anything thing that interacts with the system..No such file or directory at tiefile.pl line 26.
Update: There is also a scope issue - having my @Card inside the sub Leggi make this program fail sileltnly even if the tie succeeds. My guess is that return @Card returns a list which still isn't tied. I think that either puttting the my @Card in the outer scope or returning a reference from the sub (and dealing with it in the code that invokes the sub) would fix this, though I've only tested the first of these options, although you also ahve to remove the @Card = in the @Card = Leggi($filecard); - since the tie already references the array, thi swas unneeded and complicates stuff. Anyhow, since you only posted code fragments, it's hard to test this stuff. In the future, it would help to ensure that everything between <code></code> tags compiles.
--Bob Niederman, http://bob-n.com
|
|---|