Angerstein wrote:
Hello,
Hello,
I have a problem reading strings out of a binaery file.
perldoc -f binmode
The last 128 Byte of the File contains a String I want to work with.
(sorry, this code is windows, feel free to flame me ^^)
################################
my $tsize = 128;
my $fsize = (-s "d:\\mp3\\forseti.mp3");
my $offset = ($fsize - $tsize);
open(INF, "d:\\mp3\\forseti.mp3");
seek(INF, $offset, 0);
$tag = <INF>;
I would write that as:
use Fcntl ':seek';
my $tsize = 128;
my $file = 'd:/mp3/forseti.mp3';
open INF, '<', $file or die "Cannot open $file: $!";
binmode INF;
seek INF, -$tsize, SEEK_END or die "Cannot seek $file: $!";
read INF, my $tag, $tsize or die "Cannot read $file: $!";
@id3v1 = split (//, $tag);
$id3v_t = unpack("B8","$id3v1[125]");
Do you really need to split() $tag?
my $id3v_t = unpack 'B8', substr $tag, 125, 1;
print $id3v_t;
################################
I get:
00000000
If I print the whole string it looks like:
This is what I get 2002
^^^^^^ ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^
The Parts I markt are no whitespaces. They are binaery 00000000.
Is there something I could do to transform or remove this null-chars?
(Something small and smart.)
$tag =~ tr/\0/ /s;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>