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

Re: Class::Fields, a base/fields.pm rewrite



On Sun, Jan 09, 2000 at 12:31:16AM -0500, Ilya Zakharevich wrote:
> On Sat, Jan 08, 2000 at 10:59:09PM -0500, Michael G Schwern wrote:
> > sub has_fields {
> >         my($class) = shift;
> >         my $fglob;
> >         return $fglob = ${"$class\::"}{"FIELDS"} and *$fglob{HASH};
> 
> Probably '&&', not 'and'.
> 
> > }
> 
>   sub has_fields { *{ ${ shift() . '::' }{FIELDS} || \*has_fields }{HASH} }
> 
> 1/2 ;-)

No, I believe it has to be 'and'.  The statement is actually written
in a confusing manner.  I'm trying to accomplish this:

        if( $fglob = ${"$class\::"}{"FIELDS"} ) {
                return (*$fglob{HASH}) ? 1 : 0;
        }
        else {
                return 0;
        }

not this

        $fglob = ${"$class\::"}{"FIELDS"};
        $fglob = *$fglob{HASH} if $fglob;
        return $fglob;

Either way, its written confusingly.  I'll see if I can clear it up.


BTW return $fglob = ${"$class\::"}{"FIELDS"} && *$fglob{HASH}; doesn't
work since $fglob needs to be set before *$fglob{HASH} is checked.

$ perl -wle 'package Foo;  use fields qw(foo);  my $class = "Foo";  sub has_fields { return $fglob = ${"$class\::"}{"FIELDS"} && *$fglob{HASH}; }  print has_fields'
Can't use an undefined value as a symbol reference at -e line 1.



-- 

Michael G Schwern                                           schwern@pobox.com
                    http://www.pobox.com/~schwern
     /(?:(?:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i


Follow-Ups from:
Larry Wall <larry@wall.org>
Ilya Zakharevich <ilya@math.ohio-state.edu>
References to:
Michael G Schwern <schwern@pobox.com>
Ilya Zakharevich <ilya@math.ohio-state.edu>
Michael G Schwern <schwern@pobox.com>
Ilya Zakharevich <ilya@math.ohio-state.edu>

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