sweetblood has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Fcntl; sysopen(FH, "data.sg", O_RDONLY) or die "$!\n"; my $flen = (-s "data.sg"); for (my $i=0;$i<$flen;$i++){ sysread(FH,my $byte,1,$i); # do stuff to $byte }
Now if I take this approach I won't be able to use stdin as a data path as I won't know the legnth of the file. I thought if I set $/ = ""; that would give me "byte mode" but no dice. I'd like me finished script to read either a named file or stdin. Is there a way to put Perl into "byte mode" as undef $/ puts Perl into "Slurp mode"?
Thanks in advance
By the way this is an HP-UX system running Perl 5.6.1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read data 1 byte at a time
by jmcnamara (Monsignor) on Oct 28, 2003 at 14:32 UTC | |
|
Re: read data 1 byte at a time
by Anonymous Monk on Oct 28, 2003 at 14:34 UTC | |
|
Re: read data 1 byte at a time
by Abigail-II (Bishop) on Oct 28, 2003 at 17:02 UTC | |
by BrowserUk (Patriarch) on Oct 28, 2003 at 20:43 UTC | |
by Abigail-II (Bishop) on Oct 28, 2003 at 22:11 UTC | |
by BrowserUk (Patriarch) on Oct 28, 2003 at 22:30 UTC | |
by Abigail-II (Bishop) on Oct 28, 2003 at 22:42 UTC | |
|
Re: read data 1 byte at a time
by pg (Canon) on Oct 28, 2003 at 15:55 UTC | |
|
Re: read data 1 byte at a time
by zentara (Cardinal) on Oct 28, 2003 at 16:38 UTC | |
|
Re: read data 1 byte at a time
by sweetblood (Prior) on Oct 28, 2003 at 20:43 UTC |