Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: hex in regexp

by kcott (Chancellor)
on May 22, 2012 at 12:39 UTC ( #971784=note: print w/replies, xml ) Need Help??

in reply to Re^2: hex in regexp
in thread hex in regexp

Changing upper to ascii and using your string, I get:

$ perl -Mstrict -Mwarnings -E ' my $x = q{çe quil Y a Yå}; $x =~ s/([[:^ascii:]])/unpack q{H2}, $1/eg; say $x; ' c383c2a7e quil Y a Yc383c2a5

Check that you didn't make a typo when entering your code. If you are still having problems, please post your code - as it is, I can't reproduce your problem.

To wrap the codes in < and >, or any other characters, you can just concatenate the characters at the beginning and end of the hex code:

$ perl -Mstrict -Mwarnings -E ' my $x = q{çe quil Y a Yå}; $x =~ s/([[:^ascii:]])/q{<} . unpack(q{H2}, $1) . q{>}/eg; say $x; ' <c3><83><c2><a7>e quil Y a Y<c3><83><c2><a5>

-- Ken

Replies are listed 'Best First'.
Re^4: hex in regexp
by shamanoff (Initiate) on May 22, 2012 at 21:09 UTC
    I double checked the code and haven't found any typo:
    #!/usr/bin/perl $file = @ARGV[0]; $out_file = $file.".out"; my $count = 0; print "Processing file: $file\n"; print "Output file: $out_file\n"; open FILE, "$file" or die "cannot open $file file"; open OUT, ">>$out_file" or die "cannot create $out_file file"; #go through the file rows while (<FILE>) { chomp; # if row contain non-ASCII symbols - it is counted if ($_ =~ /[[:^ascii:]]/) { print "String before modification:\n $_ \n"; s/[[:^ascii:]]/q{<} . unpack(q{H2}, $1) . q{>}/eg; print "String after modification:\n $_ \n"; print OUT "$_\n"; $count++ ; } else { print OUT "$_\n"; } } print "there are $count possibly corrupted rows\n"; close FILE; close OUT;
    the contents of processed file:
    0,1,,,1,~=_<>}[]||$? £??§^`??¿ ?. Qu est çe quil Y a Yå,0,20120 +306101731 0,1,,,1,Teá,0,20120314104403 0,1,,,1,Q<8a>rUì ,0,20120306103345 1,1,,,3,,0,20120331152610 1,1,,,3,,0,20120331152612
Re^4: hex in regexp
by shamanoff (Initiate) on May 22, 2012 at 21:23 UTC
    Thanks, Ken! I found the typo - forgot to put the search expression in brackets ([...]). Let me say that I am sorry for my impatience. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971784]
[marto]: good morning all
[Discipulus]: good morning marto
[shmem]: good morning monkses and monksisses

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-22 07:13 GMT
Find Nodes?
    Voting Booth?