[25187] in Perl-Users-Digest
Perl-Users Digest, Issue: 7436 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 22 06:05:52 2004
Date: Mon, 22 Nov 2004 03:05:05 -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 Mon, 22 Nov 2004 Volume: 10 Number: 7436
Today's topics:
a length of variable question (justme)
Re: a length of variable question <tony_curtis32@yahoo.com>
Re: a length of variable question <spamtrap@dot-app.org>
Re: a length of variable question <1usa@llenroc.ude.invalid>
Re: a length of variable question <noreply@gunnar.cc>
Re: a length of variable question <jurgenex@hotmail.com>
Re: Command-line HTML Post-method (medline in lynx) vjp2.at@at.BioStrategist.dot.dot.com
Re: Command-line HTML Post-method (medline in lynx) <postmaster@castleamber.com>
Re: Command-line HTML Post-method (medline in lynx) <rf@.invalid>
Re: Command-line HTML Post-method (medline in lynx) <zzzzzz@xxx.yyy>
Re: cookies vs. hidden fields <toreau@gmail.com>
Re: cookies vs. hidden fields <postmaster@castleamber.com>
FAQ 7.9: How do I create a module? <comdog@panix.com>
FAQ 8.31: Can I use perl to run a telnet or ftp session <comdog@panix.com>
Re: finding the number of keys in hash <gbh04@tiscali.co.uk>
Re: Ignore spaces in string match <toreau@gmail.com>
Perl on the Pocket PC - Easy! ioneabu@yahoo.com
Re: PLEASE HELP! Perl script does not work! <toreau@gmail.com>
Re: script hangs waiting for key stroke <zen13097@zen.co.uk>
Search.cgi followup <bnbliss@comcast.net>
Re: using regexes as command line parameters <waggis_at_hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Nov 2004 18:59:30 -0800
From: eight02645999@yahoo.com (justme)
Subject: a length of variable question
Message-Id: <c0837966.0411211859.3a355250@posting.google.com>
hi
in my script i will process from a database and assign a value to a
variable $var1
The value assigned to $var1 is a number. eg 1, 2 or 3. But it is in
"string" format. There will be spaces in front as well as behind it.
eg
$var1 = xxxxxxx2xxx
or
$var1 = xxx3xxxxxxxxxxx
where x = spaces.
I want to remove these spaces and just get the number. so i tried to
use
$var1 =~ s/(.*)(\d)(.*)/\2/ ;
Then when i print the length of $var1, it says length is 2. Is there
anything wrong with my regexp?
thanks for help
------------------------------
Date: Sun, 21 Nov 2004 21:05:20 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: a length of variable question
Message-Id: <87llcuvb0v.fsf@limey.hpcc.uh.edu>
>> On 21 Nov 2004 18:59:30 -0800,
>> eight02645999@yahoo.com (justme) said:
> hi in my script i will process from a database and assign a
> value to a variable $var1 The value assigned to $var1 is a
> number. eg 1, 2 or 3. But it is in "string" format. There
> will be spaces in front as well as behind it.
would just casting it into an int work?
$m = ' 4 ';
$n = int $m;
print "$n\n";
4
------------------------------
Date: Sun, 21 Nov 2004 22:15:21 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: a length of variable question
Message-Id: <Lq-dnbZw3bJXxDzcRVn-1w@adelphia.com>
justme wrote:
> I want to remove these spaces and just get the number. so i tried to
> use
>
> $var1 =~ s/(.*)(\d)(.*)/\2/ ;
You should be using "use warnings;".
> Is there anything wrong with my regexp?
In addition to the fact that it generates a warning, it's more complex
than it needs to be. You're not using the whitespace, so why create
subexpressions to capture it? Why bother with subexpressions at all?
Just use the /g modifier to replace all whitespace characters with an
empty string:
$var1 =~ s/\s//g;
Or, if you want to replace *only* spaces, leaving tabs, newlines, and
other forms of whitespace intact:
$var1 =~ s/ //g;
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 22 Nov 2004 03:29:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: a length of variable question
Message-Id: <Xns95A8E4DD21E8Dasu1cornelledu@132.236.56.8>
eight02645999@yahoo.com (justme) wrote in
news:c0837966.0411211859.3a355250@posting.google.com:
> in my script i will process from a database and assign a value to a
> variable $var1
> The value assigned to $var1 is a number. eg 1, 2 or 3. But it is in
> "string" format. There will be spaces in front as well as behind it.
>
> eg
>
> $var1 = xxxxxxx2xxx
> or
> $var1 = xxx3xxxxxxxxxxx
>
> where x = spaces.
>
> I want to remove these spaces and just get the number. so i tried to
> use
>
> $var1 =~ s/(.*)(\d)(.*)/\2/ ;
Please read the posting guidelines posted here frequently.
You seem not to be using strict or warnings.
C:\Home> cat t6.pl
use strict;
use warnings;
my $m = ' 4 ';
$m =~ s/(.*)(\d)(.*)/\2/ ;
print $m, "\n", length $m, "\n";
C:\Home> t6
\2 better written as $2 at C:\Home\asu1\t6.pl line 5.
4
1
> Then when i print the length of $var1, it says length is 2. Is there
> anything wrong with my regexp?
If you are not going to use the leading and trailing whitespace, there is
no need to capture it.
C:\Home> cat t6.pl
use strict;
use warnings;
my $m = ' 4 ';
$m =~ s/\s*(\d)\s*/$1/ ;
print $m, "\n", length $m, "\n";
C:\Home> t6
4
1
But then, if all you want is to remove space characters, there is no need
to use s/// anyway:
C:\Home> cat t6.pl
use strict;
use warnings;
my $m = ' 4 ';
$m =~ tr/ //d;
print $m, "\n", length $m, "\n";
C:\Home> t6
4
1
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Mon, 22 Nov 2004 04:31:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: a length of variable question
Message-Id: <30d4ruF2vlhkoU1@uni-berlin.de>
justme wrote:
> in my script i will process from a database and assign a value to a
> variable $var1
> The value assigned to $var1 is a number. eg 1, 2 or 3. But it is in
> "string" format. There will be spaces in front as well as behind it.
>
> eg
>
> $var1 = xxxxxxx2xxx
> or
> $var1 = xxx3xxxxxxxxxxx
>
> where x = spaces.
>
> I want to remove these spaces and just get the number. so i tried to
> use
>
> $var1 =~ s/(.*)(\d)(.*)/\2/ ;
>
> Then when i print the length of $var1, it says length is 2. Is there
> anything wrong with my regexp?
1) The capturing parenteses around '.*' are redundant.
2) If the length of $var1 is 2 after that operation, the string contains
anything else but a digit, probably a newline. Is that what you want?
3) The regex does not cover the possibility that the number consists of
more than one digit. Is that intentional?
4) If you enable warnings (why didn't you do so before posting?), Perl
will tell you about another thing that isn't good.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 22 Nov 2004 06:00:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: a length of variable question
Message-Id: <5gfod.4681$0k1.870@trnddc08>
justme wrote:
> The value assigned to $var1 is a number. eg 1, 2 or 3. But it is in
> "string" format. There will be spaces in front as well as behind it.
>
> eg
>
> $var1 = xxxxxxx2xxx
> or
> $var1 = xxx3xxxxxxxxxxx
>
> where x = spaces.
>
> I want to remove these spaces and just get the number. so i tried to
> use
>
> $var1 =~ s/(.*)(\d)(.*)/\2/ ;
Way, way to complicated.
As I wrote just yesterday in a different thread to cast a string to a
numerical value you simply add 0.
my $var1 = ' 3 ';
print $var1 + 0;
This will work as long as there are just blanks before the number.
jue
------------------------------
Date: Mon, 22 Nov 2004 04:43:32 +0000 (UTC)
From: vjp2.at@at.BioStrategist.dot.dot.com
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <cnrqpk$gbp$1@reader1.panix.com>
I found the groups I posted to by searching groups.google.com for html
and "post method". The replies obtained were positively unAmerican.
- = -
Vasos-Peter John Panagiotopoulos II, Columbia'81+, Bio$trategist
BachMozart ReaganQuayle EvrytanoKastorian
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Health Reform means abolishing FDR's insurance tax exemption]
[To stop SPAM, Charge net-postage] [Abolish 16th (Inc Tx) Amendment]
------------------------------
Date: 22 Nov 2004 06:41:07 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <Xns95A96F6FDAD3castleamber@130.133.1.4>
wrote:
> The replies obtained were positively unAmerican.
Is that a good thing or a bad thing?
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 22 Nov 2004 07:22:19 GMT
From: "rf" <rf@.invalid>
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <Lsgod.44607$K7.38320@news-server.bigpond.net.au>
vjp2.at@at.BioStrategist.dot.dot.com
> I found the groups I posted to by searching groups.google.com for html
> and "post method". The replies obtained were positively unAmerican.
Possible because the vast majority or people in the world are not American.
--
Cheers
Richard.
------------------------------
Date: Mon, 22 Nov 2004 08:54:28 GMT
From: Alan Connor <zzzzzz@xxx.yyy>
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <8Phod.1159$NU3.14@newsread1.news.pas.earthlink.net>
On Mon, 22 Nov 2004 07:22:19 GMT, rf <rf@.> wrote:
> vjp2.at@at.BioStrategist.dot.dot.com
>
>> I found the groups I posted to by searching groups.google.com
>> for html and "post method". The replies obtained were
>> positively unAmerican.
>
> Possible because the vast majority or people in the world are
> not American.
>
> -- Cheers Richard.
>
>
good one
AC
------------------------------
Date: Mon, 22 Nov 2004 08:04:43 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: cookies vs. hidden fields
Message-Id: <pan.2004.11.22.07.04.42.760907@gmail.com>
On Fri, 19 Nov 2004 17:20:48 -0500, Sherm Pendley wrote:
>> is there one reason over another whether i shoudl use "cookies" or
>> "hidden fields" to pass info from one form to another?
> This is really more of a CGI question than a Perl question, in that the
> answer would be the same if you were using PHP, JSP, ASP, or whatever.
>
> Having said that, all other things being equal, I'd use hidden fields.
> Cookie support is optional, a cookie file can be deleted by a user, etc.
> They're just not as reliable.
One other thing: There's no harm in practising some "security by
obscurity" in this case. :) Use a hidden file which points to a temporary
file where the _real_ values are stored, ie.:
<input type="hidden" name="tmp" value="blahfoobar.tmp">
Never (!) use a path in that name, of course.
--
Tore Aursand <toreau@gmail.com>
"The pure and simple truth is rarely pure and never simple." (Oscar
Wilde)
------------------------------
Date: 22 Nov 2004 07:21:59 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: cookies vs. hidden fields
Message-Id: <Xns95A9DE60726Acastleamber@130.133.1.4>
Tore Aursand wrote:
> On Fri, 19 Nov 2004 17:20:48 -0500, Sherm Pendley wrote:
>>> is there one reason over another whether i shoudl use "cookies" or
>>> "hidden fields" to pass info from one form to another?
>
>> This is really more of a CGI question than a Perl question, in that
>> the answer would be the same if you were using PHP, JSP, ASP, or
>> whatever.
>>
>> Having said that, all other things being equal, I'd use hidden
>> fields. Cookie support is optional, a cookie file can be deleted by a
>> user, etc. They're just not as reliable.
>
> One other thing: There's no harm in practising some "security by
> obscurity" in this case. :) Use a hidden file which points to a
> temporary file where the _real_ values are stored, ie.:
>
> <input type="hidden" name="tmp" value="blahfoobar.tmp">
>
> Never (!) use a path in that name, of course.
And you get all problems most CGI scripts can't get right, like file
locking and temp file creation..
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 22 Nov 2004 05:03:06 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.9: How do I create a module?
Message-Id: <cnrrua$gls$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.9: How do I create a module?
A module is a package that lives in a file of the same name. For
example, the Hello::There module would live in Hello/There.pm. For
details, read perlmod. You'll also find Exporter helpful. If you're
writing a C or mixed-language module with both C and Perl, then you
should study perlxstut.
The "h2xs" program will create stubs for all the important stuff for
you:
% h2xs -XA -n My::Module
The "-X" switch tells "h2xs" that you are not using "XS" extension code.
The "-A" switch tells "h2xs" that you are not using the AutoLoader, and
the "-n" switch specifies the name of the module. See h2xs for more
details.
--------------------------------------------------------------------
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: Mon, 22 Nov 2004 11:03:04 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.31: Can I use perl to run a telnet or ftp session?
Message-Id: <cnsh18$lnm$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.
--------------------------------------------------------------------
8.31: Can I use perl to run a telnet or ftp session?
Try the Net::FTP, TCP::Client, and Net::Telnet modules (available from
CPAN). http://www.cpan.org/scripts/netstuff/telnet.emul.shar will also
help for emulating the telnet protocol, but Net::Telnet is quite
probably easier to use..
If all you want to do is pretend to be telnet but don't need the initial
telnet handshaking, then the standard dual-process approach will
suffice:
use IO::Socket; # new in 5.004
$handle = IO::Socket::INET->new('www.perl.com:80')
|| die "can't connect to port 80 on www.perl.com: $!";
$handle->autoflush(1);
if (fork()) { # XXX: undef means failure
select($handle);
print while <STDIN>; # everything from stdin to socket
} else {
print while <$handle>; # everything from socket to stdout
}
close $handle;
exit;
--------------------------------------------------------------------
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: Mon, 22 Nov 2004 10:57:17 -0000
From: gbh <gbh04@tiscali.co.uk>
Subject: Re: finding the number of keys in hash
Message-Id: <MPG.1c0bd66a3f12594f989683@news.tiscali.co.uk>
In article <cnlgqh$l4h$1@grapevine.wam.umd.edu>, ustun@wam.umd.edu
says...
> I would like to compute the number of
> keys in a hash, as in below, but without
> using a temporary variable.
>
> #this works
> use strict;
> @foo = keys %$A;
> $number = $#{@foo};
>
> ($A is a reference to a hash). So why does
>
> $number = $#{keys %$A};
> or
> $number = $#{@{keys %$A}};
>
> not work? I get the error
>
> "Can't use string ("357") as an ARRAY ref while "strict refs" in use"
>
> Many thanks,
>
> Cev.
>
Whats wrong with "$n = scalar(keys %hash);" ?
Just add package names with strict.
--
gbh
gbh04 is a spamtrap
all post is deleted
------------------------------
Date: Mon, 22 Nov 2004 08:13:02 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: Ignore spaces in string match
Message-Id: <pan.2004.11.22.07.13.01.572439@gmail.com>
On Sat, 20 Nov 2004 14:50:39 +0000, Thelma Lubkin wrote:
> I am trying to compare two strings that must match except for their
> spacing.
>
> If I write:
>
> $h1 = 'here i am';
> $h2 = 'herei am';
>
> can I do a less clumsy comparison than
>
> ($hh2 = $h2) =~ s/\s//x;
> if($hh2 =~ /^$h1$/x) ...
Remove the spaces in both strings, then do the match;
sub compare_strings {
my $s1 = shift;
my $s2 = shift;
$s1 =~ tr/ //d;
$s2 =~ tr/ //d;
return ( $s1 eq $s2 );
}
--
Tore Aursand <toreau@gmail.com>
"I call upon all nations to do everything they can to stop these
terrorist killers. Thank you. Now watch this drive." (George W. Bush,
while playing golf)
------------------------------
Date: 21 Nov 2004 22:00:39 -0800
From: ioneabu@yahoo.com
Subject: Perl on the Pocket PC - Easy!
Message-Id: <1101103239.151520.159670@z14g2000cwz.googlegroups.com>
I was complaining before about how difficult it was going to be to get
Perl working on my Pocket PC pda (a Dell Axim 3). The fact that it
does not come with the Perl libraries and that there are registry
changes to make turned me off to trying it. The word 'registry' makes
me cringe. I don't know why I have this aversion to the Windows
registry, but I just do. I guess if you want to keep a secret from me,
hide it in the registry.
Anyway, I was determined to make it work no matter how difficult or
time consuming. I went to
http://www.rainer-keuchel.de/wince/perlce.html for files and
instructions.
It turned out to be very straight forward and easy. As far as the
registry stuff, he lays it out in a sample batch file which makes it
also very easy. I installed ActivePerl on my Windows computer to get
the libraries and I threw in a few more from CPAN. It is really,
really cool to have Perl running on my pda.
Here's my first script, written and executed entirely on the pda. It
is to fix a bunch of files with Weight Watcher's daily points and add
the total at the bottom of each file:
#!/usr/bin/perl
use File::Slurp;
@a = read_dir('\\oldpts\\');
foreach(@a)
{
@b = ();
@b = read_file("\\oldpts\\$_");
if (not (grep /^total/, @b))
{
$c = 0;
map
{
/^(\d+)\s/;
$c += int $&;
} @b;
push @b, "total: $c";
write_file("\\oldpts\\$_",@b);
}
}
I know it is not entirely efficient, but it worked. I couldn't believe
how fast it ran. One second to compile and no time to process dozens
of files. Now I just need the portable keyboard :-)
wana (now using map and grep a little :-)
------------------------------
Date: Mon, 22 Nov 2004 08:18:27 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: PLEASE HELP! Perl script does not work!
Message-Id: <pan.2004.11.22.07.18.26.605156@gmail.com>
On Sat, 20 Nov 2004 09:24:57 -0800, Gandu wrote:
> #!/usr/bin/perl
>
> $directory_name = '.mozilla/gandu/uar30qwk.slt/Cache';
>
> print "Opening directory ...: $directory_name\n";
>
> opendir(the_dir, $directory_name) || die("Directory could not be
> opened");
>
> @filelist = readdir(the_dir);
>
> foreach $f (@filelist){
> unless(($f eq ".") || ($f eq "..")){
> printf("Removing ... $f\n");
> unlink($f);
> }
> }
>
> closedir(the_dir);
Use the 'File::Find::Rule' module from CPAN, and check the return value of
the 'unlink' function;
#!/usr/bin/perl
#
use strict;
use warnings;
use File::Find::Rule;
my $dir = '.mozilla/gandu/uar30qwk.slt/Cache';
my @files = File::Find::Rule->file()->in( $dir );
foreach ( @files ) {
unlink or warn "Couldn't delete '$_'; $!\n";
}
--
Tore Aursand <toreau@gmail.com>
"USA Today has come out with a new survey - apparently, three out of
every four people make up 75% of the population." (David Letterman)
------------------------------
Date: 22 Nov 2004 10:12:55 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: script hangs waiting for key stroke
Message-Id: <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: Sun, 21 Nov 2004 21:02:31 -0800
From: Ken Saunders <bnbliss@comcast.net>
Subject: Search.cgi followup
Message-Id: <ags2q0hqtl9rd3bnhtjiasoadmaq3sqerc@4ax.com>
first Thaks to all those folks that gave me pointers on the perl
script assignment I was doing. I managed to cobble it together. Now
that I've gotten it together I'm facing another challenge. the script
is working but won't return any search results. Here is the code can
someone tell me why I get no results page? I'm new at this and
already I've learned that Perl is really fun and amazingly frustrating
at the same time. Thanks
bnbliss
#!/usr/bin/perl
#this perl script performs a keyword search and displays the results
use strict;
use CGI qw(:standard);
use File::Find;
# Root directory of my website
my $filePath = '/home/classes/ksaund01/public_html';
print header;
print start_html(-bgcolor=>'lightblue');
if( param('criteria') ) {
find(\&search_file, $filePath);
}
else {
display_menu();
}
print end_html;
# Subroutines
sub search_file {
my $query = param('query');
if( $_ !~ /html|txt$/o ) {
return();
}
open(IN, "$_") or warn "Can't open $_: $!\n";
while ( my $line = <IN> ) {
chomp($line);
# Remove HTML from the line
$line =~ s/\<.*?\>//g;
# Cleanup filenames and turn it them
# a valid relative URL so that it can be uesd
# as a link
my $uri = $File::Find::name;
$uri =~ s/^$filePath//;
$uri = "/$uri";
if( $line =~ /$query/o ) {
print "<A HREF=$uri>$_</A><BR>";
}
}
close(IN);
}
sub display_menu {
print start_form,
b('Search this site for:'),
br,
textfield(-name=>'criteria'),
br,
submit(-name=>'Search'),
end_form;
}
------------------------------
Date: 22 Nov 2004 10:05:23 +0200
From: JMI <waggis_at_hotmail.com>
Subject: Re: using regexes as command line parameters
Message-Id: <Xns95A966A37A7B9waggishotmailcom@192.37.1.74>
Worked ! Thanks a lot :-)))
"Paul Lalli" <mritty@gmail.com> wrote in
news:2Q4nd.12483$wY2.3433@trndny05:
> "JMI" <waggis_at_hotmail.com> wrote in message
> news:Xns95A5B40F63810waggishotmailcom@192.37.1.74...
>> Let's imagine your program accepts two command line arguments to
> perform
>> replaces in a string:
>> usage: myprogram -s "foo" -r "bar"
>> where s is the search regex and r the replace regex.
>>
>> Everything works fine, even grouping with parenthesis, etc. As
> described in
>> detail in the cookbook.
>>
>> But:
>> When I want to use a captured value in the replacement regex, it does
>> simply not work. Using all possible syntaxes ( as \$1, or \\$1...)
> only
>> leads to either an exmpty value in the replaced string, or a
> plain-text
>> "$1" text when too much is escaped.
>
> Giving simply $1 makes the shell pass the shell's own $1 variable to
> your script.
> Giving \$1 passes the literal string '$1' to your script.
>
> What you need to do is tell Perl to evaluate that literal string as
> Perl:
>
> perl -le'$_ = q/foo/; s/($ARGV[0])/$ARGV[1]/ee; print;' foo \$1
>
> This is a trivial example, of course, but it does illustrate that perl
> is correctly replacing 'foo' with the captured match (which also happens
> to be 'foo').
>
> For more info, look up the /e modifier in
> perldoc perlretut
> or
> perldoc perlre
>
> Paul Lalli
>
------------------------------
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 7436
***************************************