Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by haukex (Bishop)
on Nov 26, 2017 at 09:04 UTC ( #1204273=note: print w/replies, xml ) Need Help??


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

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://1204273]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-05-19 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?