Re: Trivial Question

[prev] [thread] [next] [Date index for 2005/06/11]

From: Cees Hek
Subject: Re: Trivial Question
Date: 01:56 on 11 Jun 2005
How about sticking something like this in your base class:

sub hashref {
  my $self =3D shift;
  my @cols =3D @_ ? @_ : $self->columns();
  my %hash;
  # pull the data, and keep NULLs as undef, stringify the rest
  @hash{@cols} =3D map { defined $_ ? "".$_ : undef } $self->get(@cols);
  return \%hash;
}

You can then call ->hashref on any object and pass it a list of
columns you want, or it will just return values for all columns in the
table.

Cheers,

Cees

On 6/10/05, David Christensen <dwc@xxxx.xxx> wrote:
> Hey list,
>=20
> I'm sure this is a really basic question with a quick answer, but I was
> not able to find it by scouring the docs or by googling.  If I have an
> object and I want to extract the fields and values as a hash, what is
> the sanctioned way of doing this?  (I believe I read on-list that the
> object could more-or-less be treated as a hashref, but I want something
> that will continue to work across releases, and that seems a bit too
> implementation specific for me to stomach---not to mention that the
> inflate/deflate routine may or may not be called, nor may all of the
> fields have been fetched.)  I can't be the only person to want this, so
> please let me know what I'm missing.  :)
>=20
> Thanks,
>=20
> David Christensen
>=20
>

(message missing)

Trivial Question
David Christensen 01:36 on 11 Jun 2005

Re: Trivial Question
Cees Hek 01:56 on 11 Jun 2005

Re: Trivial Question
David Christensen 12:58 on 11 Jun 2005

Re: Trivial Question
Tony Bowden 07:30 on 11 Jun 2005

Re: Trivial Question
Michael G Schwern 20:32 on 11 Jun 2005

Re: Trivial Question
Tony Bowden 21:49 on 11 Jun 2005

Re: Trivial Question
Michael G Schwern 00:15 on 12 Jun 2005

Re: Trivial Question
Emanuele Zeppieri 08:27 on 12 Jun 2005

Relationship question.
Rod Za 18:15 on 13 Jun 2005

Re: Relationship question.
Matt S Trout 02:07 on 14 Jun 2005

Re: Relationship question.
Aaron Trevena 08:41 on 14 Jun 2005

Re: Relationship question.
Rod Za 16:25 on 14 Jun 2005

Generated at 16:37 on 28 Jul 2005 by mariachi v0.52