[19276] in Perl-Users-Digest
Perl-Users Digest, Issue: 1471 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 00:05:42 2001
Date: Wed, 8 Aug 2001 21:05:08 -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: <997329908-v10-i1471@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 8 Aug 2001 Volume: 10 Number: 1471
Today's topics:
Re: cgi->upload <ron@savage.net.au>
Re: cross reference? <goldbb2@earthlink.net>
Re: FAQ: How do I shuffle an array randomly? <goldbb2@earthlink.net>
Re: Intermittent problems printing from perl <bwalton@rochester.rr.com>
Re: LD_RUN_PATH (Martien Verbruggen)
mySQL - More records or longer records - Speed? (Mark Deibert)
Re: mySQL - More records or longer records - Speed? (Martien Verbruggen)
Re: mySQL - More records or longer records - Speed? <l_pantin@hotmail.com>
Re: mySQL - More records or longer records - Speed? <bwalton@rochester.rr.com>
NET::FTP and other file operations <gerhardpremovethis@inch.com>
Re: newbie q: multi line matching (Tad McClellan)
Re: newbie q: multi line matching <gnarinn@hotmail.com>
Re: newbie q: multi line matching <goldbb2@earthlink.net>
Re: newbie question... <gnarinn@hotmail.com>
Re: Perl not releasing lock on file under Windows?? <miscellaneousemail@yahoo.com>
Re: Perl Search Engine <AHALL5@nc.rr.com>
Re: Perl Search Engine <brentdax1@earthlink.net>
Re: PERL system function and variables <goldbb2@earthlink.net>
Re: perldoc is like Greek to a beginner?? <miscellaneousemail@yahoo.com>
Re: perldoc is like Greek to a beginner?? <miscellaneousemail@yahoo.com>
Re: perldoc is like Greek to a beginner?? <uri@sysarch.com>
Re: Redirect Script with Form Variables <brentdax1@earthlink.net>
replacing hex characters within a string with their asc <dianne@dogmac.com>
Re: SQL error with s/// (John J. Trammell)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 9 Aug 2001 13:30:11 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: cgi->upload
Message-Id: <hwnc7.1423$813.66242@ozemail.com.au>
If all else fails, see tut # 37: http://savage.net.au/Perl-tutorials.html
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
------------------------------
Date: Wed, 08 Aug 2001 23:59:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: cross reference?
Message-Id: <3B720A87.74C5EFFF@earthlink.net>
Leary wrote:
>
> "Leary" <leary@foad.NOSPAM.org> wrote in message
[snip]
> > The "for /f" takes a string of input, delimited by the delims= char and
> > returns the number of "tokens" specified by the tokens= field. As an
> > example if testdata.txt contained a single line as follows;
> >
> > >>start testdata.txt<<
> > first field, second field, third field
> > >>end testdata.txt<<
> >
> > then ;
> > %%g=first field
> > %%h=second field
> > %%i=third field
> >
> > %%g is explicitly declared while %%h and %%i are implicitly declared via
> > the tokens option. Basically it's one of the primary methods of parsing text
> > in an NT script.
open TESTDATA, "<testdata.txt" or die "Could not open testdata.txt: $!";
while(<TESTDATA>) {
my ($g, $h, $i) = split /,\s*/;
do stuff here
}
close TESTDATA;
> In the hope of not seeming like a total newbie loser... I have a script I
> wrote in NT script that generates a report. As an exercise I am writing a
> perl script that does the same report. The for /f statement above is what I
> used to parse the input data for the report. The actual data I am parsing
> looks like this;
>
> 11:00:01 AM Mon Oct 09, 2000 00005 PAYMENT 40.10 0.00 FALSE FALSE
>
> That should be all one line.
Considering the variable spacing, I would guess that this is NOT simply
a space delimited string, but one which uses fixed length fields.
open TESTDATA, "<testdata.txt" or die "Could not open testdata.txt: $!";
while(<TESTDATA>) {
my ($date, $num, $type, $credit, $debit, $bool_a, $bool_b) =
unpack "a28 xx a5 x a9 x a8 x a7 x a5 x a5", $_;
do stuff here
}
close TESTDATA;
OTOH, if the only fixed length field is the date, then perhaps this
might be prefferred:
open TESTDATA, "<testdata.txt" or die "Could not open testdata.txt: $!";
while(<TESTDATA>) {
(my ($date), $_) = unpack "a28 x a*", $_;
my ($num, $type, $credit, $debit, $bool_a, $bool_b) = split;
do stuff here
}
close TESTDATA;
One or more [even all] of these may be wrong... I don't know what kind
of data you have other than that one line.
--
I need more taglines. This one is getting old.
------------------------------
Date: Thu, 09 Aug 2001 00:14:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: FAQ: How do I shuffle an array randomly?
Message-Id: <3B720E24.F4FC879D@earthlink.net>
John J. Trammell wrote:
>
> PerlFAQ Server <faq@denver.pm.org> wrote:
[snip]
> 6 for ($i = @$array; --$i; ) {
> 7 my $j = int rand ($i+1);
> 8 @$array[$i,$j] = @$array[$j,$i];
> 9 }
[snip]
> for (my $i = @$array; $i > 0; $i--) {
> my $j = int rand ($i+1);
> @$array[$i,$j] = @$array[$j,$i];
> }
This isn't correct either. In the original code from the FAQ, the first
value of $i inside the loop was @$array-1, due to the --$i inside the
for test. Yours has $i starting at @$array. Better might be:
sub fisher_yates_shuffle {
my $array = shift;
for (my $i = @$array; --$i > 0; ) {
my $j = int rand ($i+1);
@$array[$i,$j] = @$array[$j,$i];
}
}
--
I need more taglines. This one is getting old.
------------------------------
Date: Thu, 09 Aug 2001 03:00:49 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Intermittent problems printing from perl
Message-Id: <3B71FD1E.40DDE68F@rochester.rr.com>
Zenon Bachir wrote:
...
> I am getting an intermittent problem trying to print a postscript
> file. I have a perl batch program which runs automatically from a
> scheduler. It logs onto our Oracle database and checks a queue for
> pending jobs. It then calls our report generator (SQR) which creates a
> postscript file. It tries to print the file using the ‘lp’
> command. If all goes well it removes the job from the queue.
>
> It seems that sometimes (30% of the time) the file does not print!
> There is no error. It just quietly goes on its way. The postscript
> file looks OK. I can view/print it with no problems.
>
> Is it possible that the postscript file does not yet exist when we try
> to print? Is checking for the return from ‘system’ enough
> to detect any problems that occurred?
...
> Zenon Bachir
...
It is possible your report generator, or pieces of it, is running
asynchronously (i.e., in the background). If so, system() may return
before the report is generated, or before it is completely generated.
Check and see if you can make the report generator run in the
foreground, so that system() will not return until the report is
complete. Also, you could sleep for a while after the system() call and
see if that improves the odds.
--
Bob Walton
------------------------------
Date: Thu, 9 Aug 2001 11:38:43 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: LD_RUN_PATH
Message-Id: <slrn9n3qd3.cq.mgjv@martien.heliotrope.home>
On Wed, 08 Aug 2001 12:21:08 -0500,
Bing Du <bing-du@tamu.edu> wrote:
None of this stuff has anything to do with Perl, but are general Unix
runtime linker things. I suggest you actually ask this question on a
newsgroup that talks about irix. That said:
\begin{offtopic}
> I got the following error when I run it:
>
>==============
> Can't load
> '/usr/freeware/lib/perl5/site_perl/5.005/irix-64/auto/DBD/mysql/mysql
> .so' for module DBD::mysql: 27636767:/usr/freeware/bin/perl64: rld:
> Fatal Error:
> Cannot Successfully map soname 'libmysqlclient.so.7' under any of the
> filenames
[snip]
> Our system admin suggested me set up LD_RUN_PATH to /usr/local/lib/mysql
> in my script. I did so as shown below. And I can see LD_RUN_PATH in
> the printout of %ENV. However I still got the above long error message.
LD_RUN_PATH is used when you compile your libraries, to include the path
in the executable. I think you want LD_LIBRARY_PATH.
if Irix has ldd, which I believe it should have, then try something
like:
ldd /usr/freeware/lib/perl5/site_perl/5.005/irix-64/auto/DBD/mysql/mysql.so
which should tell you which libraries are used, and which can't be
found. Then set your LD_LIBRARY_PATH environment variable to include the
path you need, and then try ldd again. Once all the libraries needed can
be found by ldd, your environment should be ok.
> #!/usr/freeware/bin/perl64
>
> $ENV{'LD_RUN_PATH'} = "/usr/local/lib/mysql";
>
> foreach $key (keys %ENV)
> {
> print "$key: $ENV{$key}\n";
> }
>
> use DBI;
> use DBD::mysql;
This is too late anyway. You need to make sure that LD_LIBRARY_PATH is
set _before_ Perl tries to load DBD::mysql. The use statements are done
at compile time, your statement is done at run time. You could put yours
in a BEGIN block, which may help, but it also may not. It is actually
better to make sure that your environment is set up correctly for this
sort of stuff before you even start your program.
Set LD_LIBRARY_PATH in your environment, and the executing environment
of everything that needs to run your program.
Maybe better solutions are:
Add the path to the configuration of your run time linker, if it
supports that (probably man ld.so).
Set LD_RUN_PATH before building and linking the Perl module. Depending
on your system that may or may not work.
Put the mysql libraries in a spot where your system will find them
automatically (your sysadmin won't like this one, probably)
\end{offtopic}
Martien
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a
Commercial Dynamics Pty. Ltd. | terminological inexactitude.
NSW, Australia |
------------------------------
Date: 8 Aug 2001 18:25:06 -0700
From: area31@mail.com (Mark Deibert)
Subject: mySQL - More records or longer records - Speed?
Message-Id: <20f405bf.0108081725.317cbb9b@posting.google.com>
What would be faster in mySQL (or any really), creating a table that
will store 1000 records with 4 fields in each record, or 4 records
with 1000 fields in each record?
Thanks for your input,
Mark Deibert
------------------------------
Date: Thu, 9 Aug 2001 12:04:44 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: mySQL - More records or longer records - Speed?
Message-Id: <slrn9n3rts.cq.mgjv@martien.heliotrope.home>
On 8 Aug 2001 18:25:06 -0700,
Mark Deibert <area31@mail.com> wrote:
> What would be faster in mySQL (or any really), creating a table that
> will store 1000 records with 4 fields in each record, or 4 records
> with 1000 fields in each record?
Why are you asking this in a Perl newsgroup?
Try finding a group that talks about mysql, or check the website. You'll
have more success, and more accurate answers if you ask the people who
should know, instead of just a random group that may or may not know
anything about this.
Martien
--
Martien Verbruggen |
Interactive Media Division | This matter is best disposed of from
Commercial Dynamics Pty. Ltd. | a great height, over water.
NSW, Australia |
------------------------------
Date: Thu, 09 Aug 2001 02:03:20 GMT
From: "Kevin Bartz" <l_pantin@hotmail.com>
Subject: Re: mySQL - More records or longer records - Speed?
Message-Id: <Ibmc7.39304$gj1.3630120@bgtnsc05-news.ops.worldnet.att.net>
He probably forgot to mention that he's using Perl DBI to fetch the
data.
I can't say I've rigorously tested this, but I'd suggest crafting your
table to ensure that you'll be able to run easy selects for only the
data you'll need. For the most part, I've found that Perl DBI's
execution speed depends on the number of elements you end up fetching.
But I haven't benchmarked this by any means.
Kevin
Martien Verbruggen wrote in message ...
:On 8 Aug 2001 18:25:06 -0700,
: Mark Deibert <area31@mail.com> wrote:
:> What would be faster in mySQL (or any really), creating a table
that
:> will store 1000 records with 4 fields in each record, or 4 records
:> with 1000 fields in each record?
:
:Why are you asking this in a Perl newsgroup?
:
:Try finding a group that talks about mysql, or check the website.
You'll
:have more success, and more accurate answers if you ask the people
who
:should know, instead of just a random group that may or may not know
:anything about this.
:
:Martien
:--
:Martien Verbruggen |
:Interactive Media Division | This matter is best disposed of
from
:Commercial Dynamics Pty. Ltd. | a great height, over water.
:NSW, Australia |
------------------------------
Date: Thu, 09 Aug 2001 02:37:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: mySQL - More records or longer records - Speed?
Message-Id: <3B71F7AE.CCA5E85D@rochester.rr.com>
Mark Deibert wrote:
>
> What would be faster in mySQL (or any really), creating a table that
> will store 1000 records with 4 fields in each record, or 4 records
> with 1000 fields in each record?
...
> Mark Deibert
Why don't you
use Benchmark;
and find out?
--
Bob Walton
------------------------------
Date: Thu, 9 Aug 2001 00:07:54 -0400
From: "Gerhard" <gerhardpremovethis@inch.com>
Subject: NET::FTP and other file operations
Message-Id: <9kt24u$6hdbo$1@ID-35855.news.dfncis.de>
I'm not sure if anyone else has come across this, but here it is:
I have this short script that retrieves some files using Net::FTP. In it I
also want to do some logging to a text file.
Seems that when I do a $ftp->get($file); I can no longer log to a text
file. (print LOG "[$when] $script: $msg\n";) LOG is of course the handle
to that text file.
Is there something about the $ftp->get() that knocks out other file handles?
Gerhard
------------------------------
Date: Wed, 8 Aug 2001 20:19:51 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie q: multi line matching
Message-Id: <slrn9n3lp7.oal.tadmc@tadmc26.august.net>
Andy Piper <andy.piper@freeuk.com> wrote:
>In article <slrn9n38vb.nsv.tadmc@tadmc26.august.net>, "Tad McClellan"
><tadmc@augustmail.com> wrote:
>> Andy Piper <andy.piper@freeuk.com> wrote:
>>>I want to be able to count all lines beginning with "mystring1" (easy),
>> Assuming the Whole Darn File is in $_:
>>
>> $count++ while /^mystring1.*\n\n/gm;
>>> while (<INPUT>)
>>> {
>>> $counter1++ if $_ =~ /^mystring1/;
>>> $counter2++ if $_ =~ /^mystring1 string2"/; # unfortunately
>>> matching "mystring1 string2\n\n" doesn't work :-(
>>> }
>>
>> open INPUT, $filename or die "Can't open '$filename' $!";
>> { local
>> $/; # enable slurp mode
>> $_ = <INPUT>; # slurp entire file into a single scalar
>> }
>> close(INPUT);
>>
>> # pattern match as above...
>
>Ah, but now how do I get the count of the number of lines starting just
>with "mystring" (equivalent to my original $counter1)?
I thought you said that that part was "easy" :-)
Well, you were right:
$counter1++ while /^mystring1/gm;
or maybe
$counter1++ while /^mystring1\n\n/gm;
>Thanks for the advice, Tad - I'm learning, gradually...
Glad I could help.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 9 Aug 2001 01:22:27 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: newbie q: multi line matching
Message-Id: <997320147.697738631628454.gnarinn@hotmail.com>
In article <20010808.220330.1884661237.2466@freeuk.com>,
Andy Piper <andy.piper@freeuk.com> wrote:
>Hi,
>
>I'm new to the Perl language, and at the moment it feels a lot like I've
>bitten off more than I can chew :-/
>
>I've got a file which I know contains a number of lines of a particular
>format, with three variations:
>
>1)
>mystring1
>
>2)
>mystring1 string2
>
>3)
>mystring1 string2
>string3
>
>I want to be able to count all lines beginning with "mystring1" (easy),
>and then count all occurences of 2), excluding 3) - that is, "mystring1
>string2<CR><blank line or CR>" not "mystring1 string2<CR>string3".
>
>At present a friend has helped me to the following, but it is flawed - my
>fault, not his - as it counts cases 1) plus 2) AND 3), which is no good. I
>believe I need to be able to perform multiline match, but I can't figure
>out how to achieve that :-(
>
> open INPUT, "<$i" or die "Can't open $i";
> while (<INPUT>)
> {
> $counter1++ if $_ =~ /^mystring1/;
> $counter2++ if $_ =~ /^mystring1 string2"/;
> # unfortunately matching "mystring1 string2\n\n" doesn't work :-(
> }
>
untested:
my $prev="";
while (<INPUT>)
{
$counter1++ if $_ =~ /^mystring1/;
$counter2++ if ($_ eq "\n") && ($prev =~ /^mystring1 string2"/);
$prev=$_;
}
gnari
------------------------------
Date: Wed, 08 Aug 2001 23:43:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: newbie q: multi line matching
Message-Id: <3B7206F0.B3577DAC@earthlink.net>
Andy Piper wrote:
>
> Hi,
>
> I'm new to the Perl language, and at the moment it feels a lot like
> I've bitten off more than I can chew :-/
>
> I've got a file which I know contains a number of lines of a
> particular format, with three variations:
>
> 1)
> mystring1
>
> 2)
> mystring1 string2
>
> 3)
> mystring1 string2
> string3
>
> I want to be able to count all lines beginning with "mystring1"
> (easy), and then count all occurences of 2), excluding 3) - that is,
> "mystring1 string2<CR><blank line or CR>"
> not "mystring1 string2<CR>string3".
local $_ = do {
local ($/, *INPUT);
open INPUT, "<$i" or die "Can't open $i";
<INPUT>;
};
$counter1 = m/^mystring1/mg;
$counter2 = m/^mystring1 string2(?!.*\nstring3)/mg;
This [untested code] should work because m//g in scalar context should
return the number of matches. The /m is needed so that ^ matches at
either the beginning of the string, or just after a newline.
If you really want to use a loop:
open INPUT, "<$i" or die "Can't open $i";
my $prev;
while( <INPUT> ) {
++$counter1 if /^mystring1/;
++$counter2 if $prev =~ /^mystring1 string2/ &&
!/^string3/;
$prev = $_;
}
++$counter2 if $prev =~ /^mystring1 string2/;
close INPUT;
I prefer the first form, since the file is opened for the shortest
amount of time possible, and is automatically closed. Not to mention,
if something else uses a filehandle INPUT, the first doesn't clobber it,
the second does.
--
I need more taglines. This one is getting old.
------------------------------
Date: Thu, 9 Aug 2001 01:06:01 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: newbie question...
Message-Id: <997319161.709625550545752.gnarinn@hotmail.com>
In article <3B71A339.4050106@post.rwth-aachen.de>,
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Barry Kimelman wrote:
>
>> All perl statements must be terminated by a semicolon
>
>Strictly speaking, this is not quite true. The semicolon in Perl rather
>acts like a statement delimiter than a terminator. That's why
>if ($cond) { print "hello" }
>works.
>
and indeed, that is why the OP's example worked with one statement,
but not with both.
gnari
------------------------------
Date: Thu, 09 Aug 2001 01:27:39 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Perl not releasing lock on file under Windows??
Message-Id: <MPG.15db9521cdbc297198971a@news.edmonton.telusplanet.net>
In article <3B71BC85.60803@post.rwth-aachen.de>, Tassilo von Parseval at
Tassilo.Parseval@post.rwth-aachen.de says...
> You should better not define a constant TRUE and FALSE. This is
> something that comes from other programming languages and might cause
> problems in Perl. This may work for scalars but matters get more complex
> under different circumstances, such as lists and hash-elements.
> I can't give you a definite example now where this might fail....I just
> remember Randal once giving some code-snippets where a mere TRUE or
> FALSE would break your script.
Interesting Tassilo. I never thought of that. I will have to check into
this.
I finally solved my problem and below I have given a solution for anyone
who is interested. I should have deleted this post. Sorry about that.
Thanks to both you and JR for responding. I am very blessed to have you
all helping me out.
PROBLEM SOLUTION:
Here is what was happening. I had four programs open that were operating
on the file (subscribe.cgi) written in Perl.
Windows Apache.
An HTML editor.
Opera.
Perl.
My code consisted of a form that when submitted called subscribe.cgi
through the following HTML code:
<form action="../cgi-bin/subscribe.cgi" method="POST">
I opened my browser. Refreshed "localhost" which called up my main form.
So far so good. Then I would hit the Submit button on that form which
forced the form to execute subscribe.cgi as seen above.
Now normally I would have gotten errors on my browser screen and all that
but instead Opera (and Internet Explorer) would just hang and hang and
hang until I pressed their respective Stop buttons. I guess I shouldn't
say that they hung. What actually happened is that they would pass off
control to Perl. Which tried to parse and execute subscribe.cgi.
When I did a CTRL-ALT-DELETE to see what was open, I saw a copy of Perl
for every instance that I pressed the Submit button.
When I would stop the action in the browser, Perl apparently had not
finished with the script yet (it was stuck parsing it due to script
errors). So Perl had a hold of the file. Subsequently I couldn't make
changes to it.
The solution was to CTRL-ALT-DELETE, do and End Task on Perl (which did
not release the lock), go out to the DOS prompt, copy the file, rename
the file, delete the file, open up the copy back in my HTML editor, and
finally save it to the name it had before access was denied.
I cleaned up my Perl script and the problem is no longer happening.
I just never had this sort of thing happen while developing a web
page before (though I had experienced Access Denied file use problems in
the past in other contexts) and it was rather confusing trying to figure
out what was happening.
--
Carlos
www.internetsuccess.ca
------------------------------
Date: Thu, 09 Aug 2001 02:08:51 GMT
From: "Antoine Hall" <AHALL5@nc.rr.com>
Subject: Re: Perl Search Engine
Message-Id: <Tgmc7.105467$TM5.15468673@typhoon.southeast.rr.com>
Yeah, but I have a text extensive website with over 300 pages and I would
have to search every page....would I need to build some kind of index table
or file?
"Kevin Bartz" <l_pantin@hotmail.com> wrote in message
news:Malc7.39176$gj1.3621911@bgtnsc05-news.ops.worldnet.att.net...
> Try $text =~ /$word/
>
> It's burly and built for the job.
>
> Kevin
>
> Antoine Hall wrote in message
> <9Mkc7.105408$TM5.15369395@typhoon.southeast.rr.com>...
> :Does anyone know where I can find a simple but fast search engine?
> :
> :==
> :'Toine
> :
> :
>
>
------------------------------
Date: Thu, 09 Aug 2001 03:29:30 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Perl Search Engine
Message-Id: <usnc7.1410$Fc7.133614@newsread2.prod.itd.earthlink.net>
"Antoine Hall" <AHALL5@nc.rr.com> wrote in message
news:Tgmc7.105467$TM5.15468673@typhoon.southeast.rr.com...
> Yeah, but I have a text extensive website with over 300 pages and I would
> have to search every page....would I need to build some kind of index
table
> or file?
>
> "Kevin Bartz" <l_pantin@hotmail.com> wrote in message
> news:Malc7.39176$gj1.3621911@bgtnsc05-news.ops.worldnet.att.net...
> > Try $text =~ /$word/
> >
> > It's burly and built for the job.
> >
> > Kevin
> >
> > Antoine Hall wrote in message
> > <9Mkc7.105408$TM5.15369395@typhoon.southeast.rr.com>...
> > :Does anyone know where I can find a simple but fast search engine?
The best thing I can think of on this is to build a DBM with the search
terms as keys and a list of the pages they appear in (probably join()ed with
an appropriate delimiter) as values, kinda like this:
#assume %pages is tied to your favorite DBM implementation
#keys: search terms
#values: pages containing each search term, joined by : (colon)
#also assume that @keywords contains the keywords the user is looking
for
my %hits; #keys: page names, values: the number of times each
page name matched
for(@keywords) {
for(split(/:/, $pages{$_})) {
$hits{$_}++;
}
}
my(@results); #this is the biggie--pages in order of hit "quality"
@results=sort { $hits{$a} <=> $hits{$b} || $a cmp $b } keys %hits;
#now we output @results somehow
...
The indexing program and actually putting this algorithm into use are both
left as exercises to the reader. :^) So is modifying it for regexp
matches--for that, qr// and each() will both come in handy.
It sure ain't Google, but it's something, right?
HTH,
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Wed, 08 Aug 2001 23:20:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: PERL system function and variables
Message-Id: <3B720196.BA48678D@earthlink.net>
Scott wrote:
>
> Greetings,
>
> I am trying to assign the output of the below system function-based
> command to a variable.
>
> system "ls -d /etc/lp/interface/* | grep $lprinter";
my @var = grep /$lprinter/, glob("/etc/lp/interface/*");
--
I need more taglines. This one is getting old.
------------------------------
Date: Thu, 09 Aug 2001 01:49:07 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15db97e369b6835d98971b@news.edmonton.telusplanet.net>
In article <slrn9n34mg.nit.tadmc@tadmc26.august.net>, Tad McClellan at
tadmc@augustmail.com says...
> >To be sure most responses have been absolutely
> >wonderful but a few of them have led me to be very careful in asking
> >questions on this newsgroup.
>
> Good. I imagine we'd have 700 messages a day here without
> the "curbing" that you mention :-)
True enough Tad. I guess if ones on this newsgroup aim to answer every
question (and it is indeed a great thing about this newsgroup that almost
all questions do get answered) then I see your point. The newsgroup
would indeed get flooded with newbie questions. Most of which could be
figured out with a minimum of homework. I will concentrate more than ever
on doing my homework and reading through relevant documentation.
> >Sometimes I feel like I am talking to
> >programmers who have lost touch with the realities of first coming into
> >Perl.
>
>
> This can (and does) surely happen.
> All we can do is try and recognize it, and jerk ourselves back.
> Sometimes we fail. (it is rumored that we are humans)
>
I appreciate and respect your humbleness in admitting that sometimes this
happens. Honestly I do (in case anyone thinks I am being sarcastic).
--
Carlos
www.internetsuccess.ca
------------------------------
Date: Thu, 09 Aug 2001 01:49:07 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15db9a2f74342ebe98971c@news.edmonton.telusplanet.net>
In article <997308301.595097878016531.gnarinn@hotmail.com>, gnari at
gnarinn@hotmail.com says...
> I am just wondering, do you consider perl to be a low lever language?
Not really. I guess I compared it to C in the sense that Perl can get
quite...I think the word is obsfiscated...or something like that. Where
you get these little symbols meaning all this stuff without it making
much sense to human eyes who are not familiar with the symbols. As
compared to something like Visual Basic where the code sort of explains
itself.
> C has regular expressions?
Perhaps I am not understanding Perl regular expressions or even regular
expressions for that matter. To me a regular expression has been and is
just an expression. Such as if ($string eq "Hi there") to something more
complicated such as s/^\s+/;.
C's regular expressions (i.e. just expressions) were and are easier for
me to follow than Perl's. For the time being at least.
> it is best to keep regular expression syntax totally separate in your
> mind from usual programming syntax, just like format syntax.
>
I might be mixing up regular expression syntax and usual programming
syntax. I am not sure. I guess the important point for me gnari is that
I believe without a doubt that stuff can be made much simpler so that
more and more people will want to try Perl and succeed in it. There are
a lot of people out there who are not computer scientists who could use
the benefits of this language.
--
Carlos
www.internetsuccess.ca
------------------------------
Date: Thu, 09 Aug 2001 03:56:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <x7bslpantv.fsf@home.sysarch.com>
>>>>> "CCG" == Carlos C Gonzalez <miscellaneousemail@yahoo.com> writes:
>> C has regular expressions?
CCG> Perhaps I am not understanding Perl regular expressions or even
CCG> regular expressions for that matter. To me a regular expression
CCG> has been and is just an expression. Such as if ($string eq "Hi
CCG> there") to something more complicated such as s/^\s+/;.
CCG> C's regular expressions (i.e. just expressions) were and are
CCG> easier for me to follow than Perl's. For the time being at
CCG> least.
well, you have that wrong. regular expressions are a specific class of
patterns that can match text. they have been around for many years
before perl and are in use in many programs (grep, sed, emacs, most
editors, mail filters, etc.) besides perl. in fact, the syntax of simple
regular expressions are basically the same in all cases with some
interesting differences here and there. read the book mastering regular
expressions for more on this.
now 'expressions' are a different matter and there you could compare
perl and c. in fact perl stole its basic expression grammar and many of
its operators directly from c. but perl works on higher level pieces of
data (scalars, arrays and hashes) while c works on integers/floats,
arrays and structs. so you can't compare them too carefully since they
have different ways of managing data.
>>
CCG> I might be mixing up regular expression syntax and usual
CCG> programming syntax. I am not sure. I guess the important point
CCG> for me gnari is that I believe without a doubt that stuff can be
CCG> made much simpler so that more and more people will want to try
CCG> Perl and succeed in it. There are a lot of people out there who
CCG> are not computer scientists who could use the benefits of this
CCG> language.
you are mixing them up. as i said, many programs have support for
regular expressions. once you learn basic regex stuff, you can usually
write them in most any program's dialect. you will first have to check
for the varations in that program's docs.
and as others have said, there is little chance of simplifying regular
expression grammar. it has been around for so many years and nobody has
come up with a better/simpler grammar.
now, accept that perl's regex support is tightly integrated into the
language while that is not so with most other programs and
languages. this is a big win for perl. one useful saying about perl is
that if you are not using hashes and regular expressions all the time,
you are not coding in perl.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 09 Aug 2001 02:42:27 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Redirect Script with Form Variables
Message-Id: <nMmc7.1313$Fc7.122822@newsread2.prod.itd.earthlink.net>
"Peter" <here@there.com> wrote in message
news:Yogc7.6767$pH1.55267@news1.mts.net...
> I'm looking for a redirect script that will allow me to send variables
from
> a form which a user fills in on a web page, to another URL. So the action
> line of the form would have the URL of this cgi script, and when the user
> clicks the submit button all the variables of the form are sent to the
> redirected page. The script itself does not need to read and use the
> variables, just pass them along. Anyone know where I could find such a
> script?
>
> Thanks in advance.
> Peter
Such a script is trivial to code with CGI.pm. However, it's not a normal
request, so I don't think there's a script you can just download online.
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Thu, 9 Aug 2001 14:02:56 +1000
From: "Dianne van Dulken" <dianne@dogmac.com>
Subject: replacing hex characters within a string with their ascii equivalent
Message-Id: <RXnc7.1439$813.66485@ozemail.com.au>
Hi all
I am having a bit of a problem with a querystring variable that I need to
save into a database. A typical string being passed might be:
%3Cdel_phone%3E%28020%200202%2000202%3C/del_phone%3E
and they want me to save the ascii equivalent, in this case
<del_phone>(02)20202 00202</del_phone>
I am having a little problem with converting the hex values that has been
passed to me to ascii. I can do them individually, but I am forever missing
values.
So far I have tried using:
$string2 = escapeHTML($string) <-- this is apparently a standard CGI call,
but it keeps on giving me a "cannot find main::escapeHTML error" perhaps how
I am calling it?
$string2 = pack("H*", $string) <-- gives me the entire string converted,
which looks very odd
$string =~ s/%../pack("H*", $..)/g <-- replaces the hex code with pack...
Oops!
Obviously, I am missing something pretty obvious, but I can't for the life
of me work out what it is.
I'm sorry for asking something that is probably fairly stupid. A couple of
nice people pointed me to the CGI documentation, but that seems to indicate
I should be using escapeHTML, which I couldn't get to behave.
I'd appreciate any help
Thanks a lot
Di
--
Dianne van Dulken
"I'm not sure how they fit those caps over their halos?"
-Belinda Clark about the English Women's cricket team.
------------------------------
Date: 09 Aug 2001 03:56:29 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: SQL error with s///
Message-Id: <slrn9n3gmu.6u.trammell@haqq.hypersloth.net>
On Tue, 07 Aug 2001 23:24:42 GMT, Daniel Gibby <dangby@worldnet.att.net> wrote:
> 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.
Instead of "rolling your own", how about using the DBI module's
quote() method? It will probably save you some grief...
------------------------------
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 1471
***************************************