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

Hello tye,

First of all I want to say thank you for your time and effort to assist me with my problem.

My read program ends with "\0"? Could you please help me a bit more here. I am a bit confused, I thought all strings in Perl end automatically with "\0", I can not avoid that.

I will look again and again the code in order to understand what you mean.

Thanks again for your time and effort.

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

Replies are listed 'Best First'.
Re^3: ID3 tag version 2.4.0 Pack and Unpack (text encoding byte)
by tye (Sage) on Sep 04, 2014 at 22:57 UTC

    Before the write, your read program is actually writing out "Third Part Frame id: TPE1 Frame Size: 10 Flags: \0An artist" and "Third Part Frame id: TALB Frame Size: 9 Flags: \0An album", but those "\0" bytes are not visible.

    Your writer needs to not deal with just the frame type, frame length, and flags. It also has to deal with (for some frame types) one more byte which I quoted the documentation for above.

    - tye        

      Hello again tye,

      I understand what you mean by the null terminating character on the strings. But on the flag how can I remove it? I assume you mean the part that I apply if ($flags == 0). I assume, I tried to apply chop right after the part ( $flags ) = unpack ( "h" , $lines ); I apply chop($flags);. On the writing part I still have the problem. Unless if I miss understood.

      I know that I am missing somewhere one byte and I can not understand what is my error.

      Seeking for Perl wisdom...on the process of learning...not there...yet!
        I understand what you mean by the null terminating character on the strings.

        That is unfortunate as I have not been saying anything about null terminating characters. I have been talking about a single byte that is not part of the strings and is not terminating but goes right before each string. And it doesn't have to be a "null". It can be "\0", "\01", "\02", or "\03".

        Please go re-read my first post once you have thoroughly dismissed from your mind the idea that I'm talking about the "\0" bytes that terminate string values. Pay special attention to the part where I quote part of the spec you linked to. Then go find that part of the spec and read more there.

        - tye        

Re^3: ID3 tag version 2.4.0 Pack and Unpack (text encoding byte)
by Athanasius (Archbishop) on Sep 05, 2014 at 02:35 UTC
    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,

      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,