in reply to help neeed in unpack
It isn't really clear what you are trying to accomplish with unpack so it is difficult to tell what your problem is.
Under pack/unpack, 'A' only works with ASCII strings, so that is unlikely to be what you want. 'U' returns the ordinal of a utf-8 character. That may be useful to you, I can't tell from your question.
It seems like you are just trying to get the first 4 characters from the line, in which case, unpack is probably not the best way to go. You may be better of using substr
use warnings; use strict; my $infile = 'D:/try_unicode/input.txt'; # or whatever my $outfile = 'D:/try_unicode/output.doc'; open my $input, '<:utf8', $infile or die "Couldn't open file: $!"; open my $output, '>:utf8', $outfile or die "Couldn't open file: $!"; while (my $line = <$input>) { chomp $line; print $output 'The first four utf-8 chars from the line: ', pack( "U4", unpack( "U4", $line ) ),"\n"; print $output 'Or, an easier way to get the same thing: ', substr $line, 0, 4; print $output "\n", '-' x 79, "\n"; }
|
|---|