Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all,
I have little formatting problem, we have code:
sub test {
$sth = $dbh->prepare_cached(<<SQL);
INSERT INTO table (ip, port, type, create_date)
VALUES (?,?,?,?)
SQL
$sth->execute('12.12.12.12', 80, proxy, '2002-12-12');
$sth->finish;
return;
}
this of course doesn't work, because SQL is not at begining of the
line. I tried:
$sth = $dbh->prepare_cached(<<" SQL");
and that works. But could I use regexp for that? something like this:
$sth = $dbh->prepare_cached(<<\s*SQL);
it is just cosmetic question, but i'd like to know answer....
/brano
-=x=-
Skontrolované antivírovým programom NOD32
Post Follow-up to this messageIng. Branislav Gerzo wrote:
> Hi all,
>
> I have little formatting problem, we have code:
>
> sub test {
> $sth = $dbh->prepare_cached(<<SQL);
> INSERT INTO table (ip, port, type, create_date)
> VALUES (?,?,?,?)
> SQL
> $sth->execute('12.12.12.12', 80, proxy, '2002-12-12');
> $sth->finish;
> return;
> }
>
> this of course doesn't work, because SQL is not at begining of the
> line. I tried:
> $sth = $dbh->prepare_cached(<<" SQL");
>
> and that works. But could I use regexp for that? something like this:
>
> $sth = $dbh->prepare_cached(<<\s*SQL);
>
> it is just cosmetic question, but i'd like to know answer....
No, you can't use the regex. For more discussion see:
perldoc -q "Why don't my <<HERE documents work?"
I prefer this construct:
$sth = $dbh->prepare_cached(q[
INSERT INTO table (ip, port, type, create_date)
VALUES (?,?,?,?)
]);
Post Follow-up to this messagegerfobra@stonline.sk <gerfobra@stonline.sk> wrote:
: Hi all,
:
: I have little formatting problem, we have code:
:
: sub test {
: $sth = $dbh->prepare_cached(<<SQL);
: INSERT INTO table (ip, port, type, create_date)
: VALUES (?,?,?,?)
: SQL
: $sth->execute('12.12.12.12', 80, proxy, '2002-12-12');
: $sth->finish;
: return;
: }
Don't use a HERE doc and pass $dbh into the subroutine.
sub test {
my $dbh = shift;
my $sth = $dbh->prepare_cached(
q(
INSERT
INTO table( ip, port, type, create_date )
VALUES (?,?,?,?)
)
);
$sth->execute( '12.12.12.12', 80, 'proxy', '2002-12-12' );
$sth->finish;
return;
}
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.