[24308] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6499 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 1 14:05:49 2004

Date: Sat, 1 May 2004 11:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 1 May 2004     Volume: 10 Number: 6499

Today's topics:
    Re: CGI.pm Escaping query strings - ampersand issue <pkent77tea@yahoo.com.tea>
    Re: comparing decimal numbers <dwall@fastmail.fm>
    Re: comparing decimal numbers <jurgenex@hotmail.com>
    Re: cywin versus activestate on xp <bik.mido@tiscalinet.it>
    Re: First edition of _Programming perl_, how useful is  (Randal L. Schwartz)
    Re: free source search engine (simple) ## comments? <tassilo.parseval@rwth-aachen.de>
    Re: free source search engine (simple) ## comments? <bik.mido@tiscalinet.it>
    Re: hope this is easy, passing a url as a parameter <dannywork5@hotmail.com>
    Re: hope this is easy, passing a url as a parameter <gnari@simnet.is>
    Re: How to define a sub on the fly? (Anno Siegel)
    Re: How to define a sub on the fly? <mark.clements@kcl.ac.uk>
    Re: How to define a sub on the fly? (Peter Scott)
    Re: How to define a sub on the fly? (Anno Siegel)
    Re: How to define a sub on the fly? <socyl@987jk.com>
        How to make a Perl program do concurrent downloading? <Adlene3352@hotmail.com>
    Re: Performance implications of using the Switch module (Anno Siegel)
    Re: problem with pattern match <dave.verhoeven@pandora.be>
        problem with redirect in CGI <dannywork5@hotmail.com>
    Re: problem with redirect in CGI <jds@nospantrumpetweb.co.uk>
    Re: problem with redirect in CGI <dannywork5@hotmail.com>
    Re: reducing a regex <uri@stemsystems.com>
    Re: reducing a regex (Anno Siegel)
    Re: search.pl <bik.mido@tiscalinet.it>
        Why doesn't this work? <David@Grey.con>
    Re: Why doesn't this work? <spamtrap@dot-app.org>
    Re: Why doesn't this work? <jurgenex@hotmail.com>
    Re: Why doesn't this work? <gnari@simnet.is>
    Re: Why doesn't this work? <David@Grey.con>
    Re: Why doesn't this work? <spamtrap@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 01 May 2004 14:28:14 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: CGI.pm Escaping query strings - ampersand issue
Message-Id: <pkent77tea-7B224C.14281401052004@pth-usenet-01.plus.net>

In article <2Kykc.98000$UC4.69547@bignews2.bellsouth.net>,
 "Matthew Salerno" <msalerno_rmhere_@bellsouth.net> wrote:

