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
####
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 );
####
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.
####
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: