[19262] in Perl-Users-Digest
Perl-Users Digest, Issue: 1457 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 21:05:51 2001
Date: Tue, 7 Aug 2001 18:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997232714-v10-i1457@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 7 Aug 2001 Volume: 10 Number: 1457
Today's topics:
Re: $ENV{'REMOTE_ADDR'} <dbe@wgn.net>
Re: $ENV{'REMOTE_ADDR'} <bwalton@rochester.rr.com>
Re: Continuing Perl MySQL DBI woes <cpryce@pryce.net>
Re: difference between using map {} or using CGI:: <gnarinn@hotmail.com>
Dos commands execution in Win2K scheduler <ultronic@bigfoot.com>
Re: Dos commands execution in Win2K scheduler <brentdax1@earthlink.net>
FAQ: How can I make the Perl equivalent of a C structur <faq@denver.pm.org>
Re: get rid of these leading zeros in Perl <godzilla@stomp.stomp.tokyo>
Re: get rid of these leading zeros in Perl (Abigail)
Re: Having some trouble with map <ren@tivoli.com>
Re: member profile db <angenent@kabelfoon.nl>
Re: member profile db <angenent@kabelfoon.nl>
multiple line comments? <dangby@worldnet.att.net>
Re: multiple line comments? <bwalton@rochester.rr.com>
Re: multiple line comments? <james@zephyr.org.uk>
Re: multiple line comments? <cberry@cinenet.net>
Re: multiple line comments? <l_pantin@hotmail.com>
Re: multiple line comments? <godzilla@stomp.stomp.tokyo>
Re: multiple line comments? <dbe@wgn.net>
Re: Search statments -> SQL -> DBI <goldbb2@earthlink.net>
Re: Sending e-mail from a script in MS windows (Martien Verbruggen)
Re: split(?) <andrew.savige@ir.com>
SQL error with s/// <dangby@worldnet.att.net>
Re: SQL error with s/// <andrew.savige@ir.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Aug 2001 17:07:21 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: $ENV{'REMOTE_ADDR'}
Message-Id: <3B7082B9.29433A6B@wgn.net>
jtjohnston wrote:
>
> ############################
> ##### Why does this work: #####
> ############################
>
> if(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
>
> ############################
> ##### But Not this? ######
> ############################
> if(!($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
> ############################
> ##### Or Not this? ######
> ############################
> if(!(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/)))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
Maybe if you explained what you are trying to do. They work as
one would expect and obviously won't have the same result since
they aren't equivalent.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Wed, 08 Aug 2001 01:02:16 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: $ENV{'REMOTE_ADDR'}
Message-Id: <3B708FDD.FC71FBF1@rochester.rr.com>
jtjohnston wrote:
>
> ############################
> ##### Why does this work: #####
> ############################
>
> if(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
>
> ############################
> ##### But Not this? ######
> ############################
> if(!($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
> ############################
> ##### Or Not this? ######
> ############################
> if(!(($ENV{'REMOTE_ADDR'} =~ /\b(127\.0)/) || ($ENV{'REMOTE_ADDR'} =~
> /\b(132\.210)/)))
> {
> print "Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }else{
> print "Not Allowed<BR>\n";
> print "$ENV{'REMOTE_ADDR'}\n";
> exit;
> }
I'm not sure what you mean by "work". What do they do or not do that
are different from what you expect? All three seem to "work" to me --
they compile, run, and generate an output according to the logic
embedded in them. Perhaps you mean the logic is not accomplishing what
you want it to do for the second two cases? Or perhaps that the regex
/\b(127\.0)/ will match both 127.0.0.1 and 0.127.0.1, as well as
127.033.044.055 and many others that you likely don't want it to match?
--
Bob Walton
------------------------------
Date: Tue, 7 Aug 2001 17:17:46 -0500
From: "cp" <cpryce@pryce.net>
Subject: Re: Continuing Perl MySQL DBI woes
Message-Id: <5MZb7.3770$x84.891799@ruti.visi.com>
"Alan Farrington" <killspam@redyonder.co.uk> wrote in message
news:PJQb7.89524$_b4.7071731@news1.cableinet.net...
> Could anyone briefly scan the code below and tell me why it is giving an
SQL
> error. I've been playing with the code since 9 am and am getting
absolutely
> nowhere. I think I am missing the fundamentals :-(
> #! /usr/bin/perl -w
>
> use strict;
> use Win32API::Net;
> use Win32::NetAdmin;
> use DBI;
>
> my ($dsn)="DBI:mysql:m0ajf:localhost";
> my ($user_name)="root";
> my ($password)="";
> my ($dbh,$sth);
> my $server;
> my %users_info;
> my @users;
> my $users_ref = \@users;
> my $users_info= \%users_info;
> my ($name,$full_name,$comment,$name_sql);
> my $query;
>
> # connect to database
>
> $dbh=DBI ->connect($dsn,$user_name,$password, {RaiseError=> 0, PrintError
> =>1});
>
> obtain_data();
>
> $sth ->finish();
> $dbh ->disconnect();
>
> sub obtain_data
>
> {
> Win32::NetAdmin::GetDomainController ("","",$server);
> Win32::NetAdmin::GetUsers($server,2,$users_ref);
>
> foreach $users_ref(@users)
> {
> Win32API::Net::UserGetInfo($server,$users_ref,2,$users_info);
>
> $name = $users_info {'name'};
> $full_name = $users_info {'fullName'};
> $comment = $users_info {'usrComment'};
>
> print "\n\t**********name is $name*************\n";
>
> sql_update();
> }
> }
>
> sub sql_update
>
> {
> $query ="SELECT user_name FROM nt_detail WHERE user_name=?";
> my $sth =$dbh->prepare($query);
> $sth->execute($name);
>
> ($name_sql)=$sth->fetchrow_array();
It appears as though user_name is an unique value, and you are testing to
see if there is one.
I would use the more convenient selectrow_arrayref(). The above four lines
of code can be replaced with:
$name_sql = $dbh->selectrow_arrayref(qq{SELECT FROM nt_detail WHERE
user_name='$name'});
>
> if (defined($name_sql))
probably better not to use 'defined'.
if ($name_sql) { # works just fine
> {
> print "\nUpdate loop entered for existing records\n";
>
> $sth=$dbh->prepare(qq{UPDATE nt_detail SET user_name, full_name,comment
> VALUES(?,?,?)});
I'll bet you'd like a WHERE clause here, or you'd be updating all of your
records.
$sth = $dbh->prepare(qq{UPDATE nt_details SET user_name=?, full_name=?,
comment=? WHERE user_name='$name'});
> $sth->execute($name,$full_name,$comment); *********LINE63 HERE********
>
> }
> else
[ code snipped ]
>
> Error messages (sniped to avoid repetition)
>
> **********name is Administrator*************
>
> Update loop entered for existing records
> DBD::mysql::st execute failed: You have an error in your SQL syntax near '
> full_
> name,comment VALUES('Administrator','','')' at line 1 at importB_nt.pl
line
> 63.
>
> **********name is Guest*************
>
> Update loop entered for existing records
> DBD::mysql::st execute failed: You have an error in your SQL syntax near '
> full_
> name,comment VALUES('Guest','','')' at line 1 at importB_nt.pl line 63.
>
> **********name is krbtgt*************
>
> Update loop entered for existing records
> DBD::mysql::st execute failed: You have an error in your SQL syntax near '
> full_
> name,comment VALUES('krbtgt','','')' at line 1 at importB_nt.pl line 63.
>
Make sure that your DB accepts NULL values on these fields...
cp
------------------------------
Date: Tue, 7 Aug 2001 21:43:18 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: difference between using map {} or using CGI::
Message-Id: <997220598.554921558592469.gnarinn@hotmail.com>
In article <9kp5in$5m5ko$2@ID-93885.news.dfncis.de>,
Aman Patel <patelnavin@icenet.net> wrote:
>Whats the exact difference between:
>
># I want all CGI form parameters to be in %params hash
>use CGI qw(:standard);
>my $query = new CGI; my %params;
>for ($query->param()) {
> $params{$_}=$query->param($_);
>}
>
>AND:
>use CGI qw(:standard);
>my $query = new CGI;
>my %params = map {$_ => $query->param($_)} $query->param();
>
>You might say that the later one is brief. But there is actually a technical
>difference between the two methods of "filling" %params. I dont know what,
>but when i executed under different post methods. The first one wored. The
>later one yeilded really really unexpected results. (FORM Method was POST).
>
really? what input? what results?
seems reasonable to me.
although there is always:
use CGI qw(Vars);
my %params=Vars();
gnari
------------------------------
Date: Tue, 7 Aug 2001 19:39:15 -0400
From: "Ultronic" <ultronic@bigfoot.com>
Subject: Dos commands execution in Win2K scheduler
Message-Id: <GY_b7.40418$HW.1770960@wagner.videotron.net>
Hi,
I can't execute any Dos command using the system() call if the Perl script
is executed in the task scheduler of a Win 2000 Server. If I run the same
Perl script in a DOS window it works fine. Maybe it's a Win2000 security
issue but I'm not sure. I run Activeperl 5.6.1.628 for Windows.
The error code I get after execution of the command system("del
c:\\xxx.txt") is 65280.
Can somebody help me ?
Thanks in advance
------------------------------
Date: Wed, 08 Aug 2001 00:20:59 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Dos commands execution in Win2K scheduler
Message-Id: <LB%b7.4140$nb4.354749@newsread1.prod.itd.earthlink.net>
"Ultronic" <ultronic@bigfoot.com> wrote in message
news:GY_b7.40418$HW.1770960@wagner.videotron.net...
> Hi,
>
> I can't execute any Dos command using the system() call if the Perl script
> is executed in the task scheduler of a Win 2000 Server. If I run the same
> Perl script in a DOS window it works fine. Maybe it's a Win2000 security
> issue but I'm not sure. I run Activeperl 5.6.1.628 for Windows.
> The error code I get after execution of the command system("del
> c:\\xxx.txt") is 65280.
I suspect this is a permissions issue. BTW, why are you using
system("del")? Perl's unlink() builtin works just as well without having to
start up another program.
------------------------------
Date: Wed, 08 Aug 2001 00:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Message-Id: <0y%b7.118$T3.196815360@news.frii.net>
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 every Standard Distribution of
Perl.
+
How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Usually a hash ref, perhaps like this:
$record = {
NAME => "Jason",
EMPNO => 132,
TITLE => "deputy peon",
AGE => 23,
SALARY => 37_000,
PALS => [ "Norbert", "Rhys", "Phineas"],
};
References are documented in the perlref manpage and the upcoming the
perlreftut manpage. Examples of complex data structures are given in the
perldsc manpage and the perllol manpage. Examples of structures and
object-oriented classes are in the perltoot manpage.
-
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.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
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-1999 Tom Christiansen and Nathan
Torkington. 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.
04.66
--
This space intentionally left blank
------------------------------
Date: Tue, 07 Aug 2001 15:31:00 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <3B706C24.F9211B6A@stomp.stomp.tokyo>
Larry S wrote:
> i have a really simple (i believe) problem, and i'm new to this..
> i want to print out a value of $id1, without leading zeros, so say
> $id1 is "00061", i want to print it as "61".
print $id1 + 0;
Godzilla!
--
$_='8445541441554045104354153585754555
84310435845554851084457414415540
43104374153585754555843414310435380
858441874144434574388341844444480
487874148487414341434185488341
84447341448341844441341448341
8555748741430744574378
8441887441418441410434153585754555
84487415448448741448808088480808087435155740548
44441884418418804141841434555
84448878841414344141434435551435155748
848878787888878387878487848788584818878437810
84445743810';tr/873514/975318642abcdef/;
s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;$_=reverse($_);
tr// H-OV-ZP-UA-G/;eval;exit;
------------------------------
Date: 8 Aug 2001 00:36:59 GMT
From: abigail@foad.org (Abigail)
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <slrn9n12e9.vbm.abigail@alexandra.xs4all.nl>
Jim Monty (monty@primenet.com) wrote on MMDCCCXCVIII September MCMXCIII
in <URL:news:9kpb98$3n2$1@nnrp1.phx.gblx.net>:
``
`` my $id1 = ...;
`` $id1 =~ s/^0+//; # Safest general solution
my $id1 = "0000000";
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: 07 Aug 2001 17:26:11 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Having some trouble with map
Message-Id: <m3ae1b8q2k.fsf@dhcp9-161.support.tivoli.com>
On 5 Aug 2001, iltzu@sci.invalid wrote:
> (It's not really even about side effects in map being evil. It's
> more about externally noticeable side effects in map being more
> obfuscated than foreach or side-effectless map, and about
> obfuscation being bad in many, though by no means all, situations.)
Maybe it's just that my introduction to map was via LISP, but I've
always mentally parsed map as meaning "map this code onto this list".
The fact that it also returns the results of that action is
secondary. In this light, I don't see how it is obfuscation.
Now, changing data with grep -- that's something else entirely...
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 8 Aug 2001 01:06:00 +0200
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Re: member profile db
Message-Id: <9kps7l$1ara$1@news.kabelfoon.nl>
well i had a bad experience with a stock quote logging script, first of all
the actual data was only a few megabytes but because of the number of
seperate files the actual size on disk was gigantic..
Also backing up with zip didn't quite work out the way i hoped for, it
reported an error that there are too many files
chris
"Alan Wrigley" <spamhater@keepyourfilthyspamtoyourself.co.uk> wrote in
message news:a51563a64a.spamhater@keepyourfilthyspamtoyourself.co.uk...
> In message <9kovi6$b3o$1@news.kabelfoon.nl>
> "GOGAR" <angenent@kabelfoon.nl> wrote:
>
> > Hi, i'm fairly new to perl and cgi and i've been trying to create a
website
> > where people have to log in .. etc etc..
> >
> > now the problem is the structure of the databse.. each time a new user
> > registers a file with their password and other info is created.. it
all
> > works.. but this method would result in thousands and thousands of
little
> > member files.. wich is a pain in the #$# to manage..
>
> Why do you believe it would be a PITA to manage? If the system is set up
> correctly it should manage itself. I run a site that does just that - I
> did it this way partly because my provider didn't offer any database
> facilities, and partly because it enabled me to experiment and fine-tune
> the services as I went along. I have several hundred members and a
> number of different files for each member - personal details, member's
> profile, access details, mailbox etc - but I neither know nor care how
> many files there are on the site at any time because they are all
> created and managed automatically by the Perl scripts. For backup I have
> a cron job which just zips up the entire directory structure and emails
> me the zip file once a day, together with an analysis of the day's
> activity. Info which is used a lot is passed back and forth in a cookie
> to save looking it up from a file each time. When someone joins, the
> system extracts the necessary data and sends me an email. I've also set
> it up to send me emails triggered by other events, e.g. when someone
> uploads a photo that needs approving or processing.
>
> If I were starting again I probably wouldn't do it this way since my new
> provider offers MySQL. But the existing system works perfectly well and
> requires no effort on my part to manage once the scripts are doing their
> job.
>
> Alan
------------------------------
Date: Wed, 8 Aug 2001 01:19:19 +0200
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Re: member profile db
Message-Id: <9kpt0j$1bn4$1@news.kabelfoon.nl>
Thanks anyways ;-) , i think i'll just see how things work out..
it seemed a bit simplistic so i was wondering if there was some way it
"should" be done.
i see a lot of "sql" flying around various websites yet i have no clue what
it is...
i already have small authentification files being put in a ramdrive upon
login or cookie identification.. a cut down copy of perl with only the
libraries i need and the cgi scripts are also copied onto the ramdrive
when the server boots up so there should be almost no disk acces..
i'm just experimenting with some things.. i bet nobody has ever done this
before hehe.. but i guess someone is gonna reply and talk down of my ideas
they always do lol
well thanks for the replies guys,
chris
------------------------------
Date: Tue, 07 Aug 2001 23:40:23 GMT
From: "Daniel Gibby" <dangby@worldnet.att.net>
Subject: multiple line comments?
Message-Id: <H%_b7.230$Ki1.9901@bgtnsc06-news.ops.worldnet.att.net>
Is there anyway to have a multiple line comment in Perl?
------------------------------
Date: Tue, 07 Aug 2001 23:51:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: multiple line comments?
Message-Id: <3B707F6C.296745DB@rochester.rr.com>
Daniel Gibby wrote:
>
> Is there anyway to have a multiple line comment in Perl?
=pod
Sort
of.
=cut
--
Bob Walton
------------------------------
Date: Wed, 8 Aug 2001 00:55:08 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: multiple line comments?
Message-Id: <+wD$Bzqc$Hc7EwgC@gratiano.zephyr.org.uk>
In message <H%_b7.230$Ki1.9901@bgtnsc06-news.ops.worldnet.att.net>,
Daniel Gibby <dangby@worldnet.att.net> writes
>Is there anyway to have a multiple line comment in Perl?
Use POD. perldoc perlpod
Or just put # at the start of every line. Is there any reason why
people don't like doing this?
--
James Coupe PGP Key: 0x5D623D5D
EBD690ECD7A1F
HEY, MOM! I FOUND SOME OF THOSE PEOPLE ON THE INTERNET B457CA213D7E6
YOU WERE TELLING ME TO NOT TALK TO! 68C3695D623D5D
------------------------------
Date: Wed, 08 Aug 2001 00:07:36 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: multiple line comments?
Message-Id: <Xns90F6AE3928361cberrycinenetnet1@207.126.101.92>
James Coupe <james@zephyr.org.uk> wrote in news:+wD$Bzqc
$Hc7EwgC@gratiano.zephyr.org.uk:
> In message <H%_b7.230$Ki1.9901@bgtnsc06-news.ops.worldnet.att.net>,
> Daniel Gibby <dangby@worldnet.att.net> writes
>>Is there anyway to have a multiple line comment in Perl?
>
> Use POD. perldoc perlpod
>
> Or just put # at the start of every line. Is there any reason why
> people don't like doing this?
Yes. It's a pain when writing or editing long comment blocks. It stops you
from using paragraph reformatting and the like (without special handling in
the editor or macro). It breaks simple searches for text strings with
whitespace separators. It can't make an arbitrary block of code invisible
by editing just two lines. And so forth.
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: Wed, 08 Aug 2001 00:26:59 GMT
From: "Kevin Bartz" <l_pantin@hotmail.com>
Subject: Re: multiple line comments?
Message-Id: <nH%b7.7007$1p1.549421@bgtnsc04-news.ops.worldnet.att.net>
If you're using Emacs, just define a Lisp routine to take in a region
of text and put a hash before every line.
I do it in my .emacs file, which I'd be happy to share if you'd like.
Kevin
Daniel Gibby wrote in message ...
:Is there anyway to have a multiple line comment in Perl?
:
:
------------------------------
Date: Tue, 07 Aug 2001 17:33:04 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: multiple line comments?
Message-Id: <3B7088C0.5C8C85CE@stomp.stomp.tokyo>
Daniel Gibby wrote:
> Is there anyway to have a multiple line comment in Perl?
Godzilla!
--
TEST SCRIPT:
____________
#!perl
use constant cut => 2
# These are comments
# which are easy to read,
# which are easy to spot
# and are easy on the eyes.
# This sytle is flexible
# and can be used to right
# comment code lines.
# This is commented out code:
# $_ =~ s/gnarly nerd/sissified geek/;
# It is very easy to spot and read.
=pod
These are comments
which are hard to read,
which are hard to spot
and are hard on the eyes.
This sytle is inflexible
and cannot be used to right
comment code lines.
This is commented out code:
$_ =~ s/gnarly nerd/sissified geek/;
It is very hard to spot and read.
=cut
print "done";
# Use of =pod and =cut methodology can
# lead to fatal syntax errors.
# Pound sign commented methodology will not.
exit;
PRINTED RESULTS:
________________
Not enough arguments for read at test1.pl line 21, near "read,"
syntax error at test1.pl line 23, near "spot
and"
Execution of test1.pl aborted due to compilation errors.
------------------------------
Date: Tue, 07 Aug 2001 17:29:13 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: multiple line comments?
Message-Id: <3B7087D9.F6F1D7C7@wgn.net>
Daniel Gibby wrote:
>
> Is there anyway to have a multiple line comment in Perl?
Try using pod syntax:
=for comment
# These are the lines to be commented out
=cut
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Tue, 07 Aug 2001 21:05:32 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Search statments -> SQL -> DBI
Message-Id: <3B70905C.AFEC3764@earthlink.net>
MrBoom wrote:
>
> I have an Access database which I am producing dynamic web pages from
> using Perl and the DBI. Currently these pages are being generated SQL
> statements which are hard coded in the Perl scripts.
>
> The next task I've been given is to produce a web search facility for
> the database. A number of the fields in the database are free text
> fields, these are the ones I'll want to be searching. What I'd like to
> do is take a search statement, eg:
>
> +"the phantom menace" +maul -"jar jar"
>
> and convert that into a form which could be inserted into my SQL
> statement.
>
> Does anyone know of the best way of doing this?
use Text::ParseWords;
my $searchstring = q{+"the phantom menace" +maul -"jar jar"};
my @keywords = shellwords($searchstring);
my @and = grep /^-/, @keywords;
my @or = grep !/^-/, @keywords;
foreach( @and ) {
s/^-//; s/([%_"])/\\$1/g;
$_ = qq{NOT table.keywordsfield LIKE "%$_%"};
}
foreach( @or ) {
s/^+//; s/([%_"])/\\$1/g;
$_ = qq{table.keywordsfield LIKE "%$_%"};
}
my $select = qq{SELECT * FROM tablename};
$select .= "WHERE " if( @and || @or );
$select .= join(" AND ",@and);
$select .= " " if( @and && @or );
$select .= join(" OR ",@or);
$sth = $dbh -> prepare( $select ) or die ...;
$sth->execute( ) or die ...;
> Also, I'd like to rank the results in order of relevance. What is the
> best way of doing this?
Hrm, that's a bit harder. How much 'relevance' keywords should have is
hard to guess. I'll assume that the earlier keywords have more weight
than the later keywords.
my $results = $sth->fetchall_hashref or die ...;
# the query has already excluded the - items.
@keywords = grep !/^-/, @keywords;
s/^+// for @keywords; # get rid of the leading +
for( @$results ) {
my ($kwf, $w, $ww) = ( $_->{keywordsfield}, 0, 1 );
for my $keyword (@keywords) {
++$ww;
$w += 1/$ww if( -1 != index( $kwf, $keyword ) );
}
$_->{".weight"} = $w;
}
@$results = sort { $b->{".weight"} <=> $a->{".weight"} } @$results;
delete $_->{".weight"} for @$results;
The way I have it now, things with both "the phantom menace" and "maul"
appear before things with only one or the other, and things with just
"the phantom menace" appear before things with just "maul".
This works ok if you want to process them all at once, but you would be
better off if you could find some way for the database to do your
sorting for you... that way, if you can still easily cut it up into
pages using a LIMIT item in your select, and you'll still get the most
relevant on your first page, less relevant on later pages, etc.
> This seems to me to be the sort of thing that there should be a module
> for, does anyone know if there is?
Well, there's the module for parsing the words with quotes... but
ranking based on "relevance" is something which varies from programmer
to programmer, and is best done as part of the query, anyway.
--
I need more taglines. This one is getting old.
------------------------------
Date: Wed, 8 Aug 2001 09:59:23 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sending e-mail from a script in MS windows
Message-Id: <slrn9n106r.tjn.mgjv@martien.heliotrope.home>
On Tue, 07 Aug 2001 02:05:19 GMT,
Dan Baker <dan@nospam_dtbakerprojects.com> wrote:
>
>
> Martien Verbruggen wrote:
>
>> > hhhmmm, last I tested, it did NOT work when sending from a win32
>> > (windows98) machine running a localhost.
>>
>> What does this mean? 'Running a localhost'? Every TCP/IP implementation
>> AFAIK has a 'localhost'...
> -------
> meaning I tried sending mail fired up from a script that was executed
> from a webpage running on http://localhost. I use Xitami running on my
Ah, that's a lot more information suddenly :). Now we know that you used
CGI or something like that. You do know that it's a good idea to test
scripts from the command line, don't you? Especially when there are
errors (FAQ section 9 talks about this a bit).
> In this case I think I remember its because MIME::Lite doen't have
> sendmail under the covers in the win32 port so its a little more
> limited. Unless I read the docs and examples wrong, which is possible,
> then there are several feaures that are not available when running on
> win32.
But MIME::Lite should be able to fall back to other methods than
sendmail, as indicated in the documentation. This is from the README:
### Do something like this in your 'main':
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', "smtp.myisp.net", Timeout=>60);
}
### Now this will do the right thing:
$msg->send; ### will now use Net::SMTP as shown above
I'd probably do more something like:
# At the top of the program:
$SMTPHOST = 'mail.wherever.org';
# Much later on:
MIME::Lite->send('smtp', $SMTPHOST, Timeout=>60) if ($SMTPHOST);
$msg->send;
Just because this is slightly easier to follow, and it doesn't require
an extraneous variable, and it keeps configuration separate from running
code.
>> Are you sure that you had your MTA set up correctly?
> -------
> I dunno, what's an MTA ? pardon the ignorance. I guess now I'm inspired
> to get to the bottom of it and re-test and maybe figure this out...
Sorry, MTA is Mail Transport Agent. In this case you probably don't have
one, since your OS doesn't normally have one installed. You'd have to
make sure that you use the right SMTP host name in your script, and it
should all work ok. Of course, you'll need to make sure Net::FTP is
installed.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 8 Aug 2001 08:37:40 +1000
From: "Knob" <andrew.savige@ir.com>
Subject: Re: split(?)
Message-Id: <U4_b7.5$%x2.593@news0.optus.net.au>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9mvokb.hfv.tadmc@tadmc26.august.net...
> Knob <andrew.savige@ir.com> wrote:
>
> >while ($buf =~ /\s*-(\S+)\s*(?:\{(.*?)\}|(\S+))/go) {
> ^
> ^ useless
>
> You should not include options that do nothing.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
Thanks for pointing out the /o blunder; the line should read:
while ($buf =~ /\s*-(\S+)\s*(?:\{(.*?)\}|(\S+))/g) {
Knob.
------------------------------
Date: Tue, 07 Aug 2001 23:24:42 GMT
From: "Daniel Gibby" <dangby@worldnet.att.net>
Subject: SQL error with s///
Message-Id: <_M_b7.176$Ki1.9121@bgtnsc06-news.ops.worldnet.att.net>
I am trying to use the s/// modifier to replace any single quotes or double
quotes with a backslash+quote so that I can insert the quote into my SQL
database.
This is how I am doing it:
$single_quote = "\\'";
$form{$each_var} =~ s/\'\"/$single_quote/g;
For some reason it doesn't seem to be working correctly. Am I missing
something?
------------------------------
Date: Wed, 8 Aug 2001 10:06:05 +1000
From: "Knob" <andrew.savige@ir.com>
Subject: Re: SQL error with s///
Message-Id: <Nn%b7.9$%x2.707@news0.optus.net.au>
"Daniel Gibby" <dangby@worldnet.att.net> wrote in message
news:_M_b7.176$Ki1.9121@bgtnsc06-news.ops.worldnet.att.net...
> I am trying to use the s/// modifier to replace any single quotes or
double
> quotes with a backslash+quote so that I can insert the quote into my SQL
> database.
>
> This is how I am doing it:
>
> $single_quote = "\\'";
> $form{$each_var} =~ s/\'\"/$single_quote/g;
>
> For some reason it doesn't seem to be working correctly. Am I missing
> something?
>
>
$_ = q#I said "Don't Panic"#;
print "$_\n";
s/(['"])/\\$1/g;
print "$_\n";
------------------------------
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.
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 1457
***************************************