> I have a cgi/mod_perl script that at one point it generates url's based on
> directories:
> 
> foreach (@dirs){
>     my $lnk = qq|<A HREF="index.cgi?List=$_&TestID=$testid" TARGET="$testid"

You can't just put any old string into a query string value, or key, and 
expect it to work. Only certain characters are safe - in particular you 
noticed that & is special, because that's the thing used to separate 
key-value pairs! [There are other specials, of course, but you can read 
the RFC for them]

So, you need to url-escape $_ _before_ you whack it into a query string 
value or key. Look at the URI::Escape module.

And then, don't forget that '&' itself is a special character in HTML 
and needs to be escaped there too.

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: Sat, 01 May 2004 16:28:22 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: comparing decimal numbers
Message-Id: <Xns94DC7EE337F8Bdkwwashere@216.168.3.30>

Tad McClellan <tadmc@augustmail.com> wrote:

> Thens <thens@NOSPAMti.com> wrote:
> 
>> I have to compare two decimals numbers 1.5.0 and 2.1.1.
> 
> 
> Those are not decimal numbers...

They don't look like whole numbers, either.



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

Date: Sat, 01 May 2004 16:40:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: comparing decimal numbers
Message-Id: <MpQkc.67433$G_.56655@nwrddc02.gnilink.net>

David K. Wall wrote:
> Tad McClellan <tadmc@augustmail.com> wrote:
>
>> Thens <thens@NOSPAMti.com> wrote:
>>
>>> I have to compare two decimals numbers 1.5.0 and 2.1.1.
>>
>>
>> Those are not decimal numbers...
>
> They don't look like whole numbers, either.

"These aren't green cars. "
"They don't look like a red cars, either."

Surprise, surprise, it's a submarine.

jue
jue




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

Date: Sat, 01 May 2004 19:47:23 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: cywin versus activestate on xp
Message-Id: <9mg790p6vboo4g2dan95faibdq4sukkli7@4ax.com>

On Fri, 30 Apr 2004 13:48:20 -0000, "David K. Wall"
<dwall@fastmail.fm> wrote:

>> BTW: this is exactly what I hade done soon after installing AS
>> perl the very first time; I'm using less from UNXUTILS/UNXUPDATES,
>> which is fine. But I have some problems with some keybindings
>> (yes, not a Perl question!): e.g. I can't use PgUp, but I have to
>> use 'b' instead. Not so bad after all, but still slightly
>> annoying... 
[snip]
>Nope, PageDown and PageUp work just as you would expect for me. I 
>normally use space and 'b' anyway because that's how I learned it 
>originally, plus I don't have to move my hands as much that way.
>
>In case it helps, here's the version of less I'm using:
[snip]
>I have version 340 bundled with some GNU tools compiled for win32 and 
>it works as expected, too. Sorry.

340 here too, and *not* working as expected! (Maybe due to non-US
settings?)


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Sat, 01 May 2004 17:41:27 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: First edition of _Programming perl_, how useful is it?
Message-Id: <d8565b74647e06da7bbf50246bfa6fe3@news.teranews.com>

>>>>> "Alex" == Alex Withers <awithers@barney.gonzaga.edu> writes:

Alex> I have a first edition of _Programming perl_ and I am curious as to
Alex> how much of it is obsolete and/or irrelevant.

I had to chuckle, because I read that as "irreverent". :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 1 May 2004 17:51:08 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: free source search engine (simple) ## comments?
Message-Id: <c70h1f$gsnds$1@ID-231055.news.uni-berlin.de>

Also sprach Anno Siegel:

> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Also sprach Sherm Pendley:
>> 
>> > Robin wrote:
>> > 
>> >> btw, unless I change newsreaders which I haven't had much success with,
>> >> I've downloaded like 5 and none seem to work for me cause they don't work
>> >> with my mail server my indenting is gonna be screwed up, so please bear
>> >> with me.
>> > 
>> > You mentioned earlier about spaces and tabs getting screwed up. I've seen
>> > that happen many times - the problem is that everyone has their own idea
>> > where the "right" place to put tab stops is. Some folks put them at every 4
>> > columns, some every 8, some every 2, etc. If you use tabs in your file, and
>> > someone with different tab settings views the file, the formatting gets
>> > totally hosed.
>> > 
>> > The solution is to avoid using tabs. I'm *not* saying don't indent your
>> > code! :-) I'm just saying to use spaces to do it, instead of tabs. Most
>> > programmer's editors have an option to insert spaces when you hit the tab
>> > key, so you'll hardly notice a difference when typing.
>> 
>> Actually - and I was told about that on perl5-porters - using tabs is
> 
> Just waitaminute.  We're talking about formatting Perl, not the perl
> source.

I was under the impression that we were talking about indentation of
source code in general.

>> the right thing to do. Or at least partly, as the perl source
>> conventions are a little more complicated. The first level of
>> indentation is four spaces (no tab there). The second level would be
>> eight spaces and is then transformed into one tab. The third level would
>> then be one tab plus four spaces, and so on.
> 
> I have noticed this strange convention.  If there is a reason for it, I
> don't want to know...

Futile to seek a reason when Perl is the topic. :-)

>> Any proper editor can be told to follow this convention automatically.
>> They also have settings for setting the visual tab width so that your
>> code will looks as though there are only spaces.
> 
> I guess so.
> 
>> In the end, your editor will display these files correctly. But when you
>> look at it through a pager or so, it will look strange, depending on how
>> many spaces it uses per tab (I have an alias which maps 'less' to
>> 'less -x4 -r' which would be four spaces per tab).
> 
> Well, that's fine when the source requires that format, as the Perl source
> seems to do.  But you're not recommending it for new sources (C, Perl
> or otherwise), are you?

Not necessarily, right. My main point was just that the principle of tab
avoiding is maybe not as common among projects as it seems.
Incidentally, I had thought the perl source used spaces instead of tabs
(I had never looked that closely) until someone pointed out to me that
the whitespacing in one of my patches was slightly off.

> Tabs where introduced with mechanical typewriters to save typing time.
> In a programming environment they have the additional advantage of saving
> space, so early programmers adopted them eagerly.  But they never worked
> really well, because every bit of hard- or software has its own ideas of
> what a tab really means.
> 
> These days, editors do the time-saving, and byte-counting has ceased
> to be profitable.  Tabs might have been useful with more standardization, 
> but they aren't now.

So when tabs are still used in perl nowadays, this probably means it is
a left-over from those times when tabbing was still an issue. So this
convention probably remains only for the sake of uniformity.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 01 May 2004 19:47:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: free source search engine (simple) ## comments?
Message-Id: <e5n790h5uan4p0jb0pfe6of38itqg85ltu@4ax.com>

On Fri, 30 Apr 2004 12:23:17 -0800, "Robin" <webmaster @ infusedlight
 . net> wrote:

