Home > Archive > PERL Beginners > October 2004 > formatting problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
formatting problem
|
|
| Ing. Branislav Gerzo 2004-10-30, 8:55 pm |
| 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
| |
| Bob Showalter 2004-10-30, 8:55 pm |
| Ing. 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 (?,?,?,?)
]);
| |
| Charles K. Clarkson 2004-10-30, 8:55 pm |
| gerfobra@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
|
|
|
|
|