[29614] in Perl-Users-Digest
Perl-Users Digest, Issue: 858 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 17 11:14:17 2007
Date: Mon, 17 Sep 2007 08:14:11 -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 Mon, 17 Sep 2007 Volume: 11 Number: 858
Today's topics:
Re: HTTP Filtering and Threads... <tadmc@seesig.invalid>
Re: HTTP Filtering and Threads... <ben@morrow.me.uk>
Re: Installing XS Modules on Windows -- Like Pulling Te <ben@morrow.me.uk>
Re: Latest spamware here!!!!! <army1987@NOSPAM.it>
Re: Latest spamware here!!!!! <ataru@faeroes.freeshell.org>
Re: Module::Install can't locate required modules <matteo.corti@gmail.com>
Re: Module::Install can't locate required modules <ben@morrow.me.uk>
Re: Module::Install can't locate required modules <matteo.corti@gmail.com>
Re: Newbie question: load data to array <ben@morrow.me.uk>
Perl data structure to hold same multiple keys and diff <ver_amitabh@yahoo.com>
Re: Perl data structure to hold same multiple keys and <ver_amitabh@yahoo.com>
Re: Perl data structure to hold same multiple keys and <kenslaterpa@hotmail.com>
Re: Perl data structure to hold same multiple keys and <paduille.4061.mumia.w+nospam@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Sep 2007 11:38:51 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: HTTP Filtering and Threads...
Message-Id: <slrnfespn6.utr.tadmc@tadmc30.sbcglobal.net>
Dan <danett18@yahoo.com.br> wrote:
> Hi Ben,
[ Please provide a proper attribution when you quote someone. ]
>>Don't call subs with &. It was a Perl 4 practice, and has some strange side-effects in Perl 5.
> Anw what about if someone try to run this script in a old box with
> perl 4?
Perl 4 ...
... is an ancient, dead, not-to-be-used, unsupported,
CERT-notified-security-bugridden ancient version of a language that
helped the web get its start, and sysadms get their job done faster,
but is now abandoned by anyone in the know. [1]
(and that was said 8 years ago.)
Do you worry about how your program will run under Windows 3.1 too?
[1] Message-ID: <m1u2painfh.fsf@halfdome.holdit.com>
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 17 Sep 2007 12:53:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: HTTP Filtering and Threads...
Message-Id: <sd62s4-ft1.ln1@osiris.mauzo.dyndns.org>
Quoth Dan <danett18@yahoo.com.br>:
> [Ben Morrow <ben@morrow.me.uk> wrote:]
> >
> >You are trying to parse HTML with regular expressions. This is a very
> >bad idea. I would strongly recommend using HTML::Parser, or another
> >module capable of actually parsing HTML.
>
> Hummm, thank you for the suggestion. I will look at it.
>
> Anyway, I fixed the problem, it was so dumb. To fix I just done it:
>
> my ($value) = $_ =~ /input name="$mdName" type=.* value="(.*)">/i;
>
> And all worked. My problem was:
>
> - Using two variables to recieve responses (my ($value, $name)...).
Err... this works just fine. You obviously need the same number of ()
groups as you have variables, but even if you don't the extras just get
assigned undef.
> - Use the * regex operator as you spoted. :)
Yes, but what you have above will still fail. Say your input looks like
(please excuse the overlong line, it is necessary... :) )
<input name="foo" type=one value="bar"><input name="baz" type=two value="quux">
^----------------------------------------^
and you try the match with $mdName = 'foo'. The .* after type= will
match everything from the 'o' of 'one' to the 'o' of 'two', and $value
will be set to 'quux', not 'bar'. The only reason it is working at the
moment is because (by default) . does not match a newline, so the fact
your <input>s are on separate lines is keeping them apart.
Also, and more importantly, if the structure of the input changes at all
(say, the attributes appear in a different order), the pattern won't
match at all.
> > Quoth Dan <danett18@yahoo.com.br>:
> >>
> >> (my $ruid, @userIDs) = &GetUserList($start, $end);
>
> >Don't call subs with &. It was a Perl 4 practice, and has some strange
> side-effects in Perl 5.
>
> Fixed. Thank you for tip.
>
> Anw what about if someone try to run this script in a old box with
> perl 4? It will fail without the & before call stubs?
Err... I don't know. I've never had the pleasure of using Perl 4... In
any case, there's likely to be a lot more that causes it to fail than
that: for instance, if you're using threads you will require perl 5.8.
If you really need to write Perl 4 (and you almost certainly *don't*),
you need to write Perl 4 from the beginning.
> >> [threading]
> >
> >Note that this may well not make it run faster. Unless you have 8
> >processors (lucky you ;) ), it will just make things slower.
>
> >One thing that may be slowing things down is if you are fetching and
> >parsing the same page many times. You may want to look at the Memoize
> >module as an easy way of avoiding that.
>
> Hehehe, my slow problem is not exactly related with processing power,
> but with only do one connection by each time, and it take much time to
> do all the job. So I would like to do some (6, 7, 8) connections in
> parallel, I'm sure my machine with 1 processor will not decept me in
> work just with 8 simultaneous connections. :)
Sorry, yes of course, if you're blocking on the network performing
several fetches in parallel can help. Stupid of me... :)
> >The simplest way to multi-thread the above is something like
>
> >use threads;
>
> >foreach $userID (@userIDs) {
> > async {
> > my ($name, $middlename, $lname, $bdate) =
> > GetUserData($userID);
> >
> > print "$userID\t: $name, $middlename, $lname, $bdate";
> >
> > # Some irrelevant code stuff...
> > }
> >
> >}
>
> >This will run each request in a new thread; but as you have identified,
> >the output will come out any which way.
>
> Humm... but in this example, how I define the number of threads (6, 7,
> 8) to spawn? :)
You don't... it's only a trivial example :).
> Wait, maybe I can use it. There are exist lock()/mutex() in perl?
Err... yes. See threads::shared.
> So I can do something like this:
>
> use threads;
>
> foreach $userID (@userIDs) {
> async { # I need to learn define number of threads :)
> my ($name, $middlename, $lname, $bdate) =
> GetUserData($userID);
> }
>
> lock($name);
> lock($middlename);
> lock($lname);
> lock($bdate);
>
> # Some irrelevant code stuff...
>
> print "$userID\t: $name, $middlename, $lname, $bdate";
>
> unlock($name);
> unlock($middlename);
> unlock($lname);
> unlock($bdate);
>
> # Some irrelevant code stuff...
>
> }
>
> Is it possible? Or something equivalent?
This, as written, will not work at all. Perl threads are not like C
threads: variables are *not* shared between threads by default. So the
above will fail for four reasons:
You need to 'use threads::shared', to get the lock routine; and
there is no unlock, you just let the lock fall out of scope.
$name isn't in scope at the point where you try to lock it. It only
exists inside the async block.
Even if it were (if you moved the 'my $name' outside the async {}),
the new thread gets a completely new copy of the variable. If you
want the variable shared between threads, you need to say so: again,
see threads::shared. In fact, you can't even attempt to lock a
variable that isn't shared: there'd be no point.
If the variables *were* shared, you would need to lock them inside
the async as well (otherwise you'd just be printing blank values
from before they got set); in which case (assuming you managed to
avoid deadlock) only one thread would run at once.
> In this way, I can grant the output will not be printed out of order,
(did you mean 'I cannot grant'?)
> but I can grant the value of variables will not be overwritten by
> other threads before I manipulate and print it. :)
You don't need to worry about this. Read perldoc perlthrtut, for
starters: Perl guarantees this for you, usually by giving each thread
its own copy of the variable.
You may want to try the Thread::Pool module from CPAN, which looks like
it does what you want.
> >but I have had success with PAR, which you can install from CPAN.
>
> Nice, I never had seen it before. Really good. :)
>
> I installed it via cpan, but it doesn't installed the "pp" binary used
> to convert packages.
Err... it seems that pp has been moved into the PAR-Packer dist.
> I tryed via Perl as documentation say:
>
> perl -MPAR=packed.exe other.pl
>
> But it doesn`t work. Instead of generate a packed.exe, it only execute
> my perl script (exactly as if I had called perl other.pl).
Yes, that's correct. This syntax says you want to run other.pl using the
modules inside the PAR file packed.exe (which doesn't exist, so this has
no effect).
> Well, anyway, Debian have a package (libpar-perl) with "pp"
> included. :)
>
> So I generated a executable from it:
>
> pp -o packed.exe source.pl
>
> Lol! My code in perl is around 10k and the output .exe is around
> 2.7MB, insane. hehehe
>
> Does exist any optimization option for PAR? ;)
Read the FAQ... basically, no. Everything is already zipped, and the
reason the output is so large is because there's a lot of stuff to fit
in. I strongly suspect perl2exe produces files of a similar size.
However, if you know the machine you will be deploying to has
<something>, you can ask PAR to omit <something> from the archive: for
instance, if you know your target machine will have libperl.so/
perl58.dll installed, you can reduce the size of the executable by using
pp -d.
> I belive it should had generated a executable for Windows (PE), right?
> How I define if the output is for Linux (ELF) or Windows (PE)?
You can't. pp will only generate archives for the arch it is running on,
so if you want a Win32 executable you have to create it on Win32. This
is possibly an advantage of perl2exe.
Ben
------------------------------
Date: Mon, 17 Sep 2007 11:42:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Installing XS Modules on Windows -- Like Pulling Teeth
Message-Id: <o822s4-p81.ln1@osiris.mauzo.dyndns.org>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Sun, 16 Sep 2007 15:28:30 -0000, FeelLikeANut@gmail.com wrote:
>
> >I'm running on Windows with ActivePerl, and I'm trying to install
> >XML::LibXML. It's not in the PPM repository, so that's out of the
> >question. I downloaded MinGW, so I have gcc, and I downloaded both
>
> Did you try other repositories?
>
> http://win32.perl.org/wiki/index.php?title=PPM_Repositories
Given the number of questions that come up with this answer, do you
suppose ActiveState could be persuaded to include them by default? I
guess they don't want support requests for things they cannot support...
Ben
------------------------------
Date: Mon, 17 Sep 2007 15:13:51 +0200
From: Army1987 <army1987@NOSPAM.it>
Subject: Re: Latest spamware here!!!!!
Message-Id: <pan.2007.09.17.13.10.13.467120@NOSPAM.it>
On Sat, 15 Sep 2007 12:59:10 -0700, DA Morgan wrote:
> freespamwareweb666@gmail.com wrote:
>> http://[snip]/
>
> Thank you you pathetic spammer. I don't know what we would do if
> it weren't for self-serving spammers.
And what purpose did you serve by quoting the URL, exactly?
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen
------------------------------
Date: Mon, 17 Sep 2007 14:04:00 +0000 (UTC)
From: Christopher Benson-Manica <ataru@faeroes.freeshell.org>
Subject: Re: Latest spamware here!!!!!
Message-Id: <fcm1gg$mv9$1@chessie.cirr.com>
In comp.lang.c Army1987 <army1987@nospam.it> wrote:
> On Sat, 15 Sep 2007 12:59:10 -0700, DA Morgan wrote:
> And what purpose did you serve by quoting the URL, exactly?
He didn't. Look again. (Although the fact that he insisted on
beating the dead Graveyard Groups horse is moderately unfortunate.)
--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
------------------------------
Date: Mon, 17 Sep 2007 07:09:45 -0000
From: Teo <matteo.corti@gmail.com>
Subject: Re: Module::Install can't locate required modules
Message-Id: <1190012985.160471.164610@k79g2000hse.googlegroups.com>
Hi again,
On Sep 16, 11:20 pm, Teo <matteo.co...@gmail.com> wrote:
> Hi,
>
> I just tried to write my first Makefile.PL as follows:
>
> # Load the Module::Install bundled in ./inc/
> use inc::Module::Install;
>
> # Define metadata (we read it from the script)
> name 'dprofpp_grapher';
> abstract_from 'dprofpp_grapher';
> author_from 'dprofpp_grapher';
> version_from 'dprofpp_grapher';
> license_from 'dprofpp_grapher';
>
> # Specific dependencies
> require 'Data::Dumper' => 0;
> # other requirements stripped
>
Sometimes a night of sleep and a couple of coffees can help: reading
the perlfunc man page about require and removing the quotes works like
a charm ...
Matteo
------------------------------
Date: Mon, 17 Sep 2007 11:51:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Module::Install can't locate required modules
Message-Id: <hq22s4-p81.ln1@osiris.mauzo.dyndns.org>
Quoth Teo <matteo.corti@gmail.com>:
>
> I just tried to write my first Makefile.PL as follows:
>
> # Load the Module::Install bundled in ./inc/
> use inc::Module::Install;
>
> # Define metadata (we read it from the script)
> name 'dprofpp_grapher';
If your script does anything significant (which I assume it does), it
may well be better to extract the functionality out into a module (say,
App::DProfPPGrapher, or perhaps Devel::DProf::Graph) and have a
relatively trivial script that just calls into the module.
> abstract_from 'dprofpp_grapher';
> author_from 'dprofpp_grapher';
> version_from 'dprofpp_grapher';
> license_from 'dprofpp_grapher';
This can be simplified to
all_from 'dprofpp_grapher';
which will also attempt to extract a minimum Perl version from any
use 5.006;
or such you have.
>
> # Specific dependencies
> require 'Data::Dumper' => 0;
'require' is not a M::I command, it is a Perl command. I suspect you
meant 'requires'.
Ben
------------------------------
Date: Mon, 17 Sep 2007 14:20:29 -0000
From: Teo <matteo.corti@gmail.com>
Subject: Re: Module::Install can't locate required modules
Message-Id: <1190038829.456611.299040@19g2000hsx.googlegroups.com>
Dear Ben,
On Sep 17, 12:51 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Teo <matteo.co...@gmail.com>:
> > I just tried to write my first Makefile.PL as follows:
>
> > # Load the Module::Install bundled in ./inc/
> > use inc::Module::Install;
>
> > # Define metadata (we read it from the script)
> > name 'dprofpp_grapher';
>
> If your script does anything significant (which I assume it does), it
> may well be better to extract the functionality out into a module (say,
> App::DProfPPGrapher, or perhaps Devel::DProf::Graph) and have a
> relatively trivial script that just calls into the module.
>
> > abstract_from 'dprofpp_grapher';
> > author_from 'dprofpp_grapher';
> > version_from 'dprofpp_grapher';
> > license_from 'dprofpp_grapher';
>
> This can be simplified to
>
> all_from 'dprofpp_grapher';
>
> which will also attempt to extract a minimum Perl version from any
>
> use 5.006;
>
> or such you have.
Thanks
> > # Specific dependencies
> > require 'Data::Dumper' => 0;
>
> 'require' is not a M::I command, it is a Perl command. I suspect you
> meant 'requires'.
I just figured it out (a couple of cups of coffee can be of great
help :-)
Many thanks,
Matteo
------------------------------
Date: Mon, 17 Sep 2007 11:40:10 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Newbie question: load data to array
Message-Id: <a522s4-p81.ln1@osiris.mauzo.dyndns.org>
Quoth Martijn Lievaart <m@rtij.nl.invlalid>:
> On Sun, 16 Sep 2007 15:20:30 +0000, philbo30 wrote:
>
> > I have a file with data like this:
> >
<snip>
> >
> > I want to load these values into an array called "$data". How do I make
> > this happen?
>
> open my $fh, "<", $filename or die "Cannot open $file: $!";
^^^^^^^^^ ^^^^^
One of these is not the same as the other... :)
> my @data;
> while (<$fh>) {
> push @data, $_;
> }
Huh? You're the second person who's suggested doing it like this... it's
really not necessary. Just use <> in list context:
my @data = <$fh>;
> close $fh;
If you're not going to check the return value of close there's no need
(with a lexical FH) to call it. I would generally shorten the whole
thing to
my @data = do {
open my $FH, '<', $filename
or die "cannot read '$filename': $!";
<$FH>;
};
> or use File::Slurp.
...or that, yeah :).
Ben
------------------------------
Date: Mon, 17 Sep 2007 03:38:48 -0700
From: Ami <ver_amitabh@yahoo.com>
Subject: Perl data structure to hold same multiple keys and different values
Message-Id: <1190025528.387493.55030@n39g2000hsh.googlegroups.com>
Hi All,
I am quite new to perl and need to write a script which can hold same
keys for multiple different associated values/object. Can any one help
me to find such data structure, where I can put these keys and sort
them on the keys and get the same key group to access different values/
object.
Thanks in advance for help.
-Ami
------------------------------
Date: Mon, 17 Sep 2007 03:42:35 -0700
From: Ami <ver_amitabh@yahoo.com>
Subject: Re: Perl data structure to hold same multiple keys and different values
Message-Id: <1190025755.293638.175960@57g2000hsv.googlegroups.com>
may be i am not clear with my question so once again:
I need a hash kind of data structure where I can store multiple values/
objects with same key value. I need to create a group on base of same
key. Associated values/objects will be processed on the base of groups
created.
Any help is appreciated.
Thanks
------------------------------
Date: Mon, 17 Sep 2007 04:25:48 -0700
From: kens <kenslaterpa@hotmail.com>
Subject: Re: Perl data structure to hold same multiple keys and different values
Message-Id: <1190028348.573807.45700@d55g2000hsg.googlegroups.com>
On Sep 17, 6:42 am, Ami <ver_amit...@yahoo.com> wrote:
> may be i am not clear with my question so once again:
> I need a hash kind of data structure where I can store multiple values/
> objects with same key value. I need to create a group on base of same
> key. Associated values/objects will be processed on the base of groups
> created.
> Any help is appreciated.
> Thanks
Hello. It sounds like you may want a hash of arrays. I have a simple
example below. See if this is something close to what you want.
use strict;
use warnings;
my %hashOfArrays;
foreach my $friend ( 'James', 'John', 'etc' )
{
push @{$hashOfArrays{'Ami'}}, $friend;
}
foreach my $name ( sort keys %hashOfArrays )
{
print "$name\'s friends:\n";
foreach my $friend ( @{$hashOfArrays{$name}} )
{
print " $friend\n";
}
}
Each element of the array could be a reference to an object if so
desired.
HTH, Ken
------------------------------
Date: Mon, 17 Sep 2007 08:17:46 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Perl data structure to hold same multiple keys and different values
Message-Id: <13et1caivsqai6c@corp.supernews.com>
On 09/17/2007 05:42 AM, Ami wrote:
> may be i am not clear with my question so once again:
> I need a hash kind of data structure where I can store multiple values/
> objects with same key value. I need to create a group on base of same
> key. Associated values/objects will be processed on the base of groups
> created.
> Any help is appreciated.
> Thanks
>
Read the data structures introduction:
http://perldoc.perl.org/perldsc.html
------------------------------
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 V11 Issue 858
**************************************