>This is a very a simple search engine that prints the filenames of the files
>and a link to them, it's not very advanced but I used it as an excersise
>into writing search engines, and I'm planning on making it into a more
>advanced one in the future I am aware of the race conditions in the header
>and footer subs and their suckiness and am working now to fix them, I got
>some advice from someone on the perl beginners yahoo list, but to work their
>code I have to understand it and I don't so once I read up I'll fix the race
>condition, anyway, any comments would be nice.

Dear Robin,


I *do* have a comment: is there any good reason why you continue to
post to this group whole projects of yours, occasionally claiming to
make them available publicly, whereas (i) you've been repeatedly been
warned about several different issues with both the code proper and
this "activity", (ii) even if this may come as a surprise to you,
there are people here who could carry on equivalent projects in a much
more reliable/secure/etc. way (and indeed someone who does that on a
professional basis) *and* they do *not* post here tons of code for
review?

Personally I think that there's nothing wrong with being proud about
our own little successes and new learnings. But this group, for one
thing, is about *Perl*, not about web development. (Even if using
Perl!)

BTW: are you aware that perl is not a CGI-only thing?!?

This group is for discussions about Perl: OTs and asides are welcome
to some extent, but there are precise directions not too waste too
much bandwidth not to say people's own time that are just at the same
time quite *reasonable* behavioural rules, that comprise, for example
the request to post only minimal examples, to the extent that this is
possible.

Now what would happen if 5 other Robin's popped out each posting
his/her own new bbs (crappy) code, guestbook (crappy) code, blog
(crappy) code, search engine (crappy) code, (crappy) review of some
product/book, etc.?!?

As I said, there's nothing wrong *IMHO* with, say, sharing some piece
of code and asking for comments; just as a somewhat self-referential
example see this old post of mine:
<news:d96i5vsbvu01vhvqs5qa6i22tev11q21i2@4ax.com>.

>btw, unless I change newsreaders which I haven't had much success with, I've
                      ^^^^^^^^^^^
>downloaded like 5 and none seem to work for me cause they don't work with my
>mail server my indenting is gonna be screwed up, so please bear with me.
 ^^^^^^^^^^^

Unless you *do* want to use your newsreader also as a mail client,
which is not unreasonable, but may also not be fundamental for you,
being it unable to "work with your mail server" (*which* mail server,
BTW?) shouldn't make it impossible to use it for reading and writing
usenet articles...

Also, sorry for the intended sarcasm, but isn't it strange that a
self-declared (not Perl but) "win32 expert" can't properly setup at
least one out of *five* different newsreaders?!?


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Sat, 01 May 2004 10:13:41 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: Re: hope this is easy, passing a url as a parameter
Message-Id: <pLKkc.67740$Gd3.16862998@news4.srv.hcvlny.cv.net>


"Gregory Toomey" <nospam@bigpond.com> wrote in message
news:1513682.d3x1Bjo0rK@GMT-hosting-and-pickle-farming...
> Danny wrote:
>
> >
> > "John Bokma" <postmaster@castleamber.com> wrote in message
> > news:40931fc8$0$198$58c7af7e@news.kabelfoon.nl...
> >> Danny wrote:
> >> > I am trying to pass a parameter to a cgi script,  it is a URL that
has
> > its
> >> > own call to a cgi script with ? in statement.
> >> > for example
> >> >
> >> > so my cgi (load.cgi) is getting confused because of the extra ? in
the
> >> > statement.
> >> > my cgi redirects to the passed url
> >> >
> >> > I call it like this:
> >> >
> > www.domain.com/cgi-bin/load.cgi?url=http://www.anotherdomain.com/cgi-bin
> pro
> >> > ducts.cgi?search=volvo
> >>
> >> Encode the URL, this is wrong.
> >>
> >> --
> >> John                               MexIT: http://johnbokma.com/mexit/
> >>                             personal page:       http://johnbokma.com/
> >>     Experienced Perl programmer available:     http://castleamber.com/
> >
> > Thanks
> >
> > How can I encode the URL.?
>
> Its a faq.
>
> http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html
> How do I decode or create those %-encodings on the web?
>
>
> But its better to use the cgi.pm module
>
> gtoomey

Thanks

I will fix this:

but an initial call with this long url is always made from my index.html,
how can I encode a URL in an HTML page?

Thanks again




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

Date: Sat, 1 May 2004 10:29:12 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: hope this is easy, passing a url as a parameter
Message-Id: <c6vu33$f0m$1@news.simnet.is>

