[28401] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9765 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 25 18:10:20 2006

Date: Mon, 25 Sep 2006 15:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 25 Sep 2006     Volume: 10 Number: 9765

Today's topics:
    Re: Spreadsheet::WriteExcel & worksheet->write courtney.machi@gmail.com
    Re: Spreadsheet::WriteExcel & worksheet->write <David.Squire@no.spam.from.here.au>
    Re: Spreadsheet::WriteExcel & worksheet->write <veatchla@yahoo.com>
    Re: Spreadsheet::WriteExcel & worksheet->write <mritty@gmail.com>
    Re: Spreadsheet::WriteExcel & worksheet->write <glex_no-spam@qwest-spam-no.invalid>
    Re: Spreadsheet::WriteExcel & worksheet->write (Gary E. Ansok)
    Re: Spreadsheet::WriteExcel & worksheet->write courtney.machi@gmail.com
    Re: Spreadsheet::WriteExcel & worksheet->write (reading news)
    Re: submatch scoping in while anno4000@radom.zrz.tu-berlin.de
    Re: Web Reporting Enhancement <tzz@lifelogs.com>
    Re: Web Reporting Enhancement <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 25 Sep 2006 11:06:45 -0700
From: courtney.machi@gmail.com
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <1159207605.070706.172770@d34g2000cwd.googlegroups.com>

AHHH! My apologies!!! I wasn't aware it'd be a problem.

OK, well the script now writes to the spreadsheet, but it will only
write one line. I am reading in data from a text file and need the
script to write one line to the spreadsheet per line in the text file
based on information in a database. Here is the code:

#open file
        $filename = shift;
        open(GR,"$filename") or die("Unable to open file");
        @sub =<GR>;
        close(GR);


