develooper Front page | perl.perl6.language | Postings from January 2002

fixed-sized output records

Thread Next
From:
Tzadik Vanderhoof
Date:
January 2, 2002 09:42
Subject:
fixed-sized output records
Message ID:
AECBBE13620B29408319875D13D3ACF20180AAD6@bltexch.thinq.org
Hi.  I've had a feature in mind for a while now, but I missed my chance to
make it an RFC.  I was told that I could still present it by using this
list, so here goes.
 
There is a (relatively) new feature of the $/ variable which allows you to
set it to a numeric reference, i.e:
 
$/ = \80;
 
This will allow you to read fixed-length records from a file, instead of
delimited records.  The above example causes every read from a filehandle to
read exactly 80 bytes.  I liked this feature as soon as a I heard about it,
but it always bothered me that it was not symmetrically applied to $\.  In
other words, you can't say:
 
$\ = \80;
 
to make your *output* records (i.e. "print") fixed-length.  The feature I
propose would be to allow $\ to be set to a numeric reference, and if it is,
to pad any output record shorter than the specified number with spaces on
the end, to make it exactly that size and to truncate any out record longer
than the specified size.
 
It just seems logical that if there is direct support for *reading* fixed
length records, there should be analogous support for *writing* them as
well.
 
Thanks for your consideration.
 
Tzadik
 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About