thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; # it warns about undefined values use strict; # it's a lexically scoped declaration use Data::Dumper; use Fcntl qw( SEEK_SET ); $| = 1; #flushing output my ( $mp3_size , $lines , $lines_1 , $lines_2 , $lines_3 , $lines_4 ) += "\0"; my @size = "\0"; open(FH, ,"<", "song.mp3") or die "Can not open file: $!\n"; binmode(FH); # Open in binary mode. seek( FH , 6 , SEEK_SET ) or die "Could not seek: $!"; read( FH , $lines, 4 ); # Read 32 bits (4 Bytes) and store the data in + $lines Size (4 Bytes Size). ( $lines_1, $lines_2, $lines_3, $lines_4 ) = unpack ( "I I I I" , +$lines ); # (I) An unsigned integer. print ("This is the content of lines_1: $lines_1\n"); print ("This is the content of lines_2: $lines_2\n"); print ("This is the content of lines_3: $lines_3\n"); print ("This is the content of lines_4: $lines_4\n"); exit(0); $mp3_size = ($size[0] & 0xFF) | (( $size[1] & 0xFF ) << 7) | (( $size[2] & 0xFF ) << 14) | (( $size[3] & 0xFF ) << 21); print Dumper($mp3_size); close (FH) or die "Can not close file: $!\n"; $| = 1; #flushing output
I am trying to decode the ID3v2 TAG. As my first step (code: 1) I am trying to read 4 Bytes (32 bits) of unsigned integer into the $lines[0]-$lines3 which is the header size after the 6th Byte. The first 6 Bytes I have managed to read them and decode them effectively so far but I am having trouble with this one. The reason that I am trying to decode the message in 4 different strings is that I want to apply sync_safe process after as it is displayed on the code sample above.
seek( FH , 6 , SEEK_SET ) or die "Could not seek: $!"; read( FH , $lines, 1 ); ( $lines_1 ) = unpack ( "I" , $lines ); read( FH , $lines, 1 ); ( $lines_2 ) = unpack ( "I" , $lines ); read( FH , $lines, 1 ); ( $lines_3 ) = unpack ( "I" , $lines ); read( FH , $lines, 1 ); ( $lines_4 ) = unpack ( "I" , $lines );
Error when executing code:
This is the content of lines_0: 990183424 Use of uninitialized value $lines_1 in concatenation (.) or string at +test.pl line 63. This is the content of lines_2: Use of uninitialized value $lines_2 in concatenation (.) or string at +test.pl line 64. This is the content of lines_3: Use of uninitialized value $lines_3 in concatenation (.) or string at +test.pl line 65.
I tried also to read one byte (code: 2) each time by using the read() function and unpack() one by one the 4 Bytes but I keep getting the same error message.
In theory by reading one by one the Bytes with the read() function and applying the unpack I should not have a problem, at least so far worked fine for the previous Bytes.
But by doing to in the final step I keep getting the following error:
Use of uninitialized value $lines_0 in concatenation (.) or string at +test.pl line 62. This is the content of lines_0: Use of uninitialized value $lines_1 in concatenation (.) or string at +test.pl line 63. This is the content of lines_1: Use of uninitialized value $lines_2 in concatenation (.) or string at +test.pl line 64. This is the content of lines_2: Use of uninitialized value $lines_3 in concatenation (.) or string at +test.pl line 65. This is the content of lines_3:
I am a beginner in programming so I can not understand the reason that there is no value inside this values. Any guidance or assistance would be much appreciated
Thanks in advance for your time and effort.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ID3v2 TAG unpack uninitialized value
by BrowserUk (Patriarch) on Jan 05, 2014 at 04:32 UTC | |
by no_slogan (Deacon) on Jan 05, 2014 at 15:46 UTC | |
by thanos1983 (Parson) on Jan 06, 2014 at 00:06 UTC | |
by thanos1983 (Parson) on Jan 05, 2014 at 23:42 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2014 at 00:30 UTC | |
by thanos1983 (Parson) on Jan 06, 2014 at 04:59 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2014 at 07:00 UTC |