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

Re^6: Tie::File failing with Unicode/UTF-8 encoding?

by remiah (Hermit)
on Nov 08, 2012 at 10:29 UTC ( #1002869=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Tie::File failing with Unicode/UTF-8 encoding?
in thread Tie::File failing with Unicode/UTF-8 encoding?

Hello HelenCR.

I just thought setting bval option would solve this crlf problem, but DB_File allows only one byte for record delimitor (sorry, I didn't know this ...). DB_File document says

Also note that the bval option only allows you to specify a single byte as a delimiter.

So as you say, Filter_Push for crlf will work.

my @Tied; my $Filename='087.txt'; my $dbh = new DB_File::RECNOINFO ; $dbh->{bval}="\n"; #set bval explicitly my $db = tie @Tied, 'DB_File', $Filename, O_CREAT | O_RDWR, 0644, $dbh or die "failed top open $Filename"; #utf8 $db->Filter_Push('encode' => 'UTF-8'); #add crlf filter $db->Filter_Push( Fetch => sub { s/\r\n$/\n/;}, #convert crlf to lf Store => sub { $_ .="\r"; }, #add cr ); # ... same as before
For documents, I like HTML pages of search.cpan.org
DB_File
DBM_Filter
And you will have "t" directory for each modules, which is for testing. Scripts in "t" directory gives me hints for usages.

regards, good luck.


Comment on Re^6: Tie::File failing with Unicode/UTF-8 encoding?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-07-24 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls