Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by ikegami (Pope)
on Nov 26, 2017 at 07:51 UTC ( #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 (Abbot) 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
Node Status?
node history
Node Type: note [id://1204272]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-06-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?