Home > Archive > PERL Beginners > September 2007 > HTTP Filtering and Threads...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
HTTP Filtering and Threads...
|
|
|
| Hi,
That's my first program and my first question in perl programming..
lolll! Any kind of help is appreciated. :)
1) I have a code in perl which is doing a HTTP request and getting a
response and saving in a variable, so I want to filter a specific
value of a field. My code is more or less like this one:
next unless /^<input name/i;
my ($name, $value) = $_ =~ /input name="(.*)Name" type=.*
value="(.*)">/i;
if ((length($value)) > 1){
$MiddleName = $value;
#Some Stuff Code...
print "$MiddleName";<br><br>
}
However the HTTP request return a HTML code that is more or less like
this:
#Some non relevante HTML stuff...
<input name="$mdName" type="hidden" value="Silva">
#Some non relevante HTML stuff...
<input name="Name" type="hidden" value="Silva">
<input name="mdName" type="hidden" value="Daniel">
#Some non relevante HTML stuff...<code>
The problem is that my code is getting the value of "mdName" which is
"Daniel" and I want it get the value of "$mdName" which is "Silva" and
if it is missing (blank) I want to get the value of "Name" which in
the example also is "Silva". But I never want to get the value of
"mdName" which is "Daniel" and is what always is happening. :(
Obs.: I also tried (without sucess) use:
* my ($name, $value) = $_ =~ input name="\"\$mdName\" type=.*
value="(.*)">/i;
* my ($name, $value) = $_ =~ m/input name=\"\$mdName\" type=.*
value="(.*)">/i;
* my ($name, $value) = $_ =~ input name="\/$mdName\/" type=.*
value="(.*)">/i;
* my ($name, $value) = $_ =~ m/input name="\/$mdName\/" type=.*
value="(.*)">/i;
Someone can give me a snippet of code of how to fix it? :)
2) In the some program I have a piece of code which list all users and
do a loop for call the function which will get detailed information of
each user (the code in question 1 is part of this function). The
snippet is like this one:
# Some irrelevant code stuff...
(my $ruid, @userIDs) = &GetUserList($start, $end);
if ($userIDs[0] == -1) { exit(0); }
foreach $userID (@userIDs) {
&GetUserData($name, $middlename, $lname, $bdate);
print "$userID\t: $name, $middlename, $lname, $bdate";
# Some irrelevant code stuff...
}
# Some irrelevant code stuff...
The function GetUserData() is really slow, it do HTTP Request, parse
some HTML stuff and the amount of users is big. So I would like to add
thread support to it, in a fashion that I could have for example 8
instances of this code running in paralel. :)
I had looked at http://perldoc.perl.org/threads.html, but it doesn't
helped so much. I belive I should add the thread support in a fashion
that it work directly with the foreach loop instruction and
GetUserData(), right?
However I want to take care to doesn't overwrite data (in C when we
deal with threads we have some unsafe functions that can overwrite
values - which is not good)... also take care that each print will be
in the correct sequence...
Can someone give me a snippet of code based in mine for that? I know
that read documentation is better, but documentation doesn't helped
much, I appreciate practical examples...
3) The Perl2exe (http://www.indigostar.com/perl2exe.htm) is the best
option to convert Perl code to Executables? It really work well? Even
with complicated and sophisticated code (using thread, raw sockets,
windows registry access, etc)?
Well, that's my first code in perl, so sorry for ugly/bad code (and
also I'm not a programmer, just a curious:). hehe
Thank you and sorry for amount (of dumb and off-topic) questions.
Cheers,
| |
|
| you can store all the data in an array first and then apply regex on
all lines, if the response come in lines. Else, get all the data in a
scalar and apply the regex. I think this may get you the silva
my ($name,$type,$mname) =~ /name=(.*) type=(.*) value=(.*)/i;
i'm not sure though how we may capture all the occurences.
| |
| Mumia W. 2007-09-15, 7:00 pm |
| I keep getting copies of the message below. I've gotten perhaps 10
copies of it over the last 24 hours.
It continues even though I unsubscribed.
> Return-Path: <beginners-return-95362-mumia.w.18.spam+nospam=earthlink.net@perl.org>
> Received: from noehlo.host ([127.0.0.1])
> by mx-various.atl.sa.earthlink.net (EarthLink SMTP Server) with SMTP id 1iwu3yn83Nl36J2; Sat, 15 Sep 2007 05:35:16 -0400 (EDT)
> Received: from lists.develooper.com ([63.251.223.186])
> by mx-various.atl.sa.earthlink.net (EarthLink SMTP Server) with SMTP id 1iwu3y2vH3Nl36J0
> for <mumia.w.18.spam@earthlink.net>; Sat, 15 Sep 2007 05:35:16 -0400 (EDT)
> Received: (qmail 11633 invoked by uid 514); 15 Sep 2007 09:35:14 -0000
> Mailing-List: contact beginners-help@perl.org; run by ezmlm
> Precedence: bulk
> List-Post: <mailto:beginners@perl.org>
> List-Help: <mailto:beginners-help@perl.org>
> List-Unsubscribe: <mailto:beginners-unsubscribe@perl.org>
> List-Subscribe: <mailto:beginners-subscribe@perl.org>
> List-Id: <beginners.perl.org>
> Delivered-To: mailing list beginners@perl.org
> Received: (qmail 11617 invoked from network); 15 Sep 2007 09:35:13 -0000
> Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111)
> by lists.develooper.com with SMTP; 15 Sep 2007 09:35:13 -0000
> Received: (qmail 26300 invoked by uid 225); 15 Sep 2007 09:35:13 -0000
> Delivered-To: beginners@perl.org
> Received: (qmail 26293 invoked by alias); 15 Sep 2007 09:35:12 -0000
> X-Spam-Status: No, hits=-2.6 required=8.0
> tests=BAYES_00,SPF_PASS
> X-Spam-Check-By: la.mx.develooper.com
> Received: from wx-out-0506.google.com (HELO wx-out-0506.google.com) (66.249.82.239)
> by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Sat, 15 Sep 2007 02:30:49 -0700
> Received: by wx-out-0506.google.com with SMTP id t11so1077113wxc
> for <beginners@perl.org>; Sat, 15 Sep 2007 02:30:08 -0700 (PDT)
> Received: by 10.90.29.18 with SMTP id c18mr489842agc.1189806328174;
> Fri, 14 Sep 2007 14:45:28 -0700 (PDT)
> Received: by 10.90.119.11 with HTTP; Fri, 14 Sep 2007 14:45:28 -0700 (PDT)
> Message-ID: < e9a6a7e60709141445j6c508cbflac487b2301c6
cecc@mail.gmail.com>
> Date: Sat, 15 Sep 2007 03:15:28 +0530
> From: Somu <som.ctc@gmail.com>
> Reply-To: som.ctc@gmail.com
> To: Dan <danett18@yahoo.com.br>, beginners@perl.org
> Subject: Re: HTTP Filtering and Threads...
> In-Reply-To: <1189744345.822880.14730@50g2000hsm.googlegroups.com>
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> References: <1189744345.822880.14730@50g2000hsm.googlegroups.com>
> X-ELNK-Received-Info: spv=0;
> X-ELNK-AV: 0
> X-ELNK-Info: sbv=0; sbrc=.0; sbf=00; sbw=000;
>
> you can store all the data in an array first and then apply regex on
> all lines, if the response come in lines. Else, get all the data in a
> scalar and apply the regex. I think this may get you the silva
>
> my ($name,$type,$mname) =~ /name=(.*) type=(.*) value=(.*)/i;
>
> i'm not sure though how we may capture all the occurences.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
|
|
|
|
|