in reply to Dealing with huge text string
If Phil was sure that his text file contained no wide characters, he could omit the ':encoding' portion of the open mode; read operates on bytes unless otherwise informed by the status of the filehandle in question.use strict; my $length = 164; my $file = 'path/to/filename.txt'; open(my $F, '<:encoding' , $file) or die "cant open $file\n$!\n"; # you will supply the right value for 'encoding'. # one common example is 'utf8' while( read( $F, my $record, $length ) ){ # do something with $record }
my $c = 'some_scalar_data'; test_for_wide_chars: { require bytes; if ( bytes::length($c) > length($c) || ($] >= 5.008 && $c =~ /[^\0-\xFF]/)) { print "i found a wide character!" } no bytes; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dealing with huge text string
by BrowserUk (Patriarch) on Mar 28, 2008 at 19:33 UTC | |
by mobiusinversion (Beadle) on Mar 29, 2008 at 07:02 UTC | |
by BrowserUk (Patriarch) on Mar 29, 2008 at 09:15 UTC |