At 08:59 PM 8/19/00 -0400, [EMAIL PROTECTED] wrote:
> >Au contraire; sysread reads exactly the number of characters requested;
> >what I want is a way for programs that do <FH> all over the place to be
> >protected if someone throws a gargantuan number of characters at FH without
> >a newline.  The $/ = ref_to_int feature is exactly the kind of feature I
> >was expecting to do this and I was disappointed that it didn't.
>
>True but sysread is non-blocking, so it can be used for this.
>Also, in the event you are dealing with certain types of data-streams,
>you could set $/ to a character which should occur in the data.
>
>For example if you're reading a potentially large English language stream (w/o
>newlines), set $/ to e. It's a pain yes, but that's what you get for having
>control ;-)
>
>Just pointing out there are "ways around this"

Ah, but this is not p5p; this is perl6-language.

So the feature I want isn't there in Perl 5; there's something very close 
to it using $/, but it only works on record-oriented systems.  It can't be 
made to work on others because setting it to a reference to an integer 
precludes also saying what record separator you want.

Therefore I guess I want a line input discipline thingy to specify the 
maximum number of characters that a readline will return.  I reckon this 
does belong on -io after all...

-io guys, I've been looking through your archives at the line discipline 
stuff and I don't see this there: what do you think?  The proposal is for a 
mode that specifies a maximum number of characters to be returned by a 
getline (<>) so that paranoid programs can set it to a large number to 
prevent them taking up gobs of memory if someone throws zillions of 
characters sans newline at the input.  The question of what to do with the 
part not read (throw away, or return on next read) could be another mode 
switch perhaps?  I'm new to the -io list, I'm not sure if this makes sense.

Just saw Uri's message:
>and what happens to the partial line left in the input buffer? does it
>get read in the next time you call <> or is it thrown out? the semantics
>of <> in line mode is it reads a whole line. leaving the partial line to
>be read next time is bad. throwing out the leftover text is also bad.
>
>better to have <> work as now and the code just truncates the line with
>substr.

No, the point is not that I want truncated lines but that I want to say 
"toss/leave back the excess over 100,000 characters when I do a <INPUT>, 
for I am sure that a line longer than that would be an error of some 
kind."  Yes, Perl can handle many more characters than that before it 
starts to have problems, but so what.  Maybe I have scripts where I would 
set it to 1_000_000_000 but that would still make sense.


[followups to -io only please]


--
Peter Scott
Pacific Systems Design Technologies

Reply via email to