"Danny" <dannywork5@hotmail.com> wrote in message
news:pLKkc.67740$Gd3.16862998@news4.srv.hcvlny.cv.net...
>
> "Gregory Toomey" <nospam@bigpond.com> wrote in message
> news:1513682.d3x1Bjo0rK@GMT-hosting-and-pickle-farming...
> > Danny wrote:
> >
> >
> > Its a faq.
> >
> > http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html
> > How do I decode or create those %-encodings on the web?
> >
> >
> > But its better to use the cgi.pm module
> >
>
> Thanks
>
> but an initial call with this long url is always made from my index.html,
> how can I encode a URL in an HTML page?

thats where the FAQ code can be handy.
just make a short script that encodes our urls, and
paste them into your html.
or have your whole html file generated by this script.
or just use a oneliner:
  perl -ple '$_="text to encode";s/([^\w()\'*~!.-])/sprintf "%%%02x", ord
$1/eg'

gnari






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

Date: 1 May 2004 10:56:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to define a sub on the fly?
Message-Id: <c6vvo5$2au$2@mamenchi.zrz.TU-Berlin.DE>

Mark Clements  <mark.clements@kcl.ac.uk> wrote in comp.lang.perl.misc:
> Walter Roberson wrote:
> > In article <c6uipi$inb$1@reader2.panix.com>, kj  <socyl@987jk.com> wrote:
> > :Can someone please show me how to define a sub Foo::Bar::baz on
> > :the fly (i.e. when the module is loaded)?
> > 
> > Try constructing it inside a BEGIN block. BEGIN blocks are executed
> > as the module is loaded.
> Sidestepping the rest of the thread (ie the validity of doing this), you 
> can use the autoloader and/or eval. Creation of subs (or any code on the 
> fly) can be done with eval $definition.

 ...it can, granted, but there's no real need for "eval".

> eg
> eval<<EOF;
> 	sub newsub(){

Why the prototype?  They are the exception with sub definitions, not
the rule.

> 		return "from newsub";
> 	};
> EOF

    *newsub = sub { return "from newsub" };

has the same effect, but is clearer and simpler.

Anno



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

Date: Sat, 01 May 2004 12:21:15 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: How to define a sub on the fly?
Message-Id: <4093882c$1@news.kcl.ac.uk>

Anno Siegel wrote:

