Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Substring giving strange results on $1 with utf8

by Khen1950fx (Canon)
on Aug 07, 2012 at 02:45 UTC ( #985866=note: print w/replies, xml ) Need Help??


in reply to Substring giving strange results on $1 with utf8

I tried it with a different twist, using perl-5.17.2:
#!/usr/bin/perl BEGIN { $| = 1; $^W = 1; } use autodie; use strictures 1; use common::sense; open my $PL, '>', 'utf2.pl' or die $!; print {$PL} << '__PL__'; binmode STDIN, ":utf8"; binmode STDOUT, ":encoding(UTF-8)"; while (defined(my $line = <ARGV>)) { if (my($word) = $line =~ /^(.+)$/) { my $one = substr($word, 0, 1); my $w_one = substr($word, 0, 1); print "'$one' = 'one'\t at $line" if $one eq $1; print "'$w_one' = 'w_one'\t at $line" unless $w_one eq $1; } } __PL__ open my $OUT1, '>', 'utf1' or die $!; print {$OUT1} map chr hex, qw/61 61 c5 99 0a c4 8d 0a 61 61 c5 99 0a/; close $OUT1; open my $OUT2, '>', 'utf2' or die $!; print {$OUT2} map chr hex, qw/c4 8d 0a 61 61 c5 99 0a c4 8d 0a/; close $OUT2; system "$^X utf2.pl < utf1"; print "\n"; system "$^X utf2.pl < utf2";
Does that help?

Replies are listed 'Best First'.
Re^2: Substring giving strange results on $1 with utf8
by Anonymous Monk on Aug 07, 2012 at 03:45 UTC

    I tried it with a different twist, using perl-5.17.2: ... Does that help?

    How do you think that helps?

    The code no longer demonstrates the perl bug, how can that help?

    Typical Khen1950fx nonsense, poke the code with a stick and post the changes

      Typical AnonymousBug nonsense:);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985866]
help
Chatterbox?
[Cosmic37]: thank you Lotus I understand
[Cosmic37]: now I have tried another blunder - can anyone explain why I am such a dunderhead?
[Cosmic37]: if ( $line =~ /$mydt/ ) { print $line; }
[Cosmic37]: I try to match successive date times stored in variable $mydt
[Cosmic37]: I guess it is searching for the string "$mydt"
[Corion]: Indeed cool, erix ;)
[Cosmic37]: rather than the value of $mydt which is a date time strong such as 2016-01-01 12:30:56
[Corion]: Cosmic37: No, but maybe $mydt doesn't contain what you think it does, or it contains characters that are special in a regular expression? Try if( $line =~ /\Q$mydt\E/) { ... for a literal match
[Cosmic37]: I mean string grrr
[Corion]: Maybe add an else branch in which you print what the values of $line and $mydt are?

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2017-06-29 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (673 votes). Check out past polls.