RFC 259 (v1) Builtins : Make use of hashref context for garrulous builtins
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Builtins : Make use of hashref context for garrulous builtins =head1 VERSION Maintainer: Damian Conway [EMAIL PROTECTED] Date: 19 Sep 2000 Last Modified: 29 Sep 2000 Mailing List: [EMAIL PROTECTED] Number: 259 Version: 1 Status: Frozen Frozen since: v3 =head1 ABSTRACT This RFC proposes the builtin functions that return a large number of values in an array context should also detect hashref contexts (see RFC 21) and return their data in a kinder, gentler format. =head1 DESCRIPTION It's hard to remember the sequence of values that the following builtins return: stat/lstat caller localtime/gmtime get* and though it's easy to look them up, it's a pain to look them up Every Single Time. Moreover, code like this is far from self-documenting: if ((stat $filename)[7] 1000) {...} if ((lstat $filename)[10] time()-1000) {...} if ((localtime(time))[3] 5) {...} if ($usage (getpwent)[4]) {...} @host{qw(name aliases addrtype length addrs)} = gethostbyname $name; warn "Problem at " . join(":", @{[caller(0)]}[3,1,2]) . "\n"; It is proposed that, when one of these subroutines is called in the new HASHREF context (RFC 21), it should return a reference to a hash of values, with standardized keys. For example: if (stat($filename)-{size} 1000) {...} if (lstat($filename)-{ctime} time()-1000) {...} if (localtime(time)-{mday} 5) {...} if ($usage getpwent()-{quota}) {...} %host = %{gethostbyname($name)}; warn "Problem at " . join(":", @{caller(0)}{qw(sub file line)} . "\n"; =head2 Standardized keys The standardized keys for these functions would be: =over 4 =item Cstat/Clstat 'dev' Device number of filesystem 'ino' Inode number 'mode' File mode (type and permissions) 'nlink' Number of (hard) links to the file 'uid' Numeric user ID of file's owner 'gid' Numeric group ID of file's owner 'rdev' The device identifier (special files only) 'size' Total size of file, in bytes 'atime' Last access time in seconds since the epoch 'mtime' Last modify time in seconds since the epoch 'ctime' Inode change time in seconds since the epoch 'blksize' Preferred block size for file system I/O 'blocks'Actual number of blocks allocated =item Clocaltime/Cgmtime 'sec' Second 'min' Minute 'hour' Hour 'mon' Month 'year' Year 'mday' Day of the month 'wday' Day of the week 'yday' Day of the year 'isdst' Is daylight savings time in effect (localtime only) =item Ccaller 'package' Name of the package from which sub was called 'file' Name of the file from which sub was called 'line' Line in the file from which sub was called 'sub' Name by which sub was called 'args' Was sub called with args? 'want' Hash of values returned by want() 'eval' Text of EXPR within eval EXPR 'req' Was sub called from a Crequire (or Cuse)? 'hints' Pragmatic hints with which sub was compiled 'bitmask' Bitmask with which sub was compiled =item Cgetpw* 'name' Username 'passwd'Crypted password 'uid' User ID 'gid' Group ID 'quota' Disk quota 'comment' Administrative comments 'gcos' User information 'dir' Home directory 'shell' Native shell 'expire'Expiry date of account of password =item Cgetgr* 'name' Group name 'passwd'Group password 'gid' Group id 'members' Group members =item Cgethost* 'name' Official host name 'aliases' Other host names 'addrtype' Host address type 'length'Length of address 'addrs' Anonymous array of raw addresses in 'C4' format =item Cgetnet* 'name' Official name of netwwork 'aliases'
Re: RFC 259 (v1) Builtins : Make use of hashref context for garrulous builtins
On Tue, Sep 19, 2000 at 07:00:36AM -, Perl6 RFC Librarian wrote: =head1 REFERENCES This RFC explains the mechanism by which HASHREF context would be detected: RFC 21: Replace Cwantarray with a generic Cwant function These RFCs propose alternative solutions to this problem: RFC 37: Positional Return Lists Considered Harmful RFC 127: Sane resolution to large function returns Don't forget RFC 48 which discusses a localtime() replacement returning a hash. -- Michael G Schwern http://www.pobox.com/~schwern/ [EMAIL PROTECTED] Just Another Stupid Consultant Perl6 Kwalitee Ashuranse gumballs have no paste Tim's balls are so damn pasty bend over and squeal -- |siv|
Re: RFC 259 (v1) Builtins : Make use of hashref context for garrulous builtins
It's hard to remember the sequence of values that the following builtins return: stat/lstat caller localtime/gmtime get* and though it's easy to look them up, it's a pain to look them up Every Single Time. Moreover, code like this is far from self-documenting: use File::stat; if ((stat $filename)[7] 1000) {...} if ((lstat $filename)[10] time()-1000) {...} use Time::localtime; if ((localtime(time))[3] 5) {...} use User::pwent; if ($usage (getpwent)[4]) {...} use Net::hostent; @host{qw(name aliases addrtype length addrs)} = gethostbyname $name; Don't have one for that. warn "Problem at " . join(":", @{[caller(0)]}[3,1,2]) . "\n"; It is proposed that, when one of these subroutines is called in the new HASHREF context (RFC 21), it should return a reference to a hash of values, with standardized keys. For example: Which is what the modules listed above do. And more. --tom
RFC 259 (v1) Builtins : Make use of hashref context for garrulous builtins
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Builtins : Make use of hashref context for garrulous builtins =head1 VERSION Maintainer: Damian Conway [EMAIL PROTECTED] Date: 19 September 2000 Mailing List: [EMAIL PROTECTED] Number: 259 Version: 1 Status: Developing =head1 ABSTRACT This RFC proposes the builtin functions that return a large number of values in an array context should also detect hashref contexts (see RFC 21) and return their data in a kinder, gentler format. =head1 DESCRIPTION It's hard to remember the sequence of values that the following builtins return: stat/lstat caller localtime/gmtime get* and though it's easy to look them up, it's a pain to look them up Every Single Time. Moreover, code like this is far from self-documenting: if ((stat $filename)[7] 1000) {...} if ((lstat $filename)[10] time()-1000) {...} if ((localtime(time))[3] 5) {...} if ($usage (getpwent)[4]) {...} @host{qw(name aliases addrtype length addrs)} = gethostbyname $name; warn "Problem at " . join(":", @{[caller(0)]}[3,1,2]) . "\n"; It is proposed that, when one of these subroutines is called in the new HASHREF context (RFC 21), it should return a reference to a hash of values, with standardized keys. For example: if (stat($filename)-{size} 1000) {...} if (lstat($filename)-{ctime} time()-1000) {...} if (localtime(time)-{mday} 5) {...} if ($usage getpwent()-{quota}) {...} %host = %{gethostbyname($name)}; warn "Problem at " . join(":", @{caller(0)}{qw(sub file line)} . "\n"; =head2 Standardized keys The standardized keys for these functions would be: =over 4 =item Cstat/Clstat 'dev' Device number of filesystem 'ino' Inode number 'mode' File mode (type and permissions) 'nlink' Number of (hard) links to the file 'uid' Numeric user ID of file's owner 'gid' Numeric group ID of file's owner 'rdev' The device identifier (special files only) 'size' Total size of file, in bytes 'atime' Last access time in seconds since the epoch 'mtime' Last modify time in seconds since the epoch 'ctime' Inode change time in seconds since the epoch 'blksize' Preferred block size for file system I/O 'blocks'Actual number of blocks allocated =item Clocaltime/Cgmtime 'sec' Second 'min' Minute 'hour' Hour 'mon' Month 'year' Year 'mday' Day of the month 'wday' Day of the week 'yday' Day of the year 'isdst' Is daylight savings time in effect (localtime only) =item Ccaller 'package' Name of the package from which sub was called 'file' Name of the file from which sub was called 'line' Line in the file from which sub was called 'sub' Name by which sub was called 'args' Was sub called with args? 'want' Hash of values returned by want() 'eval' Text of EXPR within eval EXPR 'req' Was sub called from a Crequire (or Cuse)? 'hints' Pragmatic hints with which sub was compiled 'bitmask' Bitmask with which sub was compiled =item Cgetpw* 'name' Username 'passwd'Crypted password 'uid' User ID 'gid' Group ID 'quota' Disk quota 'comment' Administrative comments 'gcos' User information 'dir' Home directory 'shell' Native shell 'expire'Expiry date of account of password =item Cgetgr* 'name' Group name 'passwd'Group password 'gid' Group id 'members' Group members =item Cgethost* 'name' Official host name 'aliases' Other host names 'addrtype' Host address type 'length'Length of address 'addrs' Anonymous array of raw addresses in 'C4' format =item Cgetnet* 'name' Official name of netwwork 'aliases' Other names for network