>>eval<<EOF;
>>	sub newsub(){
> 
> 
> Why the prototype?  They are the exception with sub definitions, not
> the rule.
I tend to use them because if used correctly they enable the compiler to 
catch attempts to call subs with the wrong number of arguments, though 
obviously here they'll have no effect as the compiler can't see the 
definition of the new sub. It was therefore misleading of me to use it here.


> 
>     *newsub = sub { return "from newsub" };
In this case, yes, but I don't see how this enables you to build 
subroutines on the fly. eval STRING is relatively inefficient but 
extremely powerful (and therefore dangerous).

Mark


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

Date: Sat, 01 May 2004 12:19:47 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: How to define a sub on the fly?
Message-Id: <DBMkc.331294$oR5.11345@pd7tw3no>

In article <4093882c$1@news.kcl.ac.uk>,
 Mark Clements <mark.clements@kcl.ac.uk> writes:
>Anno Siegel wrote:

>>     *newsub = sub { return "from newsub" };
>In this case, yes, but I don't see how this enables you to build 
>subroutines on the fly.

Closures.

{
  my $thing = "foo";
  my $method = "${thing}_method";
  no strict 'refs';
  *$method = sub { ... do something with $thing ... };
}

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: 1 May 2004 12:40:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to define a sub on the fly?
Message-Id: <c705ra$614$1@mamenchi.zrz.TU-Berlin.DE>

Mark Clements  <mark.clements@kcl.ac.uk> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> >>eval<<EOF;
> >>	sub newsub(){
> > 
> > 
> > Why the prototype?  They are the exception with sub definitions, not
> > the rule.
> I tend to use them because if used correctly they enable the compiler to 
> catch attempts to call subs with the wrong number of arguments,

True, but it also makes your subs behave weirdly, supplying unexpected
context to arguments or even silently taking references.  In my view,
prototypes can (sparingly) be used in interface-type functions to
help the user deal with them, or to allow suggestive syntax.  The
non-standard behavior must be clearly documented.  Few Perl programmers
use prototypes routinely with all subs.

>                                                                 though 
> obviously here they'll have no effect as the compiler can't see the 
> definition of the new sub. It was therefore misleading of me to use it here.
> 
> 
> > 
> >     *newsub = sub { return "from newsub" };
> In this case, yes, but I don't see how this enables you to build 
> subroutines on the fly. eval STRING is relatively inefficient but 
> extremely powerful (and therefore dangerous).

If you actually need to compile a string of code for the new sub, there
is no way around "eval".

Often a closure gives enough flexibility.  If the sub needs to read a
particular file, this would do (simplified, untested):

    sub create_sub {
        my $name = shift;
        my $sub = sub {
            open( my $f, $name) or die "Can't read file '$name': $!";
            # ...
        };
        no strict 'refs';
        *{ 'read_' . $name} = $sub;
    }

That creates one named closure per call, each reading the file it is
named after.  No need for "eval" here.

Anno


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

Date: Sat, 1 May 2004 12:57:31 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Re: How to define a sub on the fly?
Message-Id: <c706rr$2rs$1@reader2.panix.com>

In <x73c6l3t27.fsf@mail.sysarch.com> Uri Guttman <uri@stemsystems.com> writes:

>>>>>> "WR" == Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> writes:

>  WR> In article <c6uipi$inb$1@reader2.panix.com>, kj  <socyl@987jk.com> wrote:
>  WR> :Can someone please show me how to define a sub Foo::Bar::baz on
>  WR> :the fly (i.e. when the module is loaded)?

>  WR> Try constructing it inside a BEGIN block. BEGIN blocks are executed
>  WR> as the module is loaded.

>that won't help much. the module itself is executed at compile time when
>it is loaded by the use statement so the BEGIN block gains little there.

>but i would ask the OP what they mean by creating a sub on the fly and
>why does he think it is needed? it isn't hard to do but i won't help if
>it is not even needed.

The framework I was referring to is a Web services one, in which
clients discover and call a server's available services at runtime.
(I should add that this framework is horribly designed, and even
worse implemented--all out of my hands.)  As it turns out, at our
site the menu of services that fit this model is one that is
dynamically changing (the sources of available data, each corresponding
to a different data file, will change from one day to the next,
both in number and in content).  In this case, clients "discover"
desired services typically by requesting desired input and output
signatures.  The input signature for all these possible services
has no room for a filename, or any other parameter that could be
used to select among all the services provided at our site at any
given time.  Likewise, the service dispatching protocol (which I
don't control) matches service names to methods in a 1-to-1 way
(in fact the service names are expected to be identical to the
names of the corresponding methods that the dispatcher calls).  I
don't see any way to match this API other than by providing separate
methods for each data source file available at our site on a given
day, even if these methods all end up calling the same core method
with an additional argument (the source file to use).  (The
meta-service that describes all the services available at our site
to interested clients would also need to determine these methods
dynamically.)

kj
-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: Sat, 1 May 2004 19:16:42 +0800
From: "Adlene" <Adlene3352@hotmail.com>
Subject: How to make a Perl program do concurrent downloading?
Message-Id: <c6vvmn$ck4$1@mawar.singnet.com.sg>

Hi, there:

I wrote a program to download 500,000 HTML files from a website, I
have compiled all the links in a file. my grabber.pl will download all of
them...

I have a fast internet connection. I think it is better to run multiple
downloads at
same time, but $INET = new Win32::Internet() only allows one at a
time...what
may I do?

I also found, occassionally the grabber just hang somewhere...In such
situation I
need to bypass $INET->FetchURL($url), write the offending URL in an error
file
and continue on to next iteration...How may I do that?

Best Regards,
Adlene





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

Date: 1 May 2004 12:09:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Performance implications of using the Switch module
Message-Id: <c7040u$53s$1@mamenchi.zrz.TU-Berlin.DE>

GreenLight <google@milbaugh.com> wrote in comp.lang.perl.misc:
> I hate looking at rows and rows of elsif statements as much as the
> next person, but using the Switch module just doesn't cut it. I wrote:
> 
> use strict;
> use warnings;
> use Benchmark;
> use Switch;
> 
> sub use_if() {
> 	my ($tag, $value);
> 	my @parsed;
> 	my @tags = (
> 			"TAG001^VALUE001", "TAG002^VALUE002", "TAG003^VALUE003",
> "TAG004^VALUE004", "TAG005^VALUE005",
> 			"TAG006^VALUE006", "TAG007^VALUE007", "TAG008^VALUE008",
> "TAG009^VALUE009", "TAG010^VALUE010"
> 		);
> 	foreach my $next (@tags) {
> 		($tag, $value) = ($next =~ /^(.*?)\^(.*?)$/);
> 		
> 		if ($tag eq 'TAG001') { push @parsed, $value }
> 		elsif ($tag eq 'TAG002') { push @parsed, $value }
> 		elsif ($tag eq 'TAG003') { push @parsed, $value }
> 		elsif ($tag eq 'TAG004') { push @parsed, $value }
> 		elsif ($tag eq 'TAG005') { push @parsed, $value }
> 		elsif ($tag eq 'TAG006') { push @parsed, $value }
> 		elsif ($tag eq 'TAG007') { push @parsed, $value }
> 		elsif ($tag eq 'TAG008') { push @parsed, $value }
> 		elsif ($tag eq 'TAG009') { push @parsed, $value }
> 		elsif ($tag eq 'TAG010') { push @parsed, $value }
> 		else { die "Bad tag!" }
> 	}
> }
> 
> sub use_switch() {
> 	my ($tag, $value);
> 	my @parsed;
> 	my @tags = (
> 			"TAG001^VALUE001", "TAG002^VALUE002", "TAG003^VALUE003",
> "TAG004^VALUE004", "TAG005^VALUE005",
> 			"TAG006^VALUE006", "TAG007^VALUE007", "TAG008^VALUE008",
> "TAG009^VALUE009", "TAG010^VALUE010"
> 		);
> 	foreach my $next (@tags) {
> 		($tag, $value) = ($next =~ /^(.*?)\^(.*?)$/);
> 		
> 		switch ($tag) {
> 			case "TAG001" { push @parsed, $value }
> 			case "TAG002" { push @parsed, $value }
> 			case "TAG003" { push @parsed, $value }
> 			case "TAG004" { push @parsed, $value }
> 			case "TAG005" { push @parsed, $value }
> 			case "TAG006" { push @parsed, $value }
> 			case "TAG007" { push @parsed, $value }
> 			case "TAG008" { push @parsed, $value }
> 			case "TAG009" { push @parsed, $value }
> 			case "TAG010" { push @parsed, $value }
> 			else { die "Bad tag!" }
> 		}
> 	}
> }
> 
> timethese (100000, {
> 		"Using 'if'" => \&use_if,
> 		"Using 'switch'" => \&use_switch
> 	});
> 
> __END__
> 
> These subroutines adequately represent tasks performed thousands of
> times per day at my client's site.

These only perform a single push as "payload" of the decision.  Is that
a realistic representation of the program?

> And the results:
> 
> Benchmark: timing 100000 iterations of Using 'if', Using 'switch'...
> Using 'if': 17 wallclock secs (16.48 usr +  0.00 sys = 16.48 CPU) @
> 6066.49/s (n=100000)
> Using 'switch': 153 wallclock secs (150.68 usr +  0.00 sys = 150.68
> CPU) @ 663.68/s (n=100000)
> 
> Using "switch" was nearly an order of magnitude slower.

Appalling, isn't it?  And yet, the result is misleading.

You say that these routines are performed thousands of times per day.
Let's be generous and say they're called 10_000 times.  Your benchmark
has called them 100_000 times and lost about 150 seconds through the
use of "switch" (which over-estimates the loss, counting *all* of the
consumed time as overhead).  So on 10_000 calls per day you waste a
total of 15 cpu-seconds, out of 24*60*60 = 86400 that are available.
Reason for concern?  I think not.

Also, if you put a more realistic payload in the benchmarks, the result
is less dramatic.  Assume the equivalent of "1 for 1 .. 10_000" instead
of a single "push".  (My machine can run that 300 times per second,
so a few thousand times per day would still amount to very little.)
According to my benchmarks, this reduces the advantage of "if" over
"switch" to 7%.  Again, no reason for much concern.

I, too, would like to see a light-weight switch statement, comparable
in execution speed to "if", but in many cases the Switch module will
still be adequate.  If it isn't, there are a lot of ad-hoc alternatives
in Perl.  Some of them, like dispatch tables, are blindingly fast where
applicable.  Your branching on fixed strings looks like an invitation
to use a dispatch table.

Anno


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

Date: Sat, 01 May 2004 10:26:03 GMT
From: "Dafke8" <dave.verhoeven@pandora.be>
Subject: Re: problem with pattern match
Message-Id: <%WKkc.835$7R2.87493031@hestia.telenet-ops.be>

> There are, unfortunately, several problems:
> 1) You're reassigning the value of @test each time through the loop,
> rather than pushing new values onto it.
> 2) You're reassigning the value of @test *every* time through the loop,
> regardless of whether the pattern match succeeded.
> 3) You're using a global pattern match but only (theoretically) storing
> one of the possible matches, rather than all of them.
> 4) You're only looking for the whole pattern on each line, ignoring the
> possibility that the pattern could span multiple lines of your input.
> 5) And finally, you're using regular expressions to parse HTML, rather
> than one of the several HTML Parsing modules available on CPAN.
>
> Paul Lalli

