[25201] in Perl-Users-Digest
Perl-Users Digest, Issue: 7447 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 25 14:05:50 2004
Date: Thu, 25 Nov 2004 11:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 25 Nov 2004 Volume: 10 Number: 7447
Today's topics:
Re: CGI.PM not setting HTTP header <nospam@thanksanyway.org>
Re: CGI.PM not setting HTTP header <nospam@thanksanyway.org>
Re: CGI.PM not setting HTTP header <flavell@ph.gla.ac.uk>
Re: CGI.PM not setting HTTP header <nospam@thanksanyway.org>
Re: Dat files help "Att James" hope@hope.com
Re: Dat files help "Att James" <spamtrap@dot-app.org>
Re: escape whitespace in qw/ / <toreau@gmail.com>
Re: escape whitespace in qw/ / <perl@my-header.org>
Re: escape whitespace in qw/ / <tadmc@augustmail.com>
FAQ 7.14: How can I pass/return a {Function, FileHandle <comdog@panix.com>
Re: Help: separate difference length of spaces between <tadmc@augustmail.com>
Re: Help: separate difference length of spaces between <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
List::Util::shuffle - where did the algorithm come from <richard@zync.co.uk>
Re: Need some problemsolving-cgi/xml <tadmc@augustmail.com>
Re: Perl Project <jwillmore@fastmail.us>
Re: Reading last N lines from large file <ccn@panix.com>
Re: script hangs waiting for key stroke (chris)
Re: Using embedded PERL with commercial applications? <dha@panix.com>
Re: Using embedded PERL with commercial applications? <tadmc@augustmail.com>
using sort directly on subroutine returning list <kisrael@mezzo.eecs.tufts.edu>
Re: using sort directly on subroutine returning list <see@sig.invalid>
Re: What is 1; <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Nov 2004 08:41:34 -0800
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <h-ydnSR72OmkljvcRVn-sQ@speakeasy.net>
Thanks to everyone who replied. It appears that Alan was on the
right track. My CGI script is implemented in two separate modules,
and each module creates a new CGI object. I was setting the header
from the second instance, which was streamed after whatever
default header was being produced by the _first_ instance.
I added my header code to the first instance, and now everything
works fine.
So. . .it appears that the web server will output an HTTP header
for each instance of a CGI object that I create? Is there any way
to create a CGI object _without_ producing an HTTP header?
I am using CGI in my first module simply to parse the URL.
I would prefer not to produce any output from the first module,
although I suppose I can live with it.
Thanks
-Mark
------------------------------
Date: Thu, 25 Nov 2004 09:47:48 -0800
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <CpKdnbPLDo0jhzvcRVn-jQ@speakeasy.net>
"Tore Aursand" <toreau@gmail.com> wrote:
>
> Is the server written in Perl?
It's an Apache server.
------------------------------
Date: Thu, 25 Nov 2004 18:17:55 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <Pine.LNX.4.61.0411251807490.23401@ppepc56.ph.gla.ac.uk>
On Thu, 25 Nov 2004, Mark wrote:
> So. . .it appears that the web server will output an HTTP header
> for each instance of a CGI object that I create? Is there any way
> to create a CGI object _without_ producing an HTTP header?
I feel sure you're looking at this from the wrong end. The idea of
the CGI.pm object is that it handles the CGI request/response
transaction. Each invocation of a CGI script will handle one
request/response transaction (that's the way that CGI scripts work in
general, it's not in any way special to CGI.pm), and, as such, needs
one CGI object which will carry the transaction through from
invocation to completion.
It's only in specialised uses of CGI.pm that one would ever use more
than one CGI object, and I see no reason to think that you're dealing
with such a specialised requirement from your description.
> I am using CGI in my first module simply to parse the URL.
> I would prefer not to produce any output from the first module,
> although I suppose I can live with it.
We haven't see any code yet; but my hunch is that what you really need
your script to do is to hand the same CGI object around to the various
parts which use it.
hope this helps
------------------------------
Date: Thu, 25 Nov 2004 10:55:41 -0800
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <jpOdnSum4YQ6tzvcRVn-rw@speakeasy.net>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote:
> On Thu, 25 Nov 2004, Mark wrote:
>
> We haven't see any code yet; but my hunch is that what you really need
> your script to do is to hand the same CGI object around to the various
> parts which use it.
Yep. I solved the problem by using only one CGI object.
No doubt I can refine it a bit more, but it works for now.
Thanks again for your help.
-Mark
------------------------------
Date: Thu, 25 Nov 2004 17:10:10 GMT
From: hope@hope.com
Subject: Re: Dat files help "Att James"
Message-Id: <874cq01dtu6tkrh9d9558qh7s39ugueplk@4ax.com>
Hi James
Thank you for getting back to me
Please see below comments
On Wed, 24 Nov 2004 14:26:58 -0800, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>In article <h2r9q0lpmkd35tc7g1qkhbtova6gcm4lbg@4ax.com>,
><hope@hope.com> wrote:
>>
>> >my @files = grep /\.dat$/, readdir $dh; # only get dat files
>> >
>> >for my $file (@files) {
>> > open my $fh, "$dir/$file" or die $!;
>> > read $fh, my $data, -s $fh;
>> > my @fields = split /\n/, $data;
>> > $csv->combine(@fields);
>> > print $out $csv->string."\n";
>> >}
>> >
>> >__END__
>>
>> If I have all the above correct then it does not work
>>
>
>
>>
>> Put at the top of the script
>> use warnings
>> use CGI:: Carp dw(fatelsToBrowser)
>
>Spelling counts. Did you cut and paste this out of your program or
>re-type it?
Yes I did re-type it I see the mistakes now it should be
>> use CGI ::Carp qw<fatelsToBrowser>;
Sorry about that
#######################
>> Which returns the errors like
>> Name "Main::dir" used only once possible typo at line 13
>> Use of uninitalized value in concatenation (.) or string at line 13
>
>These are warnings, not fatal errors, but they may be significant.
>
>
>> As always, any and all help is greatly appreciated.
>
>Please post a complete, as-short-as-possible program that demonstrates
>the problem you are having. Cut and paste the exact code; do not
>re-type it. Then someone might be able to help you.
Ok here is the complete script
Start code
use Text::CSV;
my $csv = Text::CSV->new;
open my $out, '+>/home/me/outfile' or die $!;
opendir my $dh, '/usr/local/whatever' or die $!; # open the dir
my @files = grep /\.dat$/, readdir $dh; # only get dat files
for my $file (@files) {
open my $fh, "$dir/$file" or die $!;
read $fh, my $data, -s $fh;
my @fields = split /\n/, $data;
$csv->combine(@fields);
print $out $csv->string."\n";
}
__END__
End of code
########################
>
>From the above, I might guess that $dir is undefined.
As always, any and all help is greatly appreciated.
Thank you in advance.
John
------------------------------
Date: Thu, 25 Nov 2004 13:30:58 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Dat files help "Att James"
Message-Id: <jKCdncjsGbV-uTvcRVn-gg@adelphia.com>
hope@hope.com wrote:
> Ok here is the complete script
>
> Start code
Always - yes, *always* - ask Perl for more help:
use warnings;
use strict;
> use Text::CSV;
>
> my $csv = Text::CSV->new;
>
> open my $out, '+>/home/me/outfile' or die $!;
>
> opendir my $dh, '/usr/local/whatever' or die $!; # open the dir
> my @files = grep /\.dat$/, readdir $dh; # only get dat files
>
> for my $file (@files) {
> open my $fh, "$dir/$file" or die $!;
^^^^
You're using a variable named $dir here, but you haven't declared such a
variable nor assigned it a value. ("use strict" would have told you
about this.)
> read $fh, my $data, -s $fh;
> my @fields = split /\n/, $data;
> $csv->combine(@fields);
> print $out $csv->string."\n";
> }
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Thu, 25 Nov 2004 17:07:04 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: escape whitespace in qw/ /
Message-Id: <pan.2004.11.25.16.07.03.262365@gmail.com>
On Thu, 25 Nov 2004 07:41:43 -0800, chris wrote:
> I have a whitespace separated list where some of the fields actually
> should have a extra whitespace character. Is there a way I can escape
> this space so I can use qw// to create the list:
>
> @list = qw/ 1.0 UK Y 2.5 /;
>
> where UK is actually 'UK ' (without the quotes).
>
> Is this possible?
I don't think so (after reading 'perldoc perlop'), but you can always use
your imagination;
my @list = split(',', '1.0,UK ,Y,2.5');
:-)
--
Tore Aursand <toreau@gmail.com>
"Be nice to nerds. Chances are you'll end up working for one." (Bill
Gates)
------------------------------
Date: Thu, 25 Nov 2004 18:09:29 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: escape whitespace in qw/ /
Message-Id: <ml3cq0d2ve1sk2e5tukbdq3m71p1l0lb92@4ax.com>
X-Ftn-To: chris
nadsinoz@hotmail.com (chris) wrote:
>I have a whitespace separated list where some of the fields actually
>should have a extra whitespace character. Is there a way I can escape
>this space so I can use qw// to create the list:
>
>@list = qw/ 1.0 UK Y 2.5 /;
>
>where UK is actually 'UK ' (without the quotes).
>
>Is this possible?
I think it isn't, as it seems that perl immediately convert qw// to list
E:\>perl -MO=Deparse -e "@list = qw/ 1.0 UK Y 2.5 /;"
@list = ('1.0', 'UK', 'Y', '2.5');
but you could use some other character instead space,
@list = map { tr/_/ /; $_ } qw/ 1.0 UK_ Y 2.5 /;
--
Matija
------------------------------
Date: Thu, 25 Nov 2004 11:15:38 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: escape whitespace in qw/ /
Message-Id: <slrncqc4pq.bk2.tadmc@magna.augustmail.com>
chris <nadsinoz@hotmail.com> wrote:
> I have a whitespace separated list where some of the fields actually
> should have a extra whitespace character. Is there a way I can escape
> this space
No.
qw is not the Right Tool if the data contains whitespace.
> so I can use qw// to create the list:
You can still use qw// to create the parts of the list
that do not contain whitespace.
> @list = qw/ 1.0 UK Y 2.5 /;
>
> where UK is actually 'UK ' (without the quotes).
>
> Is this possible?
@list = qw/ 1.0 /, 'UK ', qw/ Y 2.5 /;
or even:
@list = qw/ 1.0 UK Y 2.5 /;
$list[1] .= ' ';
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Nov 2004 17:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <co5385$hfs$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
With the exception of regexes, you need to pass references to these
objects. See "Pass by Reference" in perlsub for this particular
question, and perlref for information on references.
See ``Passing Regexes'', below, for information on passing regular
expressions.
Passing Variables and Functions
Regular variables and functions are quite easy to pass: just pass in
a reference to an existing or anonymous variable or function:
func( \$some_scalar );
func( \@some_array );
func( [ 1 .. 10 ] );
func( \%some_hash );
func( { this => 10, that => 20 } );
func( \&some_func );
func( sub { $_[0] ** $_[1] } );
Passing Filehandles
As of Perl 5.6, you can represent filehandles with scalar variables
which you treat as any other scalar.
open my $fh, $filename or die "Cannot open $filename! $!";
func( $fh );
sub func {
my $passed_fh = shift;
my $line = <$fh>;
}
Before Perl 5.6, you had to use the *FH or "\*FH" notations. These
are "typeglobs"--see "Typeglobs and Filehandles" in perldata and
especially "Pass by Reference" in perlsub for more information.
Passing Regexes
To pass regexes around, you'll need to be using a release of Perl
sufficiently recent as to support the "qr//" construct, pass around
strings and use an exception-trapping eval, or else be very, very
clever.
Here's an example of how to pass in a string to be regex compared
using "qr//":
sub compare($$) {
my ($val1, $regex) = @_;
my $retval = $val1 =~ /$regex/;
return $retval;
}
$match = compare("old McDonald", qr/d.*D/i);
Notice how "qr//" allows flags at the end. That pattern was compiled
at compile time, although it was executed later. The nifty "qr//"
notation wasn't introduced until the 5.005 release. Before that, you
had to approach this problem much less intuitively. For example,
here it is again if you don't have "qr//":
sub compare($$) {
my ($val1, $regex) = @_;
my $retval = eval { $val1 =~ /$regex/ };
die if $@;
return $retval;
}
$match = compare("old McDonald", q/($?i)d.*D/);
Make sure you never say something like this:
return eval "\$val =~ /$regex/"; # WRONG
or someone can sneak shell escapes into the regex due to the double
interpolation of the eval and the double-quoted string. For example:
$pattern_of_evil = 'danger ${ system("rm -rf * &") } danger';
eval "\$string =~ /$pattern_of_evil/";
Those preferring to be very, very clever might see the O'Reilly
book, *Mastering Regular Expressions*, by Jeffrey Friedl. Page 273's
Build_MatchMany_Function() is particularly interesting. A complete
citation of this book is given in perlfaq2.
Passing Methods
To pass an object method into a subroutine, you can do this:
call_a_lot(10, $some_obj, "methname")
sub call_a_lot {
my ($count, $widget, $trick) = @_;
for (my $i = 0; $i < $count; $i++) {
$widget->$trick();
}
}
Or, you can use a closure to bundle up the object, its method call,
and arguments:
my $whatnot = sub { $some_obj->obfuscate(@args) };
func($whatnot);
sub func {
my $code = shift;
&$code();
}
You could also investigate the can() method in the UNIVERSAL class
(part of the standard perl distribution).
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Thu, 25 Nov 2004 10:49:30 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help: separate difference length of spaces between words
Message-Id: <slrncqc38q.be6.tadmc@magna.augustmail.com>
KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote:
> In <VCfpd.1668$VL6.630@clgrps13> "John W. Krahn" <someone@example.com> writes:
>>Lei wrote:
>>> If I want to get $D = "first column word" $E = "second column word"
>>> and discard the last word of the row.
>>Assuming that the current row is in $_ then:
>
>>my ( $D, $E ) = split;
>
>>Which is short for:
>
>>my ( $D, $E ) = split ' ', $_;
>
> Which is short for:
>
> my ( $D, $E ) = split /\s+/, $_;
No it isn't, it behaves differently when $_ =~ /^\s/, see:
perldoc -f split
> If instead
> of only three words per line you had 1000, but still only wanted
> the first 2, then it may be more efficient to write
^^^^^^^^
^^^^^^^^
> my ( $D, $E ) = split ' ', $_, 3;
Wrong again, you don't need to write it that way to get the
efficiency.
perldoc -f split
says that Perl will do that for you *automatically* when used
like John did above.
> In contrast, the forms given
> earlier would have split the line into 1000 pieces,
No then wouldn't have.
> perldoc -f split
Errr, right!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Nov 2004 18:44:02 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Re: Help: separate difference length of spaces between words
Message-Id: <co595i$j5m$1@reader1.panix.com>
In <slrncqc38q.be6.tadmc@magna.augustmail.com> Tad McClellan <tadmc@augustmail.com> writes:
>KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote:
>> In <VCfpd.1668$VL6.630@clgrps13> "John W. Krahn" <someone@example.com> writes:
>>>Lei wrote:
>>>> If I want to get $D = "first column word" $E = "second column word"
>>>> and discard the last word of the row.
>>>Assuming that the current row is in $_ then:
>>
>>>my ( $D, $E ) = split;
>>
>>>Which is short for:
>>
>>>my ( $D, $E ) = split ' ', $_;
>>
>> Which is short for:
>>
>> my ( $D, $E ) = split /\s+/, $_;
>No it isn't, it behaves differently when $_ =~ /^\s/, see:
> perldoc -f split
>> If instead
>> of only three words per line you had 1000, but still only wanted
>> the first 2, then it may be more efficient to write
> ^^^^^^^^
> ^^^^^^^^
>> my ( $D, $E ) = split ' ', $_, 3;
>Wrong again, you don't need to write it that way to get the
>efficiency.
So, Lei, here's another important lesson: to get the real scoop in
CLPM, don't ask. Just post your best guess as fact, and someone
who really knows will go ballistic and post the correct answer.
Karl
--
Sent from a spam-bucket account; I check it once in a blue moon. If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.
------------------------------
Date: Thu, 25 Nov 2004 19:03:04 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: List::Util::shuffle - where did the algorithm come from?
Message-Id: <pan.2004.11.25.19.03.04.44915@zync.co.uk>
Hi all,
I was just looking at List::Util::shuffle (reproduced below) and wondered
where the algorithm came from. Was this invented by the module author? Is
it a known good algorithm for shuffling lists?
It wasn't immediately obvious to me that all elements of the list would be
returned, but I understand what's going on now. Visualising pigeon holes
and bits of paper helps. A bit.
So does anyone know its provenance?
Rich
sub shuffle (@) {
my @a=\(@_);
my $n;
my $i=@_;
map {
$n = int rand($i--);
(${$a[$n]}, $a[$n] = $a[$i])[0];
} @_;
}
------------------------------
Date: Thu, 25 Nov 2004 10:25:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need some problemsolving-cgi/xml
Message-Id: <slrncqc1sb.be6.tadmc@magna.augustmail.com>
lievemario <lievemario@hotmail.com> wrote:
> - it gets input from a form (a person_id)
Then you should have taint checking enabled, see:
perldoc perlsec
> Hope I get some solution.
Get it working *from the command line* first, move it to the CGI
environment after it has been debugged.
> #!/usr/bin/perl
> # use strict;
You lose all of the benefits of use strict if you comment it out.
Ask for all the help you can get:
#!/usr/bin/perl -T
use warnings;
use strict;
(and "perldoc -q CGI" ... "How can I get better error messages
from a CGI program?")
> use CGI qw(param);
> my $dbh = DBI->connect ("DBI:mysql:rd", "root", "",
^^^^^^ ^^
Please, oh please, tell that this is not your actual code!
It is bad security on many levels!
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
[snip cargo-cult param "parsing"]
Why are you doing this yourself instead of letting CGI.pm do it for you?
POST data is on STDIN, GET data is in the environment variable.
> my @details = ("data","team","pubs","other");
That sure is hard to read:
my @details = qw( data team pubs other );
> foreach $x (@details) {
Have you already declared $x somewhere?
> my $person_id = param("person_id");
Now you *are* having CGI.pm do the form parsing for you.
Why did you switch?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Nov 2004 13:32:35 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Perl Project
Message-Id: <pan.2004.11.25.18.32.35.810782@fastmail.us>
On Thu, 25 Nov 2004 00:00:13 -0800, Ratnakar Pedagani wrote:
> I'm looking for a project in perl and oracle. This project should
> focus on Internet database applications, such as technics for
> improving response time, security, user-friendliness, and other
> innovative ideas. Any help or references would be appreciated.
Homework? :-)
Try Google or Freshmeat (http://freshmeat.net/). The latter is a site
dedicated to all types of projects.
HTH
Jim
------------------------------
Date: Thu, 25 Nov 2004 16:37:07 +0000 (UTC)
From: Chris Nestrud <ccn@panix.com>
Subject: Re: Reading last N lines from large file
Message-Id: <co51nj$gp4$1@reader1.panix.com>
On Thu, 25 Nov 2004 17:01:49 +0100, Tore Aursand <toreau@gmail.com> wrote:
> On Thu, 25 Nov 2004 14:51:19 +0000, Chris Nestrud wrote:
>> I need to read a number of lines from the end of a large file. For
>> example, the file may have 460484 lines and I need the last 500.
>
> Take a look at the 'File::ReadBackwards' module;
>
> <http://search.cpan.org/~uri/File-ReadBackwards-1.02/>
This looks like exactly what I need. Thanks.
--
Chris Nestrud
Email: ccn@panix.com
http://www.panix.com/~ccn/
------------------------------
Date: 25 Nov 2004 08:42:51 -0800
From: nadsinoz@hotmail.com (chris)
Subject: Re: script hangs waiting for key stroke
Message-Id: <b8996f29.0411250842.427465f0@posting.google.com>
Agreed! Sorry! This is the latest version...
#!/usr/bin/perl -w
use strict;
use DBD::ODBC;
use util::YYYYMM;
my $start = 200402;
my $end = 200408;
my $range_list = range( $start, $end );
my @opcos = qw[ ES ];
print "This will (re)load \n\t@opcos \nfor \n\t@$range_list.\n";
print "Continue [y/N]?";
die ">> Cancelled <<" if (getc !~ /y/i);
my $dbh;
#foreach my $opco ( qw[ IE UK DE IT GR ES ] ) {
foreach my $opco (@opcos) {
foreach my $yyyymm (@$range_list) {
LOAD: {
print "Processing $opco $yyyymm\n";
$dbh = DBI->connect('dbi:ODBC:XXXXXX', 'XXXXXX', 'XXXXXX')
or redo LOAD;
my $sth = $dbh->prepare("exec udb019.m_run ( '$opco', $yyyymm );")
or redo LOAD;
$sth->execute or redo LOAD;
$dbh->disconnect;
}
}
}
my $yyyymm_plus_one = yyyymm_add( $end );
my $dbh2 = DBI->connect('dbi:ODBC:XXXXXX', 'XXXXXX', 'XXXXXX')
or redo LOAD;
my $sth2 = $dbh2->prepare("exec udb019.m_run_report ( $yyyymm_plus_one );");
$sth2->execute;
$dbh2->disconnect;
Dave Weaver <zen13097@zen.co.uk> wrote in message news:<41a1bba7$0$1078$db0fefd9@news.zen.co.uk>...
> On 19 Nov 2004 14:12:19 -0800, chris <nadsinoz@hotmail.com> wrote:
> > It runs fine!
> >
>
> Rubbish!
> Here, again, is the code you originally posted:
>
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use DBI;
> >
> > use util::YYYYMM;
> >
> > my $start = 200402;
> > my $end = 200410;
> > my $range_list = range( $start, $end );
> >
> > foreach my $opco ( qw[ IE UK DE IT GR ES ] ) {
> > foreach my $yyyymm (@$range_list) {
> > LOAD: {
> > print "Processing $opco $yyyymm\n";
> > my $dbh = DBI->connect('dbi:ODBC:XXXXX',
> > 'XXXXX', 'XXXXX')
> > or redo LOAD;
> > my $sth = $dbh->prepare("exec m_run ( '$opco',
> > $yyyymm );")
> > or redo LOAD;
> > $sth->execute or redo LOAD;
> > $dbh->disconnect;
> > }
> > }
> > }
> > my $yyyymm_plus_one = yyyymm_add( $end );
> > my $sth = $dbh->prepare("exec m_run_report ( $yyyymm_plus_one );");
>
> ^^^^
> Where is $dbh declared?
> Your code cannot possibly compile as shown, and therefore it does not,
> as you claim, "run fine".
>
>
> > $sth->execute;
------------------------------
Date: Thu, 25 Nov 2004 16:29:00 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Using embedded PERL with commercial applications?
Message-Id: <slrncqc22c.me.dha@panix2.panix.com>
On 2004-11-25, Patrick Finnegan <chppxf1@yahoo.com.au> wrote:
>> I checked out the Perl licensing issue with a contact at IBM. Perl is owned
>> by Larry Wall who deals with applications by Vendors to use embedded Perl in
>> commercial applications on a case by case basis. There is no guarantee that
>> future Perl distros will be "free" and there may be limits on the ability of
>> Vendors to write proprietary custom extensions for Perl and package those
>> extensions as part of a commercial application.
Is it me, or does this sound like fairly complete nonsense?
Just checking...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Apparently the left hand doesn't know what a right hand IS.
- zenham in #perl
------------------------------
Date: Thu, 25 Nov 2004 11:19:10 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Using embedded PERL with commercial applications?
Message-Id: <slrncqc50e.bk2.tadmc@magna.augustmail.com>
David H. Adler <dha@panix.com> wrote:
> On 2004-11-25, Patrick Finnegan <chppxf1@yahoo.com.au> wrote:
>>> I checked out the Perl licensing issue with a contact at IBM. Perl is owned
>>> by Larry Wall who deals with applications by Vendors to use embedded Perl in
>>> commercial applications on a case by case basis. There is no guarantee that
>>> future Perl distros will be "free" and there may be limits on the ability of
>>> Vendors to write proprietary custom extensions for Perl and package those
>>> extensions as part of a commercial application.
>
> Is it me, or does this sound like fairly complete nonsense?
>
> Just checking...
I just figured that Patrick had been fed a steady diet of FUD
by someone who has some alternative to sell to him.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Nov 2004 17:12:40 GMT
From: Kirk Is <kisrael@mezzo.eecs.tufts.edu>
Subject: using sort directly on subroutine returning list
Message-Id: <coopd.264$Y2.6952@news.tufts.edu>
I've been using Perl for at least 10 years and I'm kind of surprised I
haven't run into this one before, so I want to see if I'm interpreting it
correctly...
If I have a trivial funtion returning a list
sub getarray{
return ("x","z","y");
}
then
@files = getarray();
@files = sort @files;
does 'what I expect' while trying to be "clever" and inline it
@files = sort getarray();
Doesn't...because when the first argument to sort is a subroutine,
it tries to use it as the comparison function.
On the other hand, experimentally,
@files = sort &getarray();
Works...hmm, I guess the upshot is I'm a little fast and loose
with whether I call functions with & or not and this is one of the
relatively few times it comes back to bite me...any suggestions
on the preferred method to avoid this kind of problem?
--
QUOTEBLOG: http://kisrael.com SKEPTIC MORTALITY: http://kisrael.com/mortal
You Shall Not Subject Your God To Market Forces!
--Book of Om, Chap. IV v.6b ("Small Gods",Terry Pratchett)
------------------------------
Date: Thu, 25 Nov 2004 13:44:28 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: using sort directly on subroutine returning list
Message-Id: <41a62594$1_1@127.0.0.1>
Kirk Is wrote:
> I've been using Perl for at least 10 years and I'm kind of surprised I
> haven't run into this one before, so I want to see if I'm interpreting it
> correctly...
>
> If I have a trivial funtion returning a list
>
> sub getarray{
> return ("x","z","y");
> }
>
> then
>
> @files = getarray();
> @files = sort @files;
>
> does 'what I expect' while trying to be "clever" and inline it
>
> @files = sort getarray();
>
> Doesn't...because when the first argument to sort is a subroutine,
> it tries to use it as the comparison function.
>
> On the other hand, experimentally,
> @files = sort &getarray();
...
In addition, you can do:
@files = sort +getarray;
which also disambiguates the call to sort (+getarray is clearly not a
subname or a block, but an expression). I'm surprised
@files = sort &getarray;
works, as I would think &getarray is clearly a subname. Hmmmm. Perl
must think &getarray is an expression?
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 25 Nov 2004 11:20:37 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: What is 1;
Message-Id: <slrncqc535.bk2.tadmc@magna.augustmail.com>
Ian Pellew <ipellew@pipemedia.co.uk> wrote:
> What does the
> 1;
> line of a perl script do?
Not much.
(the answer would be different if you had asked about a library or
a module rather than about a "script".
)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 7447
***************************************