D
Dan
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,
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,