Thank you all for your help, I'm not so long working with perl. Because of
that it's all quit new for me and i'm learning every day more and more.

Tnx,

Dave





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

Date: Sat, 01 May 2004 15:01:18 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: problem with redirect in CGI
Message-Id: <2ZOkc.72235$Gd3.17629354@news4.srv.hcvlny.cv.net>

WE are using the redirect command in the code below, I am trying to test.
we are trying to post our products on the shopping sites, like shopping.com,
froogle, nextag etc etc.
But when we use this url as you see below as the product_url, it gives an
error.  But if you copy and paste it into the url it will work.  ODD.  So I
tried to do a redirect from my cgi directory and use this cgi script as the
product url for these sites.  But it does not work.
How can I some how make it go to my website and act as if the product_url is
being called  from my website

PS. the url works in some sites like froogle.
the error comes from our product.cgi saying "cannot create session"
I know the problem in there, but how can we make this work?

here is code that does not work.
(works for static html of course)
#!/usr/bin/perl

$theurl1 =
"http://www.domain.com/product.cgi?productid=455&department=23333";
use CGI;
use CGI::Carp qw(fatalsToBrowser); # to display warnings and errors on the
browser

$co = new CGI;


print $co->redirect(-url => $theurl1); # redirect to my page




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

Date: Sat, 1 May 2004 16:49:18 +0100
From: "Julia deSilva" <jds@nospantrumpetweb.co.uk>
Subject: Re: problem with redirect in CGI
Message-Id: <1CPkc.5800$by6.3121@pathologist.blueyonder.net>

