From: Roderick Schertler Date: Wed, 12 Mar 1997 00:39:36 +0000 (-0500) Subject: New subroutine Symbol::qualify_to_ref() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=578b087ab63db59886b8f9a1e8bebc8524523fa5;p=p5sagit%2Fp5-mst-13.2.git New subroutine Symbol::qualify_to_ref() Subject: Re: select under use strict On Tue, 11 Mar 1997 16:36:25 -0500 (EST), Trevor Blackwell said: > > use strict; > syswrite(select,"",0) || warn("$!"); [...] > yields: > > Can't use string ("main::STDOUT") as a symbol ref [...] It seems a reasonable candidate for a new function in Symbol.pm, a function just like qualify() which returns a globref. Here's an implementation. I'll send this in again after 5.004. In the meanwhile you could just put something like it in your own code. Usage would be like syswrite ref_qualify(select), "foo\n", 4 or die $!; p5p-msgid: pzlo7ut03b.fsf@eeyore.ibcinc.com --- diff --git a/lib/Symbol.pm b/lib/Symbol.pm index e40ae7b..38927d9 100644 --- a/lib/Symbol.pm +++ b/lib/Symbol.pm @@ -23,6 +23,10 @@ Symbol - manipulate Perl symbols and their names print qualify(\*x), "\n"; # returns \*x print qualify(\*x, "FOO"), "\n"; # returns \*x + use strict refs; + print { ref_qualify $fh } "foo!\n"; + $ref = ref_qualify $name, $pkg; + =head1 DESCRIPTION C creates an anonymous glob and returns a reference @@ -44,6 +48,10 @@ Qualification applies only to symbol names (strings). References are left unchanged under the assumption that they are glob references, which are qualified by their nature. +C is just like C except that it +returns a glob ref rather than a symbol name. You can use the result +even if C is in effect. + =cut BEGIN { require 5.002; } @@ -51,7 +59,9 @@ BEGIN { require 5.002; } require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(gensym ungensym qualify); +@EXPORT = qw(gensym ungensym qualify ref_qualify); + +$VERSION = 1.02; my $genpkg = "Symbol::"; my $genseq = 0; @@ -88,4 +98,8 @@ sub qualify ($;$) { $name; } +sub ref_qualify ($;$) { + return \*{ qualify $_[0], @_ > 1 ? $_[1] : caller }; +} + 1;