in reply to Re: Perl database access
in thread Perl database access

Awesome, looks good. I get it. You guys always get it right when I'm in a crunch.

How does this statement work:

my $spdtrap_stmt = <<';'; SELECT id, state, city, discription FROM speedtrap WHERE state = ? ;
Does it mean everything is really on the same line?

Replies are listed 'Best First'.
Re^3: Perl database access
by ikegami (Patriarch) on Sep 23, 2004 at 16:04 UTC

    You're welcome

    <<';' is just like the <<EOF you've used elsewhere in your program, except the single quotes mean $ and @ won't be treated as variables, and it's ends with a line containing only ';' (and no spaces). In other words, the statement in question compiles to exactly the same as:

    my $spdtrap_stmt = 'SELECT id,' . "\n" . ' state,' . "\n" . ' city,' . "\n" . ' discription' . "\n" . ' FROM speedtrap' . "\n" . ' WHERE state = ?' . "\n";

    SQL doesn't care about tabs (not used) and newlines outside of quote strings; it just treats them as another space. So the statement in question is functionally equivalent to what's below, but easier way to read:

    my $spdtrap_stmt = 'SELECT id, state, city, discription FROM speedtrap + WHERE state = ?';