> #!/usr/bin/perl
>
> $theurl1 =
> "http://www.domain.com/product.cgi?productid=455&department=23333";
> use CGI;
> use CGI::Carp qw(fatalsToBrowser); # to display warnings and errors on the
> browser
>
> $co = new CGI;
>
>
> print $co->redirect(-url => $theurl1); # redirect to my page
>


Posting code like that could get you into serious trouble here, but I'll say
no more.

try:

print $co-> redirect($theurl1);




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

Date: Sat, 01 May 2004 16:51:26 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: Re: problem with redirect in CGI
Message-Id: <iAQkc.73486$Gd3.17945236@news4.srv.hcvlny.cv.net>


"Julia deSilva" <jds@nospantrumpetweb.co.uk> wrote in message
news:1CPkc.5800$by6.3121@pathologist.blueyonder.net...
> > #!/usr/bin/perl
> >
> > $theurl1 =
> > "http://www.domain.com/product.cgi?productid=455&department=23333";
> > use CGI;
> > use CGI::Carp qw(fatalsToBrowser); # to display warnings and errors on
the
> > browser
> >
> > $co = new CGI;
> >
> >
> > print $co->redirect(-url => $theurl1); # redirect to my page
> >
>
>
> Posting code like that could get you into serious trouble here, but I'll
say
> no more.
>
> try:
>
> print $co-> redirect($theurl1);
>
>

Thakns for helping.
This did not work.
Can I do one redirect that goes to a static html page on my server and then
do another redirect from same cgi script that goes to this URL?

Thanks again




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

