what is an error?

D

dmitriy

What wrong on this code (after compare diff1.txt and diff2.txt)?

=================begin====================

#!/usr/bin/perl -w

#part one

$count="\x00\x00\x00\x00\x00\x00\x01\x01\x01\x02\x02\x02";
open F, ">diff1.txt";
print F $count;
close F;
print $count,"\n";

#part two

$count='';
foreach my $i (qw{0 0 1 2}){
my $tt1;
$tt1 ="\x".sprintf '%.2x', $i;
$tt1 x= 3;
$count.=$tt1;
}

print $count,"\n";
open F, ">diff2.txt";
print F $count;
close F;
print length $count,"\n";

==================end===================

i need file diff2.txt==diff1.txt as in part one, i.e. with size of 12 bytes.

[vilfred@mobile100 img]$ ls -la
summ 792
drwxrwxr-x 3 vilfred vilfred 4096 May 31 11:40 .
drwxr-xr-x 5 vilfred vilfred 4096 May 31 02:33 ..
-rw-rw-r-- 1 vilfred vilfred 12 May 31 11:51 diff1.txt
-rw-rw-r-- 1 vilfred vilfred 36 May 31 11:51 diff2.txt

thank you!!

dmitriy

p.s. i use perl 5.8.0

p.p.s. sorry for my bad english...
 
J

Joe Smith

dmitriy said:
What wrong on this code (after compare diff1.txt and diff2.txt)?

print $count,"\n";
open F, ">diff2.txt";
print F $count;
close F;

print "Before eval (", length($count), "): $count\n";
eval qq(\$count = "$count");
print "After eval (", length($count), "): $count\n";

It's like the difference between
$_ = 'a\tb\n';
and
$_ = "a\tb\n";
in that \t and \n are each two characters long in the first case
and each a single character in the second case.

When you put a backslash before "x00" in a double quoted string
in your program, perl converts the group of four characters into
a single byte. When you build a string or use single quotes,
the conversion does not happen; the four characters remain
four separate characters.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top