Perl won't eval PgSQL boolean value

Perl won't eval PgSQL boolean value

Post by Randall Per » Wed, 05 Sep 2001 01:43:12



I've got an if statement that checks if a boolean value is true:

    if ($cust_data->{'hold'} eq 't')

But perl will not evaluate the value. $cust_data->{'hold'} is taken from a
PgSQL boolean field (either t or f). If I use the construct above it tell me
that 'eq' is not defined thinking it's a string.

If I use:
if ($cust_data->{'hold'} == 't')

I get an error saying $cust_data->{'hold'} is a non-numeric value.

If I do this:
 if ($cust_data->{'hold'})

it will always evaluate to true whether the value is 't' or 'f'.

HELP. How do you evaluate boolean values from PgSQL in Perl?

--
Randy Perry
sysTame
Mac Consulting/Sales

phn                 561.589.6449

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

 
 
 

Perl won't eval PgSQL boolean value

Post by Andrew Sno » Wed, 05 Sep 2001 03:14:44


When comparing strings in perl you usually use the eq operator, not ==

e.g.  if($cust_data->{hold} eq 't')

- Andrew

> -----Original Message-----


> Sent: Monday, 3 September 2001 10:01 AM

> Subject: [GENERAL] Perl won't eval PgSQL boolean value

> I've got an if statement that checks if a boolean value is true:

>     if ($cust_data->{'hold'} eq 't')

> But perl will not evaluate the value. $cust_data->{'hold'} is
> taken from a PgSQL boolean field (either t or f). If I use
> the construct above it tell me that 'eq' is not defined
> thinking it's a string.

> If I use:
> if ($cust_data->{'hold'} == 't')

> I get an error saying $cust_data->{'hold'} is a non-numeric value.

> If I do this:
>  if ($cust_data->{'hold'})

> it will always evaluate to true whether the value is 't' or 'f'.

> HELP. How do you evaluate boolean values from PgSQL in Perl?

> --
> Randy Perry
> sysTame
> Mac Consulting/Sales

> phn                 561.589.6449

> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command


 
 
 

Perl won't eval PgSQL boolean value

Post by postg.. » Wed, 05 Sep 2001 04:43:40



Quote:> I've got an if statement that checks if a boolean value is true:

>     if ($cust_data->{'hold'} eq 't')

> But perl will not evaluate the value. $cust_data->{'hold'} is taken from a
> PgSQL boolean field (either t or f). If I use the construct above it tell
> me that 'eq' is not defined thinking it's a string.

This should work just fine.  It sounds like a quote is being dropped
somewhere...
I just tested it here and it works just fine.

Quote:> If I use:
> if ($cust_data->{'hold'} == 't')

> I get an error saying $cust_data->{'hold'} is a non-numeric value.

Which is what it should do.  '==' is for numerics only.

Quote:> If I do this:
>  if ($cust_data->{'hold'})

> it will always evaluate to true whether the value is 't' or 'f'.

Again, what it should do,  both 't' and 'f' are non-zero as far as Perl is
concerned.

Quote:

> HELP. How do you evaluate boolean values from PgSQL in Perl?

Your first choice (value eq 't') should do the trick.  However, it sounds
like there is another problem interfering with it.  Could we see the code?

GB

--
GB Clark II             | Roaming FreeBSD Admin

           CTHULU for President - Why choose the lesser of two evils?

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl

 
 
 

Perl won't eval PgSQL boolean value

Post by Peter Hawort » Fri, 07 Sep 2001 12:53:49



> I've got an if statement that checks if a boolean value is true:

>     if ($cust_data->{'hold'} eq 't')

> But perl will not evaluate the value. $cust_data->{'hold'} is taken from a
> PgSQL boolean field (either t or f). If I use the construct above it tell
> me that 'eq' is not defined thinking it's a string.

Assuming that you're using DBI and DBD::Pg, the problem is that DBD::Pg
returns 1 and 0 for booleans, rather than the expected 't' and 'f'. This
means that if you know you're always going to use Postgres (and that DBD::Pg
isn't going to change), you can simply say:

  if($cust_data->{hold})

However, if you want cross-database portability (and protection from
DBD::Pg's behaviour changing), you have to do this:

  if($cust_data->{hold}=~/[t1]/)

--

perl -e '$|=s""\rJust another Perl hacker,";s/\w/$&\b#/g;
         s/(${\chr(97+rand$=)}).#/$1/ig&&sleep print while/#/;die$/'
    -- Ilmari Karonen, Yanick and Abigail

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl

 
 
 

1. SQL 7 Eval Copy won't install

I purchased "Inside MS SQL Server 7.0," which has an evaluation copy of
SQL Server 7.0.  I have tried without success to install it on two
different computers.  Each time I get a dialog box with the following
message: "Internal Error.  Contact MS Technical Support."  and then it
won't install.  I wonder if this is just a bad copy of the evaluation
program or does it portend some evil thing in my computers?

Anyway, there are no directions for contacting MS Technical Support.
Are there other options besides paid support calls for an evaluation
product that won't install?

Thanks for any information

Dick Marcum

2. Sql Mail doesn't start!

3. MS OLE DB Provider won't work with boolean

4. Error: Table Mutating, Trigger may not see it???

5. Q:VB3 - Access 1 - Windows 95 GPF

6. Remove an exising instance of SQL Server

7. Boolean value's from access97 with DAO

8. Early abort in boolean eval when possible?

9. ODCB won't conect when Perl script run from Web server

10. pl/perl won't build under 7.1.3

11. Aggregating Boolean Expressions - SUM(([Field] = 'value') + ([Field] = 'value'))