[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
change ni * protos
Could you please remind me why you intentionally broke
    use strict;
    sub fn(*) { my $fh = shift;  print $fh "Boo!\n" }
    *SNEAK = *STDOUT;
    fn(SNEAK);
In _54, this was fine, because the prototype caused the function
to receive *SNEAK instead of 'SNEAK' as an argument.  Now, it just
gets a bareword string, which seems to defeat the purpose of the
prototype.  Typeglob protos used to be documented as follows (in
Camel II):
    And a * does whatever it has to do to turn the argument into a
    reference to a symbol table entry.  It's typically used for
    filehandles.
But they are now documented in perlsub(1) like this:
    A * allows the subroutine to accept a bareword, constant, scalar
    expression, typeglob, or a reference to a typeglob in that slot.
    The value will be available to the subroutine either as a simple
    scalar, or (in the latter two cases) as a reference to the
    typeglob.
I don't understand the win.  Now every function that hopes to use
this a filehandle passed in has to pull in Symbol::qualify_to_ref(),
or do the equivalent work.  That means the function that used to
say
    my $fh = shift;
must now say:
    use Symbol;
    my $fh = Symbol::qualify_to_ref(shift, caller);
There are other subtle problems, too.  If you don't lock it in right
away, you're doomed.  You can't do anything useful with that value,
like storing it into a data structure or passing it to another
function, without doing the Symbol::qualify_to_ref() thing on the
value first.  You'd lose the critical caller info otherwise.  This 
was never a concern when you had a real typeglob, and now it is.
It's bad enough that it breaks old code; in fact, this is *not* in
the release notes as a code-breaking incompatibility, but needs to
be!  Perhaps worse still, I can't see how this is an advantage.  It
also to my eye causes a lot more work than we ever had to go through
before.  What is the purpose?  I don't understand.  I'm sure you
had a good reason, but I am not seeing it.
Thank you,
--tom
#########################
# This file:
#########################
    use strict;
    $|=1; 
    package Fab;
    sub ululation(*) { 
	my $fh = shift;
	print $fh "this went out $fh\n"
	    or warn "failed to print to fh $fh: $!\n";
    } 
    package main;
    print "testing *STDOUT...."; Fab::ululation(*STDOUT);
    print "testing *stdout...."; Fab::ululation(*stdout);
    print "testing *STDOUT{IO}...."; Fab::ululation(*STDOUT{IO});
    print "testing *stdout{IO}...."; Fab::ululation(*stdout{IO});
    print "testing STDOUT...."; Fab::ululation(STDOUT);
    print "testing stdout...."; Fab::ululation(stdout);
    print "testing *snigglebottom...."; Fab::ululation(*snigglebottom);
    print "testing *snigglebottom{IO}...."; Fab::ululation(*snigglebottom{IO});
    print "testing snigglebottom...."; Fab::ululation(snigglebottom);
    __END__
#########################
# Produced this in _54:
#########################
testing *STDOUT....this went out GLOB(0x8dc18)
testing *stdout....this went out GLOB(0x8dc3c)
testing *STDOUT{IO}....this went out GLOB(0x8d054)
testing *stdout{IO}....this went out GLOB(0x8d054)
testing STDOUT....this went out GLOB(0x8dc18)
testing stdout....this went out GLOB(0x8dc3c)
testing *snigglebottom....failed to print to fh GLOB(0x9b4b4): Bad file descriptor
testing *snigglebottom{IO}....Can't use an undefined value as a symbol reference at /tmp/globtest line 26.
############################
# But produced this in _63:
############################
testing *STDOUT....this went out GLOB(0xa5490)
testing *stdout....this went out GLOB(0xa54b4)
testing *STDOUT{IO}....this went out IO::Handle=IO(0xa54a8)
testing *stdout{IO}....this went out IO::Handle=IO(0xa54a8)
testing STDOUT....Can't use string ("STDOUT") as a symbol ref while "strict refs" in use at /tmp/globtest line 9.
- Follow-Ups from:
 - 
Gurusamy Sarathy <gsar@ActiveState.com>
 
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]