in reply to Re^2: ID3 tag version 2.4.0 Pack and Unpack (text encoding byte)
in thread ID3 tag version 2.4.0 Pack and Unpack

I thought all strings in Perl end automatically with "\0"

Don’t confuse Perl with C here. Consider:

12:23 >perl -MData::Dump -wE "my $s = qq[foo\0bar]; dd $s; say length( +$s); say qq[|$s|];" "foo\0bar" 7 |foo bar| 12:23 >

If Perl used the null terminator for strings as C does, the above would print |foo|, not |foo bar|.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^4: ID3 tag version 2.4.0 Pack and Unpack (text encoding byte)
by thanos1983 (Parson) on Sep 05, 2014 at 12:24 UTC

    Hello Athanasiis,

    Thank you for your time and effort. It does help me to understand, a few things. But still I have not figure out how to solve my problem. Or let me put it this way, I have not figure it out why id3info produces different output than mine. I still can not understand, where I am going wrong and I add one extra bit. Well in case that $00 was adding the extra bit, by applying chop($flags) should have done the job but still the same problem.

    Thank you again for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      The built-in function chop removes one character from the end of a string, not from the beginning.

      Here are a couple of observations regarding variable initialisation in the OP:

      • This line:

        my ( $lines , $type , $major_version , $revision_number , $flags , $si +ze , $extended_size , $number_flags , $extended_flags ) = "\0";

        initialises $lines to \0, leaving $type, $major_version, etc., undefined. Maybe this is what you intended; but, if you want to initialise all the variables to null, you need = ("\0") x 9;.

      • This line:

        my @word = "\0" x 5;

        initialises the array @word to contain a single element, namely a string consisting of 5 consecutive null characters. If you want an array containing five elements, each a single null character, you need:

        my @word = ("\0") x 5;

      By the way, I think you should give careful attention to the example code provided by Tux, below. By studying this code you will gain valuable insight into how your own coding style can be improved.

      Update: Fixed typo, thanks to Tux.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Hello Athanasius,

        I will review my code and I will apply the proposed modifications.

        Again thank you for your time and effort.

        Seeking for Perl wisdom...on the process of learning...not there...yet!