Hi, Carl--
Using the input record separator for fixed length records does work, just as the the fine manual says. However I left out one critical character in the code I sent last night-- the magic happens when $/ is assigned a _reference_ to an integer value, as below. use strict; { local $/; $/ = \4; # must be reference open IN, "test.dbx" or die "bad open: $!\n"; binmode IN; my $i = 0; my $n = 0; while(<IN>) { $n = unpack("I", $_); printf "%02d. %08X\n", $., $n; $i++; last if $i > 10; } close IN; } This behavior is documented in Wall, et al: _Programming perl, third ed_, pg 666 (so I guess its sort of black magic). The above bit also shows that $. does work in this mode. --Will Carl Jolley wrote on Thursday, February 21, 2002 1:35 PM Subject: Re: pack > On Thu, 21 Feb 2002, Will W wrote: > > > Sisyphus wrote on Wednesday, February 20, 2002 5:16 PM > > Subject: Re: pack > > > > > > > Thanks Will ..... now for a replacement for '$.' ?? :-)) > > > (Of course it's dead easy to craft one's own incremental counter.) > > <snip> > > > > > while (1) { > > > > > sysread(READ, $ret, 4); > > <snip> > > > > Everyone's fascination with sysread() got me to poking around in the > > camel and cookbook a bit-- and I still can't see the advantage here of > > doing a low-level system call over using read(), which is generally > > buffered for optimal efficiency on whatever system your using. sysread() > > makes a lot of sense on a port, but on a disk file I'm not seeing the > > why of it-- maybe someone will enlighten me. > > > > Anyway while poking around I ran yet another way to do the job which > > really looks kind of interesting: > > > > [untested-- too much chianti on board to try it tonight] > > > > open IN, $somefile or die "gasp! $somefile! Uh! $!\n"; > > binmode IN; > > { # closure for local > > local $/; > > $/ = 4; # see the camel > > while (<IN>) { # Should work, but wait there's more > > $n = unpack("I", $_); # may have mangled the syntax > > $line = $.; # Yep, you get this too! > > } # endwhile > > } # end localizing closure > > > > Now its time for bed. Spent the day developing a single subroutine I'm > > calling recurse_the_kids because its so dang descriptive of my feelings > > about its convolutions. And I'm out of chianti anyway. > > > > By doing a: $/ = 4; all you've done is to set the input record seperator > character to a character "4". That will mean that if your file contained > the characters 0123456789 that doing a <> on that file would result > in two records being read. The first one would contain 01234 and the > second (and last) one would contain 56789. By default, $/ is the > new-line character. Changing it tells perl that a different character > should be used to separate records. If you set $/ to undefined, then > the first <> operation on the filehandle will read all the characters > it contains. Setting $/ has no effect if you are using read() or > sysread() to access the data since those function read a specified > number of characters not a record. > > > **** [EMAIL PROTECTED] <Carl Jolley> > **** All opinions are my own and not necessarily those of my employer **** > k > _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs