[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: change ni * protos



On Fri, 21 Jan 2000 16:48:26 MST, Tom Christiansen wrote:
>Could you please remind me why you intentionally broke
>
>    use strict;
>    sub fn(*) { my $fh = shift;  print $fh "Boo!\n" }
>    *SNEAK = *STDOUT;
>    fn(SNEAK);

Did you see:

  http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-04/msg00312.html

The long and the short of it is that the current semantics make it
possible to override builtins like open() and require(), which need to
see simple scalar values as they were passed, not as typeglobs.  When
you see the "*" prototype, think "any scalar including bareword" rather
than "typeglob".

>#########################
># This file:
>#########################
>
>    use strict;
>
>    $|=1; 
>
>    package Fab;
>
>    sub ululation(*) { 
>	my $fh = shift;

Replace that with:

        use Symbol 'qualify_to_ref';
	my $fh = qualify_to_ref(shift,caller);

>	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__


Sarathy
gsar@ActiveState.com


Follow-Ups from:
Gurusamy Sarathy <gsar@ActiveState.com>
Tim Bunce <Tim.Bunce@ig.co.uk>
References to:
Tom Christiansen <tchrist@chthon.perl.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]