Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

tie::file function

by PriNet (Beadle)
on Nov 10, 2012 at 04:18 UTC ( #1003225=perlquestion: print w/ replies, xml ) Need Help??
PriNet has asked for the wisdom of the Perl Monks concerning the following question:

just a quick q...

when you 'untie @array', does @array retain the value read from the file or does @array fall empty?

So there's a harder way?
I need to try that !

Comment on tie::file function
Re: Tie::File function
by Athanasius (Monsignor) on Nov 10, 2012 at 04:33 UTC

    Using Tie::File:

    #! perl use strict; use warnings; use Data::Dump; use Tie::File; my @array = ('x', 'y', 'z'); dd @array; tie @array, 'Tie::File', 'data.txt'; dd @array; untie @array; dd @array;

    With file data.txt as follows:

    AAA BBBBBB C DDDD

    Output:

    14:32 >perl 378_SoPW.pl ("x", "y", "z") ("AAA", "BBBBBB", "C", "DDDD") ("x", "y", "z") 14:32 >

    So, @array neither retains the values of the file, nor does it fall empty. Rather, it resumes the values it had before the tie.

    Hope that helps,

    Athanasius <°(((><contra mundum

      got it ... thanx

      So there's a harder way?
      I need to try that !
        So there's a harder way?
        I need to try that !

        So would doing the experiment that Athanasius performed and reported have been harder than asking the OPed question? More typing would certainly have been involved, but the potential return for the extra effort might have been very worthwhile, as an answer gained by your own efforts might have been more enlightening, and the answer to one question might have led to other questions and to a yet deeper understanding of mechanisms, possibilities, difficulties. The path of direct experience would have been more work, but perhaps much more profitable; it's possible the original question was the harder road after all.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003225]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (19)
As of 2014-10-20 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (85 votes), past polls