#FOR EACH RECORD IN TEXT FILE...
        foreach $record (@sub)
        {
          chop($record);
          $sub = uc($record);


                $sql = "query";

                $sth= $alloc_dbh->prepare($sql_psc_rachel);
                $sth->execute();
                while (($masterNum, $subNum, $platform, $machine,
$lastAlloc, $lastAllocDate, $chargeID,
                $lastname, $balance) = $sth->fetchrow())
                {
                        print OUT ("PSC Data: $masterNum, $subNum,
$platform, $machine, $lastAlloc, $lastAllocDate,
                        $chargeID, $lastname, $balance\n");


                        #TGCDB info
                                %tgdata=getTGData();

                                $start = $tgdata{"$chargeID $platform
AllocData"};
                                $alloc = $tgdata{"$chargeID $platform
Alloc"};
                                $remaining = $tgdata{"$chargeID
$platform Remaining"};
                                print OUT ("data: $chargeID, Start
$start, Alloc $alloc, Remaining
                                $remaining\n");

                                my $row = 1;

                                        $worksheet1->write($row, 0,
$masterNum);
                                        $worksheet1->write($row, 1,
$subNum);
                                        $worksheet1->write($row, 2,
$platform);
                                        $worksheet1->write($row, 3,
$machine);
                                        $worksheet1->write($row, 4,
$lastAlloc);
                                        $worksheet1->write($row, 5,
$alloc);
                                        $worksheet1->write($row, 6,
$lastAllocDate);
                                        $worksheet1->write($row, 7,
$start);
                                        $worksheet1->write($row, 8,
$chargeID);
                                        $worksheet1->write($row, 9,
$balance);
                                        $worksheet1->write($row, 10,
$remaining);
                                        $worksheet1->write($row, 11,
$lastname);
                                        $row++;

                }

                $sth->finish();
}

Can anyone see a problem?

Thanks,
Courtney


Paul Lalli wrote:
> courtney.machi@gmail.com wrote:
>
> > I am grabbing database information using fetchrow() and storing the
> > results in variables. I need to write these results to an excel
> > spreadsheet. Does worksheet->write work when you're using variables?
>
> ARRG!!  I just responded to this in perl.beginners, not realizing you'd
> posted an identical copy of the same message to another group.  PLEASE
> DON'T DO THAT!  If you *NEED* to post to more than one group,
> crosspost, do not multi-post!!
>
> http://groups.google.com/group/perl.beginners/browse_frm/thread/2722b5f7816a8127/5a89cd83b68a7bc8#5a89cd83b68a7bc8
> 
> Paul Lalli



------------------------------

Date: Mon, 25 Sep 2006 19:30:31 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <ef9788$3t8$1@gemini.csx.cam.ac.uk>

courtney.machi@gmail.com wrote:

[Top-posting corrected. Please don't do that. Please *do* read the
posting guidelines for this group, that are posted here twice weekly.]

> Paul Lalli wrote:
>> courtney.machi@gmail.com wrote:
>>
>>> I am grabbing database information using fetchrow() and storing the
>>> results in variables. I need to write these results to an excel
>>> spreadsheet. Does worksheet->write work when you're using variables?
>> ARRG!!  I just responded to this in perl.beginners, not realizing you'd
>> posted an identical copy of the same message to another group.  PLEASE
>> DON'T DO THAT!  If you *NEED* to post to more than one group,
>> crosspost, do not multi-post!!
>>
>> http://groups.google.com/group/perl.beginners/browse_frm/thread/2722b5f7816a8127/5a89cd83b68a7bc8#5a89cd83b68a7bc8
>>
> AHHH! My apologies!!! I wasn't aware it'd be a problem.
>
> OK, well the script now writes to the spreadsheet, but it will only
> write one line. I am reading in data from a text file and need the
> script to write one line to the spreadsheet per line in the text file
> based on information in a database. Here is the code:
>

Missing:

use strict;
use warnings;

Including those at the top of every script will catch many problems
before they lead you here.

> #open file
>         $filename = shift;
>         open(GR,"$filename") or die("Unable to open file");

Would be better as:

open my $GR, '<', $filename or die "Unable to open file $filename: $!";

- you don't need to quote variables
- lexically scoped filehandles are nicer
- the three-argument form of open is safer (see perldoc -f open)
- it's nice to have an informative error message

>         @sub =<GR>;
>         close(GR);
>
>
> #FOR EACH RECORD IN TEXT FILE...
>         foreach $record (@sub) {

Why do you slurp in the whole contents of the file when you only need
one line at a time? This wastes memory. It would be better as:

while (my $record = <GR>) {

>           chop($record);

You almost certainly want 'chomp' here, not 'chop'.

>           $sub = uc($record);

This variable never gets used in the script you show. What is it for?
Please post minimal, *complete*, scripts.

>
>
>                 $sql = "query";
>
>                 $sth= $alloc_dbh->prepare($sql_psc_rachel);

Where did these mystery variables $alloc_dbh and $sql_psc_rachel come
from? There are too many unknowables for us in the script fragment you
have posted.

[snip]

Please work on reducing your script to a minimal version that produces
no errors or warnings when 'use strict;' and 'use warnings;' are in
effect, yet still exhibits the problem. This exercise might even allow
you to find the problem.


DS


------------------------------

Date: Mon, 25 Sep 2006 13:38:24 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <1159209587_29317@sp6iad.superfeed.net>

courtney.machi@gmail.com wrote:
> AHHH! My apologies!!! I wasn't aware it'd be a problem.
> 
> OK, well the script now writes to the spreadsheet, but it will only
> write one line. I am reading in data from a text file and need the
> script to write one line to the spreadsheet per line in the text file
> based on information in a database. Here is the code:
> 
[snip]
> 
> 
> #FOR EACH RECORD IN TEXT FILE...
>         foreach $record (@sub)
>         {
>           chop($record);
>           $sub = uc($record);
> 
> 
>                 $sql = "query";
> 
>                 $sth= $alloc_dbh->prepare($sql_psc_rachel);
>                 $sth->execute();
>                 while (($masterNum, $subNum, $platform, $machine,
> $lastAlloc, $lastAllocDate, $chargeID,
>                 $lastname, $balance) = $sth->fetchrow())
>                 {
>                         print OUT ("PSC Data: $masterNum, $subNum,
> $platform, $machine, $lastAlloc, $lastAllocDate,
>                         $chargeID, $lastname, $balance\n");
> 
> 
>                         #TGCDB info
>                                 %tgdata=getTGData();
> 
>                                 $start = $tgdata{"$chargeID $platform
> AllocData"};
>                                 $alloc = $tgdata{"$chargeID $platform
> Alloc"};
>                                 $remaining = $tgdata{"$chargeID
> $platform Remaining"};
>                                 print OUT ("data: $chargeID, Start
> $start, Alloc $alloc, Remaining
>                                 $remaining\n");
> 
>                                 my $row = 1;

You are reseting $row back to 1 for each fetchrow().

> 
>                                         $worksheet1->write($row, 0,
> $masterNum);
>                                         $worksheet1->write($row, 1,
> $subNum);

[snip]

> $remaining);
>                                         $worksheet1->write($row, 11,
> $lastname);
>                                         $row++;
> 
>                 }
> 
>                 $sth->finish();
> }
> 
> Can anyone see a problem?
> 
> Thanks,
> Courtney


-- 

Len

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: 25 Sep 2006 11:39:57 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <1159209597.311598.138570@h48g2000cwc.googlegroups.com>

courtney.machi@gmail.com wrote:
> AHHH! My apologies!!! I wasn't aware it'd be a problem.

Another problem is that you're top-posting.  Please stop that.  Trim
your quoted material down to the smallest relevant bits, and
intersperce your comments as appropriate.

> OK, well the script now writes to the spreadsheet, but it will only
> write one line. I am reading in data from a text file and need the
> script to write one line to the spreadsheet per line in the text file
> based on information in a database. Here is the code:
>
> #open file
>         $filename = shift;

Are you using strict and warnings?  If not, please start.  They catch
99% of the errors programmers make.

>         open(GR,"$filename") or die("Unable to open file");

1) Do not double-quote variables without reason.  See also: perldoc -q
quoting
2) Use lexical filehandles, not global barewords (they are subject to
strict, they're not global, and they auto-close when they go out of
scope)
3) Use the three-argument form of open
4) State the *reason* the open failed if it does:

open my $GR, '<', $filename or die "Cannot open file: $!";

>         @sub =<GR>;
>         close(GR);
>
> #FOR EACH RECORD IN TEXT FILE...
>         foreach $record (@sub)

There is absolutely no reason to read in the entire file into memory
and keep it there for the duration of this loop.  Instead, read one
line at a time.  At each iteration, discard the previously read line
and read the next:

while (my $record = <$GR>) {

>         {
>           chop($record);

chop() is almost entirely a holdover from Perl 4.  The new standard
idiom is chomp().  (What would happen if your text file happened to not
end with a newline?)

chomp $record;

>           $sub = uc($record);
>                 $sql = "query";
>                 $sth= $alloc_dbh->prepare($sql_psc_rachel);

Where did any of these variables come from?

>                 $sth->execute();
>                 while (($masterNum, $subNum, $platform, $machine,
> $lastAlloc, $lastAllocDate, $chargeID,
>                 $lastname, $balance) = $sth->fetchrow())
>                 {
>                         print OUT ("PSC Data: $masterNum, $subNum,
> $platform, $machine, $lastAlloc, $lastAllocDate,
>                         $chargeID, $lastname, $balance\n");

When did the OUT filehandle get declared?

>                         #TGCDB info
>                                 %tgdata=getTGData();
>
>                                 $start = $tgdata{"$chargeID $platform
> AllocData"};
>                                 $alloc = $tgdata{"$chargeID $platform
> Alloc"};
>                                 $remaining = $tgdata{"$chargeID
> $platform Remaining"};
>                                 print OUT ("data: $chargeID, Start
> $start, Alloc $alloc, Remaining
>                                 $remaining\n");
>
>                                 my $row = 1;

Here you declare a brand new variable, within this loop.  It does not
exist before this line, nor after this iteration of the loop ends.
>
>                                         $worksheet1->write($row, 0,
> $masterNum);

Here (and for 10 more nearly identical lines), you use the $row
variable that you just declared.

>                                         $row++;

Here you increment this variable...

>                 }

 ... but here, that variable goes out of scope.  The next time through
the loop, a new $row is declared and initialized to 1.  No piece of
code ever uses $row when it is any value other than 1.

Move your declaration of $row outside the loop.

Paul Lalli



------------------------------

Date: Mon, 25 Sep 2006 13:53:44 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <4518250c$0$10303$815e3792@news.qwest.net>

courtney.machi@gmail.com wrote:
> AHHH! My apologies!!! I wasn't aware it'd be a problem.

What would be a problem??

> 
> OK, well the script now writes to the spreadsheet, but it will only
> write one line. I am reading in data from a text file and need the
> script to write one line to the spreadsheet per line in the text file
> based on information in a database. Here is the code:

use strict;
use warnings;

> 
> #open file
>         $filename = shift;
>         open(GR,"$filename") or die("Unable to open file");
>         @sub =<GR>;
>         close(GR);
> 
> 
> #FOR EACH RECORD IN TEXT FILE...
>         foreach $record (@sub)
>         {
>           chop($record);
>           $sub = uc($record);
> 
> 
>                 $sql = "query";
> 
>                 $sth= $alloc_dbh->prepare($sql_psc_rachel);

No idea what "$sql_psc_rachel" contains, however this could probably be 
outside of the for loop.

>                 $sth->execute();
>                 while (($masterNum, $subNum, $platform, $machine,
> $lastAlloc, $lastAllocDate, $chargeID,
>                 $lastname, $balance) = $sth->fetchrow())
>                 {

>                                 my $row = 1;

$row will always be 1.

>                 }
> 
>                 $sth->finish();
> }
> 
> Can anyone see a problem?


------------------------------

Date: Mon, 25 Sep 2006 19:18:44 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <ef9a2k$eef$1@naig.caltech.edu>

In article <1159207605.070706.172770@d34g2000cwd.googlegroups.com>,
 <courtney.machi@gmail.com> wrote:
>OK, well the script now writes to the spreadsheet, but it will only
>write one line. I am reading in data from a text file and need the
>script to write one line to the spreadsheet per line in the text file
>based on information in a database. Here is the code:

[ much snippage below ]

>                while (($masterNum, $subNum, $platform, $machine,
>$lastAlloc, $lastAllocDate, $chargeID,
>                $lastname, $balance) = $sth->fetchrow())
>                {
>                                my $row = 1;
>
>                                        $worksheet1->write($row, 0,
>$masterNum);
>                                        $row++;
>                }
>
>Can anyone see a problem?

You're resetting $row to 1 on every trip through the while() loop.

The "my $row = 1" needs to be moved outside of all the loops
that write to the same sheet.

Gary Ansok
-- 
The recipe says "toss lightly," but I suppose that depends 
on how much you eat and how bad the cramps get.      - J. Lileks 


------------------------------

Date: 25 Sep 2006 12:20:58 -0700
From: courtney.machi@gmail.com
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <1159212058.099273.71660@m73g2000cwd.googlegroups.com>

As you can probably gather...this is a temporary gig for me.

Thanks for your responses.

Paul Lalli wrote:
> courtney.machi@gmail.com wrote:
> > AHHH! My apologies!!! I wasn't aware it'd be a problem.
>
> Another problem is that you're top-posting.  Please stop that.  Trim
> your quoted material down to the smallest relevant bits, and
> intersperce your comments as appropriate.
>
> > OK, well the script now writes to the spreadsheet, but it will only
> > write one line. I am reading in data from a text file and need the
> > script to write one line to the spreadsheet per line in the text file
> > based on information in a database. Here is the code:
> >
> > #open file
> >         $filename = shift;
>
> Are you using strict and warnings?  If not, please start.  They catch
> 99% of the errors programmers make.
>
> >         open(GR,"$filename") or die("Unable to open file");
>
> 1) Do not double-quote variables without reason.  See also: perldoc -q
> quoting
> 2) Use lexical filehandles, not global barewords (they are subject to
> strict, they're not global, and they auto-close when they go out of
> scope)
> 3) Use the three-argument form of open
> 4) State the *reason* the open failed if it does:
>
> open my $GR, '<', $filename or die "Cannot open file: $!";
>
> >         @sub =<GR>;
> >         close(GR);
> >
> > #FOR EACH RECORD IN TEXT FILE...
> >         foreach $record (@sub)
>
> There is absolutely no reason to read in the entire file into memory
> and keep it there for the duration of this loop.  Instead, read one
> line at a time.  At each iteration, discard the previously read line
> and read the next:
>
> while (my $record = <$GR>) {
>
> >         {
> >           chop($record);
>
> chop() is almost entirely a holdover from Perl 4.  The new standard
> idiom is chomp().  (What would happen if your text file happened to not
> end with a newline?)
>
> chomp $record;
>
> >           $sub = uc($record);
> >                 $sql = "query";
> >                 $sth= $alloc_dbh->prepare($sql_psc_rachel);
>
> Where did any of these variables come from?
>
> >                 $sth->execute();
> >                 while (($masterNum, $subNum, $platform, $machine,
> > $lastAlloc, $lastAllocDate, $chargeID,
> >                 $lastname, $balance) = $sth->fetchrow())
> >                 {
> >                         print OUT ("PSC Data: $masterNum, $subNum,
> > $platform, $machine, $lastAlloc, $lastAllocDate,
> >                         $chargeID, $lastname, $balance\n");
>
> When did the OUT filehandle get declared?
>
> >                         #TGCDB info
> >                                 %tgdata=getTGData();
> >
> >                                 $start = $tgdata{"$chargeID $platform
> > AllocData"};
> >                                 $alloc = $tgdata{"$chargeID $platform
> > Alloc"};
> >                                 $remaining = $tgdata{"$chargeID
> > $platform Remaining"};
> >                                 print OUT ("data: $chargeID, Start
> > $start, Alloc $alloc, Remaining
> >                                 $remaining\n");
> >
> >                                 my $row = 1;
>
> Here you declare a brand new variable, within this loop.  It does not
> exist before this line, nor after this iteration of the loop ends.
> >
> >                                         $worksheet1->write($row, 0,
> > $masterNum);
>
> Here (and for 10 more nearly identical lines), you use the $row
> variable that you just declared.
>
> >                                         $row++;
>
> Here you increment this variable...
>
> >                 }
>
> ... but here, that variable goes out of scope.  The next time through
> the loop, a new $row is declared and initialized to 1.  No piece of
> code ever uses $row when it is any value other than 1.
> 
> Move your declaration of $row outside the loop.
> 
> Paul Lalli



------------------------------

Date: Mon, 25 Sep 2006 21:12:21 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <VCXRg.12565$v%4.9063@newsread1.news.pas.earthlink.net>

On 09/25/2006 01:06 PM, courtney.machi@gmail.com wrote:
> [...]
> #FOR EACH RECORD IN TEXT FILE...
>         foreach $record (@sub)
>         {
>           chop($record);
>           $sub = uc($record);
> 
> 
>                 $sql = "query";
> 
>                 $sth= $alloc_dbh->prepare($sql_psc_rachel);
>                 $sth->execute();
>                 while (($masterNum, $subNum, $platform, $machine,
> $lastAlloc, $lastAllocDate, $chargeID,
>                 $lastname, $balance) = $sth->fetchrow())
>                 {
>                         print OUT ("PSC Data: $masterNum, $subNum,
> $platform, $machine, $lastAlloc, $lastAllocDate,
>                         $chargeID, $lastname, $balance\n");
> 
> 
>                         #TGCDB info
>                                 %tgdata=getTGData();
> 
>                                 $start = $tgdata{"$chargeID $platform
> AllocData"};
>                                 $alloc = $tgdata{"$chargeID $platform
> Alloc"};
>                                 $remaining = $tgdata{"$chargeID
> $platform Remaining"};
>                                 print OUT ("data: $chargeID, Start
> $start, Alloc $alloc, Remaining
>                                 $remaining\n");
> 
>                                 my $row = 1;
> 

I know nothing about Spreadsheet::WriteExcel, but it seems that you set 
the row to "1" on each iteration of the loop. How can it write to any 
row other than "1"?


>                                         $worksheet1->write($row, 0,
> $masterNum);
>                                         $worksheet1->write($row, 1,
> $subNum);
>                                         $worksheet1->write($row, 2,
> $platform); [...]

HTH

-- 
paduille.4058.mumia.w@earthlink.net


------------------------------

Date: 25 Sep 2006 19:22:00 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: submatch scoping in while
Message-Id: <4nqoioFbcqjkU1@news.dfncis.de>

Julian Bradfield  <jcb@inf.ed.ac.uk> wrote in comp.lang.perl.misc:
> Consider the following:
> 
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
> 
> The loop terminates at $i == 1 when 'bbb' matches ^(.)b
> The enclosing block for the match construct is the whole file.
> Therefore $1 should be 'b'.
> 
> But it isn't (in Perl 5.8.5).
> 
> What am I missing?
> 
> Compare
> 
> @x = ( 'aaa','bbb'); 
> if ( $x[$i] !~ /^(.)a/ && $i <= $#x ) { $i++; } 
> print "\$1 is *$1*, i is $i\n"; 
> 
> which behaves as expected.

My advice is to avoid the match variables whenever possible.  It is safer
and saner to match in list context and catch the results in normal Perl
variables with no surprises, and meaningful names to boot.

To do so, first rewrite the loop control to use =~ instead of !~

    while ( ! ( $x[$i] =~ /^(.)b/) && $i <= $#x ) { $i++ }

That doesn't change the behavior.  Now catch the match:

    while ( ! ( ( $capt) = $x[$i] =~ /^(.)b/) && $i <= $#x ) { $i++ }
    print "\$capt is *$capt*, i is $i\n";

That gives you the expected capture of "b" without fuss.

BTW, your loop control is slightly off.  If no match occurs, you'll
increase the index beyond the array and try that element.

Check the index first.

    while ( $i <= $#x && ! ( ( $capt) = $x[$i] =~ /^(.)b/)) { $i++ }

Now the access is protected by the condition.  That's the beauty of
short-circuiting booleans.

Anno


------------------------------

Date: Mon, 25 Sep 2006 15:24:05 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Web Reporting Enhancement
Message-Id: <g69ejtzagx6.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 23 Sep 2006, pmcgover@gmail.com wrote:

> Thanks Radal,
>> Egad!  This guy has NO CLUE about security:
>>
>> my $query = param( 'query' );
>> my $title = param( 'title' );
>
> Did you read the tainting code at the bottom of the article? ....
> $query =~ /^([-\w]+\.sql)$/;
> $query = $1;
>
> $title =~ /^([\w:.?! ]+)$/;
> $title = $1;

1) It's a bad idea to post bad code in an article, then correct it
   later in the article.  People copy&paste all the time without
   reading thoroughly.

2) Instead of using the proper --tee and --execute options, the author
   uses backticks and shell redirection.  Sure, it's easier the
   author's way, but system() is much safer with a list of arguments.

Ted


------------------------------

Date: Mon, 25 Sep 2006 15:28:18 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Web Reporting Enhancement
Message-Id: <g69ac4nagq5.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 23 Sep 2006, pmcgover@gmail.com wrote:

> This model could be much more powerful if you could pass an SQL
> query parameter from the user to the sql script.  I attempted this
> by substituting the string "p_1" in the where clause of the sql code
> but I could not substitute this string with the value in the cgi
> code (ie.  $query =~ s/p_1/value_variable/;).
>
> Any ideas how this could be made to work?  Would it be a security
> issue, or is it still possible to "taint" the user input value?
> Thanks!

It's very difficult to untaint SQL parameters if you are going to
interpolate them directly into the SQL statement and run it as text.
Try using parameters to a DBI statement instead.  That will also show
you why the author's method of running `mysql' directly is inefficient
and very limited.

Ted


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9765
***************************************


home help back first fref pref prev next nref lref last post