I have a script running under Apache/cgi (not mod_perl). Building the sql statement two different ways gives different results, even though the statements are equal. The script:
sub _select { my ($self, $sql, $where, $values, $orderby) = @_; my @values = $values ? @$values : undef; $sql .= " where $where " if $where; $sql .= " order by $orderby " if $orderby; my $sql2 = "select * from content where name = 'practice' "; print $sql; print $sql2; print ($sql eq $sql2 ? 'equal' : 'NOT'); # print "DEBUG: $sql w/values: " . Dumper \@values; my $sth = $self->dbh->prepare($sql) or die "couldn't prepare: " . +$self->dbh->errstr(); # $sth->execute(@values) or die "couldn't execute: " . $self->dbh->e +rrstr(); $sth->execute() or die "could't execute: " . $self->dbh->errstr(); my @rows = (); while (my $row = $sth->fetchrow_hashref()) { push (@rows, $self->new($row) ); } return \@rows; }
The output is:
select * from content where name = 'practice' select * from content where name = 'practice' equal Software error: DBD::CSV::Statement=HASH(0x1c84c3c) is not a valid SQL::Statement obje +ct at E:/Perl/site/lib/DBD/File.pm line 171.
It dies on the $sth prepare if it is passed $sql. But works if passed $sql2. Is there some way the two vars are different even though they appear to be equal?

2001-03-19 Edit by Corion : Changed PRE tags to CODE tags


In reply to Variable are equal but don't behave that way by voyager

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.