Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^8: Loading a part of the file to array using Tie::File

by ikegami (Patriarch)
on Nov 26, 2017 at 07:51 UTC ( [id://1204272]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Loading a part of the file to array using Tie::File
in thread Loading a part of the file to array using Tie::File

The fact that you can't even use Tie::File correctly says everything: The non-Tie implementation is clearly the easier of those two implementations.

Aside the fact that your Tie::File code only saved you one line (after getting rid of those closes) and that replaced well-known operations with obscure ones, you forgot to throw an error for non-existing files in your Tie::File solution, and you hid the fact that you have to use a bunch of encodes and decodes with Tie::File while the alternative automatically uses the one encoding you set using use open.

Replies are listed 'Best First'.
Re^9: Loading a part of the file to array using Tie::File
by haukex (Archbishop) on Nov 26, 2017 at 09:04 UTC

    You are correct on both points, although I didn't intentionally hide anything - most of the data I work with day to day is plain ASCII, so I just missed the encoding issue (and Tie::File creates nonexistent files and I was testing in /tmp - but without or die it fails silently on e.g. permission denied, so that's not an excuse).

    use Tie::File; use Fcntl qw/O_RDWR/; tie my @a, 'Tie::File', $file, mode=>O_RDWR or die $!; # but doesn't handle encodings # - or - use Tie::File; open my $fh, '+<:encoding(UTF-8)', $file or die $!; tie my @a, 'Tie::File', $fh or die $!;

    Better examples, I hope. Thanks for setting me straight.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-03-28 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found