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:

tie (@Card, 'Tie::File', $filecard, mode => O_RDWR ) or die $!;
You would have seen:
No such file or directory at tiefile.pl line 26.
which is why we should always check the return code of anything thing that interacts with the system..

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

In reply to Re: Tie:File doesn't save by bobn
in thread Tie::File doesn't save by nathanvit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.