Date: Sat, 01 May 2004 14:50:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: reducing a regex
Message-Id: <x7pt9o19rx.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  >> > I am trying to figure out how to reduce or simplify the following:
  >> >
  >> /\+:\s+(\w+)\s+:\s+(\w+)\s+(\w+)\s+(\w+)\s+:\s+(\d)-(\d+)-(\d+)\s+:\s+=\s+(\
  >> > d+)\s+(\w+)\s+(\w+)\s+\[\s+(-?\d+.\d+),\s+(-?\d+.\d+)/;

  AS> You forgot to quote the two periods towards the end of the regex.  They
  AS> would match nay character.

  AS>    my @matches =  /([\w.]+)/g;

  AS> extracts the same fields.  If it does what you want, I don't know.

not exactly. he has some grabbed numbers with optional leading - signs
and [\w+.] won't grab them. so [\w.-]+ could work. but we both don't
know the real spec so we can't be sure. i wonder if he really wants to
grab all those things and if they are needed to actually match the
string. me thinks the OP just thinks you have to match each part in
detail.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 1 May 2004 17:32:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: reducing a regex
Message-Id: <c70mva$ejd$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
>   >> > I am trying to figure out how to reduce or simplify the following:
>   >> >
>   >>
> /\+:\s+(\w+)\s+:\s+(\w+)\s+(\w+)\s+(\w+)\s+:\s+(\d)-(\d+)-(\d+)\s+:\s+=\s+(\
>   >> > d+)\s+(\w+)\s+(\w+)\s+\[\s+(-?\d+.\d+),\s+(-?\d+.\d+)/;
> 
>   AS> You forgot to quote the two periods towards the end of the regex.  They
>   AS> would match nay character.
> 
>   AS>    my @matches =  /([\w.]+)/g;
> 
>   AS> extracts the same fields.  If it does what you want, I don't know.
> 
> not exactly. he has some grabbed numbers with optional leading - signs
> and [\w+.] won't grab them.

Oh, right.  I didn't see them in the monster regex.

>                             so [\w.-]+ could work. but we both don't
> know the real spec so we can't be sure. i wonder if he really wants to
> grab all those things and if they are needed to actually match the
> string. me thinks the OP just thinks you have to match each part in
> detail.

That's the point I was hoping to make by giving a pointedly unspecific
regex.  It doesn't hurt the point much that it is a little too unspecific.

Anno


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

Date: Sat, 01 May 2004 13:38:46 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: search.pl
Message-Id: <tlh5909a08gh2c9ahf4k1frh331ifl7p8k@4ax.com>

On Fri, 30 Apr 2004 09:56:40 -0800, "Robin" <webmaster @ infusedlight
 . net> wrote:

>>     use File::Find;
           ^^^^^^^^^^
[snip]
>yeah, I was thinking that exact same thing. I'll check out file::find.
                                                            ^^^^^^^^^^


Michele

-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Sat, 01 May 2004 14:24:48 GMT
From: David Grey <David@Grey.con>
Subject: Why doesn't this work?
Message-Id: <4093AD2A.CFD2E1BD@Grey.con>

#!/usr/bin/perl

use File::Copy;

$tempfile = "http://www.domain.com/temp.txt";
copy($tempfile,"temp2.txt");


How would you call a file from another server?





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

Date: Sat, 01 May 2004 10:31:51 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Why doesn't this work?
Message-Id: <Zuidne7nKK1KKQ7dRVn-vw@adelphia.com>

David Grey wrote:

> #!/usr/bin/perl
> 
> use File::Copy;
> 
> $tempfile = "http://www.domain.com/temp.txt";
> copy($tempfile,"temp2.txt");
> 
> 
> How would you call a file from another server?

Perl's built-in copy() function only works for local files. To read a file
from a URL, see the LWP or WWW::Mechanize modules on CPAN.

sherm--


-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Sat, 01 May 2004 15:04:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Why doesn't this work?
Message-Id: <Q%Okc.67381$G_.65@nwrddc02.gnilink.net>

David Grey wrote:
> #!/usr/bin/perl
>
> use File::Copy;
>
> $tempfile = "http://www.domain.com/temp.txt";
> copy($tempfile,"temp2.txt");

It doesn't work because copy() copies files and
http://www.domain.com/temp.txt is not a file but a URL (which may or may not
resolve into a file on the server side but the client wouldn't know anything
about that).

> How would you call a file from another server?

_Another_ server? Well, whatever.
To download the reply to an http request you would use e.g. the LWP module.

jue




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

Date: Sat, 1 May 2004 14:39:12 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Why doesn't this work?
Message-Id: <c70cnp$gkb$1@news.simnet.is>

"David Grey" <David@Grey.con> wrote in message
news:4093AD2A.CFD2E1BD@Grey.con...
> #!/usr/bin/perl
>
> use File::Copy;
>
> $tempfile = "http://www.domain.com/temp.txt";
> copy($tempfile,"temp2.txt");
>
>
> How would you call a file from another server?

take a look at the LWP modules

gnari






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

Date: Sat, 01 May 2004 16:37:48 GMT
From: David Grey <David@Grey.con>
Subject: Re: Why doesn't this work?
Message-Id: <4093CC56.4B2E843C@Grey.con>



Jürgen Exner wrote:

> David Grey wrote:
> > #!/usr/bin/perl
> >
> > use File::Copy;
> >
> > $tempfile = "http://www.domain.com/temp.txt";
> > copy($tempfile,"temp2.txt");
>
> It doesn't work because copy() copies files and
> http://www.domain.com/temp.txt is not a file but a URL (which may or may not
> resolve into a file on the server side but the client wouldn't know anything
> about that).
>
> > How would you call a file from another server?
>
> _Another_ server? Well, whatever.
> To download the reply to an http request you would use e.g. the LWP module.
>
> jue


Thanks, I found this after going to a bunch of pages in google that
were asking how to use it and finally came across the form:

# Create a user agent object
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');

# Pass request to the user agent and get a response back
my $res = $ua->request($req);

http://www.perldoc.com/perl5.8.0/lib/LWP.html

I don't think I would want to POST I think I would want to GET,
and then it did not have any copy examples. Can someone give
me a hint on this as well? I assume the  use File::Copy;  will not
work as pointed out.

Thanks.







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

Date: Sat, 01 May 2004 12:48:08 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Why doesn't this work?
Message-Id: <L7ednSpz0_VVSQ7d4p2dnA@adelphia.com>

David Grey wrote:

> Thanks, I found this after going to a bunch of pages in google that
> were asking how to use it

Google is nice, but did you try looking on your own computer?

perldoc LWP
perldoc LWP::Simple
perldoc lwpcook

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

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 6499
***************************************


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