what is an error?

Discussion in 'Perl' started by dmitriy, May 25, 2004.

  1. dmitriy

    dmitriy Guest

    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...
    dmitriy, May 25, 2004
    #1
    1. Advertising

  2. dmitriy

    Joe Smith Guest

    dmitriy wrote:

    > 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
    Joe Smith, May 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,659
  2. JavaQueries
    Replies:
    1
    Views:
    3,654
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,093
  4. Bishop
    Replies:
    1
    Views:
    772
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,048
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page