Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

formatting problem
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


Report this thread to moderator Post Follow-up to this message
Old Post
Ing. Branislav Gerzo
10-31-04 01:55 AM


Re: formatting problem
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 (?,?,?,?)
]);


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Showalter
10-31-04 01:55 AM


RE: formatting problem
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


Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
10-31-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:10 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.