Skip Menu |
 
Report information
Id: 22973
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: gmpassos <gm [at] virtuasites.com.br>
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: medium
Type: Patch
Perl Version: 5.8.1
Fixed In: 5.8.1



From: "Graciliano M. P. \(Virtua Sites\)" <gm [...] virtuasites.com.br>
To: <perlbug [...] perl.org>
Subject: Tied HASH as boolean always return false.
Date: Sat, 12 Jul 2003 04:28:23 -0300
Download (untitled) / with headers
text/plain 3.5k
A tied HASH when used as a boolean always return it as false! Example: my %hash ; tie(%hash , 'TiedHash') ; print "key: $hash{key}\n" ; if ( %hash ) { print "BOOL: 1\n" ;} else { print "BOOL: 0\n" ;} package TiedHash ; sub TIEHASH { bless({}, __PACKAGE__ ) ;} sub FETCH { return( 'fetch_val' ) ;} But if you set some data before set it as HASH not: my %hash = (1) ; tie(%hash , 'TiedHash') ; if ( %hash ) { print "BOOL: 1\n" ;} else { print "BOOL: 0\n" ;} package TiedHash ; sub TIEHASH { bless({}, __PACKAGE__ ) ;} I know that some Perl developers already know that. But this isn't documented and we can see that doesn't work in a beatiful way, or like it should be. What I think that can be done is to add a new TIE function BOOLEAN to catch the query of the boolean value, and if the functions doesn't exists return false to mantain the compatibility. I will look at Perl source to send some path for the new function. But if the change for the new function is not interesting for you, at least change the POD and add some commet about that. Regards, Graciliano M. P. PS: perlbug script never works for Win32! ------------------------------------------------------------------ Summary of my perl5 (revision 5 version 8 subversion 0) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE _DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL _MSVCRT_READFIX', optimize='-MD -Zi -DNDEBUG -O1', cppflags='-DWIN32' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags '-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"c:\perl\lib\CORE" -ma chine:x86' libpth="C:\perl\lib\CORE" "C:\Arquivos de programas\Microsoft Visual Studio\VC98\Lib" libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib gnulibc_version='undef' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -libpath:"c:\perl \lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS Locally applied patches: Perl Build 805 Built under MSWin32 Compiled at Mar 15 2003 19:25:16 @INC: C:/perl/lib C:/perl/site/lib .
Download (untitled) / with headers
text/plain 303b
FWIW, 5.8.1 RC2 hash changed the behavior of testing the boolean condition of a tied hash to an error: Can't provide tied hash usage; use keys(%hash) to test if empty at - line 7. until there is some way of returning bucket information from a tied hash (ie. what a hash returns in scalar context).
From: "Graciliano M. P. \(Virtua Sites\)" <gm [...] virtuasites.com.br>
To: <perlbug-followup [...] perl.org>
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
Date: Wed, 16 Jul 2003 10:51:21 -0300
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.8k
Show quoted text
> Subject: [perl #22973] Tied HASH as boolean always return false.
Show quoted text
> FWIW, 5.8.1 RC2 hash changed the behavior of testing the boolean condition
of a tied Show quoted text
> hash to an error:
Noooo!!! Now all my scripts that uses tied HASH will die!!! For example, in mod_perl, I use a module that handles the incoming formulary data, separating them in 2 hashes %POST and %GET, and an extra hash %FORM, where %FORM can access all the keys of %POST and %GET at the same time. But %FORM is only tied when I receive the 2 types of form, and when I have only 1 type it's just a link in the table to %POST or %GET. The best thing of %FORM is to can check easy if I have formulary data using: if ( %FORM ) { ... } ... and now this isn't possible, and every thing will die! Note that to enable the boolean check to %FORM, the HASH that is tied has a key seted before tie it: %hash = (1) ; tie( \%hash , 'tiehandle' ) ; Show quoted text
> Can't provide tied hash usage; use keys(%hash) to test if empty at -
line 7. OK, but I think that kind of change is not good for a fix release, since 5.8.1 is about that. And create an erro?! At least keep the compatibility with what we have before, or make the tie boolean return true always, since if you tie something you have it! Please, please, remove the error, and keep what exists before! And when we a have path for that we change the behavior, insted to say to the user that what it have is wrong! And what we have isn't wrong, it's just not implemented in the right way yet. Other thing. The best thing that should be made without implement the boolean handler for tied hashes is to add to the POD that to make a tied HASH return true, you need to have keys in the hash reference that isn't tied. Show quoted text
> until there is some way of returning bucket information from a tied hash
(ie. what a Show quoted text
> hash returns in scalar context).
I will look for a path, maybe before release 5.8.1! Regards, Graciliano M. P.
Date: Wed, 16 Jul 2003 14:20:03 -0700
From: Michael G Schwern <schwern [...] pobox.com>
To: "Graciliano M. P. (Virtua Sites)" <gm [...] virtuasites.com.br>
CC: perlbug-followup [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.1k
On Wed, Jul 16, 2003 at 10:51:21AM -0300, Graciliano M. P. (Virtua Sites) wrote: Show quoted text
> > Can't provide tied hash usage; use keys(%hash) to test if empty at -
> line 7. > > OK, but I think that kind of change is not good for a fix release, since > 5.8.1 is about that.
I'd tend to agree. Show quoted text
> And create an erro?! At least keep the compatibility with what we have > before, or make the tie boolean return true always, since if you tie > something you have it!
That just changes the behavior from wrong to a different kind of wrong. An *empty* hash will return false in scalar context. So should an empty tied hash. What could be done is: A) downgrade the error to a warning B) remove the message a together since its kind of lame as we currently have no good fix and people have survived for years with the current behavior C) do what the warning suggests behind the scenes. In boolean context, just fallback to using keys(%hash). I prefer B or C. C remains the Right Thing even if we introduce a true BUCKET method for tied hashes later on. -- I know you get this a lot, but what's an unholy fairy like you doing in a mosque like this?
To: perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
Date: Wed, 16 Jul 2003 17:35:45 -0400
From: Mark Jason Dominus <mjd [...] plover.com>
RT-Send-Cc:
Download (untitled) / with headers
text/plain 683b
Show quoted text
> What I think that can be done is to add a new TIE function BOOLEAN > to catch the query of the boolean value, and if the functions > doesn't exists return false to mantain the compatibility.
It seems to me that this is the wrong approach. I'm not sure what the right approach is, but I think it would be something more like a FETCHSIZE method which would return the total number of keys. It might also be a KEYS method which can be called in list context or scalar context when the result of 'keys' or 'values' was needed; if KEYS was undefined Perl could fall back on using FIRSTKEY and NEXTKEY as it does now. This would be more work and more code, but also more useful.
Date: Wed, 16 Jul 2003 14:52:06 -0700
From: Michael G Schwern <schwern [...] pobox.com>
To: Mark Jason Dominus <mjd [...] plover.com>
CC: perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 981b
On Wed, Jul 16, 2003 at 05:35:45PM -0400, Mark Jason Dominus wrote: Show quoted text
> > What I think that can be done is to add a new TIE function BOOLEAN > > to catch the query of the boolean value, and if the functions > > doesn't exists return false to mantain the compatibility.
> > It seems to me that this is the wrong approach. I'm not sure what the > right approach is, but I think it would be something more like a > FETCHSIZE method which would return the total number of keys. > > It might also be a KEYS method which can be called in list context or > scalar context when the result of 'keys' or 'values' was needed; if > KEYS was undefined Perl could fall back on using FIRSTKEY and NEXTKEY > as it does now. This would be more work and more code, but also more > useful.
Trouble is, you need more than just the number of keys to fully emulate the current behavior of a hash in scalar context. $ perl -wle '%h = (foo => 42); print scalar %h' 1/8 -- IGNITE THE FIRE MOAT!
Date: Wed, 16 Jul 2003 12:04:07 -1000 (HST)
From: Tim Jenness <t.jenness [...] jach.hawaii.edu>
To: Michael G Schwern <schwern [...] pobox.com>
CC: Mark Jason Dominus <mjd [...] plover.com>, Perl 5 porters <perl5-porters [...] perl.org>
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.2k
On Wed, 16 Jul 2003, Michael G Schwern wrote: Show quoted text
> On Wed, Jul 16, 2003 at 05:35:45PM -0400, Mark Jason Dominus wrote:
> > > What I think that can be done is to add a new TIE function BOOLEAN > > > to catch the query of the boolean value, and if the functions > > > doesn't exists return false to mantain the compatibility.
> > > > It seems to me that this is the wrong approach. I'm not sure what the > > right approach is, but I think it would be something more like a > > FETCHSIZE method which would return the total number of keys. > > > > It might also be a KEYS method which can be called in list context or > > scalar context when the result of 'keys' or 'values' was needed; if > > KEYS was undefined Perl could fall back on using FIRSTKEY and NEXTKEY > > as it does now. This would be more work and more code, but also more > > useful.
> > Trouble is, you need more than just the number of keys to fully emulate the > current behavior of a hash in scalar context. > > $ perl -wle '%h = (foo => 42); print scalar %h' > 1/8 >
Since a tied hash does not have to refer to a real hash couldn't this be emulated simply by returning the result as if the tied hash was a perfect hash? -- Tim Jenness JAC software http://www.jach.hawaii.edu/~timj
Date: Wed, 16 Jul 2003 18:10:16 -0400
From: Ronald J Kimball <rjk [...] linguist.Thayer.dartmouth.edu>
To: Michael G Schwern <schwern [...] pobox.com>
CC: Mark Jason Dominus <mjd [...] plover.com>, perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.3k
On Wed, Jul 16, 2003 at 02:52:06PM -0700, Michael G Schwern wrote: Show quoted text
> On Wed, Jul 16, 2003 at 05:35:45PM -0400, Mark Jason Dominus wrote:
> > > What I think that can be done is to add a new TIE function BOOLEAN > > > to catch the query of the boolean value, and if the functions > > > doesn't exists return false to mantain the compatibility.
> > > > It seems to me that this is the wrong approach. I'm not sure what the > > right approach is, but I think it would be something more like a > > FETCHSIZE method which would return the total number of keys. > > > > It might also be a KEYS method which can be called in list context or > > scalar context when the result of 'keys' or 'values' was needed; if > > KEYS was undefined Perl could fall back on using FIRSTKEY and NEXTKEY > > as it does now. This would be more work and more code, but also more > > useful.
> > Trouble is, you need more than just the number of keys to fully emulate the > current behavior of a hash in scalar context. > > $ perl -wle '%h = (foo => 42); print scalar %h' > 1/8
In fact, for that you don't really need the number of keys at all. :) It's occupied buckets/allocated buckets. But precisely emulating the behavior of a hash in scalar context seems a bit silly, since the behavior is based on the internal implementation of the hash, and the internals of a tied hash often aren't like a regular hash. Ronald
Date: Wed, 16 Jul 2003 15:32:03 -0700
From: Michael G Schwern <schwern [...] pobox.com>
To: Tim Jenness <t.jenness [...] jach.hawaii.edu>
CC: Mark Jason Dominus <mjd [...] plover.com>, Perl 5 porters <perl5-porters [...] perl.org>
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 460b
On Wed, Jul 16, 2003 at 12:04:07PM -1000, Tim Jenness wrote: Show quoted text
> Since a tied hash does not have to refer to a real hash couldn't > this be emulated simply by returning the result as if the tied > hash was a perfect hash?
Given that the scalar value of a hash is rather silly, and having a method to perfectly emulate it would be even sillier, I don't see why not. -- Cuius rei demonstrationem mirabilem sane detexi hanc subscriptis exiguitas non caperet.
Date: Thu, 17 Jul 2003 02:21:39 +0300
From: Enache Adrian <enache [...] rdslink.ro>
To: Michael G Schwern <schwern [...] pobox.com>
CC: "Graciliano M. P. (Virtua Sites)" <gm [...] virtuasites.com.br>, perlbug-followup [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.2k
On Wed, Jul 16, 2003 at 02:20:03PM -0700, Michael G Schwern wrote: Show quoted text
> On Wed, Jul 16, 2003 at 10:51:21AM -0300, Graciliano M. P. (Virtua Sites) wrote:
> > > Can't provide tied hash usage; use keys(%hash) to test if empty at -
> > line 7. > >
$ perl -le '{package P; sub TIEHASH {bless{}}} tie my %h, P; print "yeah\n" if scalar %h' Can't provide tied hash usage; use keys(%hash) to test if empty at -e line 1. $ perl -le '{package P; sub TIEHASH {bless{}}} tie %h, P; print "yeah\n" if scalar %h' $ why does Perl issue the error only when %h is in the pad ? That should be fixed somehow. Show quoted text
> What could be done is: > > A) downgrade the error to a warning > B) remove the message a together since its kind of lame as we currently > have no good fix and people have survived for years with the current > behavior > C) do what the warning suggests behind the scenes. In boolean context, > just fallback to using keys(%hash). > > I prefer B or C. C remains the Right Thing even if we introduce a true > BUCKET method for tied hashes later on.
Why should perl start doing a lot of crap behind your back (iterate through an entire tied hash) when you only wanted if know if the hash contained at least _one_ key ? :-) Regards, Adi
Date: Thu, 17 Jul 2003 02:46:10 +0300
From: Enache Adrian <enache [...] rdslink.ro>
To: Mark Jason Dominus <mjd [...] plover.com>
CC: perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 609b
On Wed, Jul 16, 2003 at 05:35:45PM -0400, Mark Jason Dominus wrote: Show quoted text
>
> > What I think that can be done is to add a new TIE function BOOLEAN > > to catch the query of the boolean value, and if the functions > > doesn't exists return false to mantain the compatibility.
> > It seems to me that this is the wrong approach. I'm not sure what the > right approach is, but I think it would be something more like a > FETCHSIZE method which would return the total number of keys.
Does testing if FIRSTKEY returns something define'd sound reasonable enough as the boolean test for a tied hash ? Regards, Adi
Date: Thu, 17 Jul 2003 03:11:04 +0300
From: Enache Adrian <enache [...] rdslink.ro>
To: Dave Mitchell <davem [...] fdgroup.com>
CC: Enache Adrian <enache [...] rdslink.ro>, Michael G Schwern <schwern [...] pobox.com>, "Graciliano M. P. (Virtua Sites)" <gm [...] virtuasites.com.br>, perlbug-followup [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 527b
On Thu, Jul 17, 2003 at 12:51:32AM +0100, Dave Mitchell wrote: Show quoted text
> On Thu, Jul 17, 2003 at 02:21:39AM +0300, Enache Adrian wrote:
> > Why should perl start doing a lot of crap behind your back (iterate through > > an entire tied hash) when you only wanted if know if the hash contained > > at least _one_ key ? :-)
> > Why can't a tied hash in a scalar context call FIRSTKEY, and if > that method returns undef, return '0', else return '1/8'. This would at > least solve the 'is the hash empty problem'
Agreed. Regards, Adi
Date: Wed, 16 Jul 2003 18:16:43 -0700
From: Michael G Schwern <schwern [...] pobox.com>
To: Mark Jason Dominus <mjd [...] plover.com>, perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 478b
On Thu, Jul 17, 2003 at 02:46:10AM +0300, Enache Adrian wrote: Show quoted text
> > It seems to me that this is the wrong approach. I'm not sure what the > > right approach is, but I think it would be something more like a > > FETCHSIZE method which would return the total number of keys.
> > Does testing if FIRSTKEY returns something define'd sound reasonable > enough as the boolean test for a tied hash ?
Yes, that'll do for boolean context. Not sure about non-boolean scalar contexts.
Date: Wed, 16 Jul 2003 23:32:02 -0400
From: Ronald J Kimball <rjk [...] linguist.Thayer.dartmouth.edu>
To: perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 453b
On Thu, Jul 17, 2003 at 02:46:10AM +0300, Enache Adrian wrote: Show quoted text
> > It seems to me that this is the wrong approach. I'm not sure what the > > right approach is, but I think it would be something more like a > > FETCHSIZE method which would return the total number of keys.
> > Does testing if FIRSTKEY returns something define'd sound reasonable > enough as the boolean test for a tied hash ?
What effect will that have on the hash iterator? Ronald
Subject: Re: Tied HASH as boolean always return false. (New method FILL and with previous compatibility)
Download (untitled) / with headers
text/plain 952b
The use of HASH as boolean was fixed and the compatibility with the previous versions of Perl was keeped too. Changes: ( File: pp.c at pp_padhv() ) New handler method FILL added to for a tied HASH. Behavior: First look for the method in the objet, if the method FILL exists, call it, and the returned value (G_SCALAR) is paste as the scalar/boolean value of the HASH. If the method FILL doesn't exists, get the buckets size as the normal/previous way, to keep the compatibility. Test Script of Changes: ## To test the previous behavior (when method FILL doesn't exists): #my %hash = (1) ; my %hash ; my $tieobj = tie(%hash , 'TiedHash') ; if ( %hash ) { print "BOOL: 1\n" ;} else { print "BOOL: 0\n" ;} my $buckets = %hash ; print "BUCKETS: $buckets\n" ; package TiedHash ; sub TIEHASH { bless({}, __PACKAGE__ ) ;} ## Try to change the return to a false value: sub FILL { print "FILL>> $_[0]\n" ; return "1/8" ;}
Download pp.c.diff
text/plain 1k
109,114c109,130 < SV* sv = sv_newmortal(); < if (SvRMAGICAL(TARG) && mg_find(TARG, PERL_MAGIC_tied)) < Perl_croak(aTHX_ "Can't provide tied hash usage; " < "use keys(%%hash) to test if empty"); < if (HvFILL((HV*)TARG)) < Perl_sv_setpvf(aTHX_ sv, "%ld/%ld", --- > bool ret_buckets = TRUE ; > MAGIC *mg; > if ( SvRMAGICAL(TARG) && (mg = mg_find(TARG, PERL_MAGIC_tied)) ) { > SV *obj = SvRV(mg->mg_obj); > GV *gv; > CV *cv = NULL; > if ( (gv = gv_fetchmethod_autoload(SvSTASH(obj), "FILL", FALSE)) && isGV(gv) && (cv = GvCV(gv))) { > ret_buckets = FALSE ; > PUSHMARK(SP); > XPUSHs(SvTIED_obj((SV*)gv, mg)); > XPUSHs(sv_2mortal(newSViv(SvREFCNT(obj)-1))); > PUTBACK; > ENTER; > call_sv((SV *)cv, G_SCALAR); > LEAVE; > SPAGAIN; > } > } > if (ret_buckets) { > SV* sv = sv_newmortal(); > if (HvFILL((HV*)TARG)) > Perl_sv_setpvf(aTHX_ sv, "%ld/%ld", 116,118c132,135 < else < sv_setiv(sv, 0); < SETs(sv); --- > else > sv_setiv(sv, 0); > SETs(sv); > }
Date: Thu, 17 Jul 2003 00:51:32 +0100
From: Dave Mitchell <davem [...] fdgroup.com>
To: Enache Adrian <enache [...] rdslink.ro>
CC: Michael G Schwern <schwern [...] pobox.com> , "Graciliano M. P. (Virtua Sites)" <gm [...] virtuasites.com.br> , perlbug-followup [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 517b
On Thu, Jul 17, 2003 at 02:21:39AM +0300, Enache Adrian wrote: Show quoted text
> Why should perl start doing a lot of crap behind your back (iterate through > an entire tied hash) when you only wanted if know if the hash contained > at least _one_ key ? :-)
Why can't a tied hash in a scalar context call FIRSTKEY, and if that method returns undef, return '0', else return '1/8'. This would at least solve the 'is the hash empty problem' -- O Unicef Clearasil! Gibberish and Drivel! - "Bored of the Rings"
From: "Graciliano M. P. \(Virtua Sites\)" <gm [...] virtuasites.com.br>
To: <perlbug-followup [...] perl.org>
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
Date: Wed, 16 Jul 2003 22:20:00 -0300
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.7k
Show quoted text
> Does testing if FIRSTKEY returns something define'd sound reasonable > enough as the boolean test for a tied hash ?
This is a good point, since it's faster to process, instead fo: (keys (%hash)) But I still think that the best way is to introduce a new function: BOOLEAN. And the user make what it want, just returning a true value (in the format that it want) or not. And if the BOOLEAN function doesn't exists, make the behavior works like in 5.8.0, just return FALSE or TRUE depending the content of the real HASH reference (the previous when it's tied). And this is not to about to fully emulate the current behavior of a hash! This is just to can now if a HASH is null or not! No one want to make this: my $hash_buckets_use = %hash ; We just want to make: if ( %HASH ) { ... } ...and the problem is in the behavior of the HASH as boolean, not to get the buckets use of a tied HASH, that make no sense! But looking in the implementation of this in Perl, at pp.c, I saw that is not good to call a method called BOOLEAN when trying to implement the behavior. Since the implementation, when checking the boolean value, look for the buckets size: if (HvFILL((HV*)TARG)) Perl_sv_setpvf(aTHX_ sv, "%ld/%ld", (long)HvFILL((HV*)TARG), (long)HvMAX((HV*)TARG) + 1); // return the buckets use (true) else sv_setiv(sv, 0); // return buckets as 0 (false) ... The best way is to implement a method that works in the FILL area (if it uses buckets or not), not in the buckets result/value. *** I'm working in a path for this, I just need to know what name to use! So, please, send your best ideas, and note, this is for a function that just tell if the HASH is null or not, if it FILLs something or not, to follow the actuall internal structure of the implementation. Regards, Graciliano M. P.
Date: Wed, 16 Jul 2003 22:42:38 -0400
From: Rick Delaney <rick.delaney [...] rogers.com>
To: perl5-porters [...] perl.org
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
RT-Send-Cc:
Download (untitled) / with headers
text/plain 947b
On Thu, Jul 17, 2003 at 02:46:10AM +0300, Enache Adrian wrote: Show quoted text
> On Wed, Jul 16, 2003 at 05:35:45PM -0400, Mark Jason Dominus wrote:
> >
> > > What I think that can be done is to add a new TIE function BOOLEAN > > > to catch the query of the boolean value, and if the functions > > > doesn't exists return false to mantain the compatibility.
> > > > It seems to me that this is the wrong approach. I'm not sure what the > > right approach is, but I think it would be something more like a > > FETCHSIZE method which would return the total number of keys.
> > Does testing if FIRSTKEY returns something define'd sound reasonable > enough as the boolean test for a tied hash ?
That might screw up someone's iterator pointer. Using the example FIRSTKEY and NEXTKEY from perltie, this would loop forever: while (($k, $v) = each %h) { print "This is for illustration only\n" if %h; } -- Rick Delaney rick.delaney@rogers.com
From: "Graciliano M. P. \(Virtua Sites\)" <gm [...] virtuasites.com.br>
To: <perlbug-followup [...] perl.org>
Subject: Re: [perl #22973] Tied HASH as boolean always return false.
Date: Thu, 17 Jul 2003 01:05:36 -0300
RT-Send-Cc:
Download (untitled) / with headers
text/plain 228b
I have sent the PATH for that (for Perl-5.8.1-RC2)! But this is the 1st time that I send a PATH to Perl, please, check if everything goes fine, since this need to be applied before release Perl-5.8.1 Regards, Graciliano M. P.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org