Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: what is the purpose of Tie::File

by Khen1950fx (Canon)
on Nov 11, 2012 at 05:29 UTC ( #1003301=note: print w/ replies, xml ) Need Help??


in reply to what is the purpose of Tie::File

Having a glitch of some kind---code is coming:). Here:

#!/usr.bin/perl -l BEGIN { $| = 1; $^W = 1; } use strict; use autodie; use warnings; my $file = "file.txt"; 1 while unlink $file; use Tie::File; my $o = tie my @lines, 'Tie::Tile', $file, memory => 0; for (@lines) { $lines[2] = "something else is here now'; print $lines[2]; #line 3 is now "something else is here now". } END { undef $o; untie @lines; 1 while unlink $file; #clears and empties everything. }


Comment on Re: what is the purpose of Tie::File
Download Code
Re^2: what is the purpose of Tie::File
by Anonymous Monk on Nov 11, 2012 at 09:11 UTC
Re^2: what is the purpose of Tie::File
by Lotus1 (Chaplain) on Nov 11, 2012 at 23:02 UTC
    • Using perl -l gives you autochomp which Tie::File has built in. From your other nodes I see you use this frequently to add a newline when you print.
    • $^W = 1; and then use Warnings; a few lines later?
    • Using autodie means the script stops after the unlink line even if there is a file to delete. Why not just die if -e $file; ?
    • Does $| = 1; have any effect on Tie::File? With the option memory => 0 it is already not cacheing anything.

    I don't understand the point of this code. Tying to a file that doesn't exist, adding a line, then deleting the newly created file doesn't seem useful.

        What doesn't make sense to me is how a node that has so many obvious code problems can muster up a positive node reputation.


        Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2015-07-07 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls