[30048] in Perl-Users-Digest
Perl-Users Digest, Issue: 1291 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 19 18:09:44 2008
Date: Tue, 19 Feb 2008 15:09:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 19 Feb 2008 Volume: 11 Number: 1291
Today's topics:
How do I add headers using WWW::Mechanize? <phillip.s.powell@gmail.com>
Re: How do I add headers using WWW::Mechanize? <joost@zeekat.nl>
Re: Number of days since 1/1/2000 mdonn@harbornet.com
Re: Number of days since 1/1/2000 <1usa@llenroc.ude.invalid>
Re: Number of days since 1/1/2000 <jurgenex@hotmail.com>
Re: Number of days since 1/1/2000 <smallpond@juno.com>
Re: Number of days since 1/1/2000 mdonn@harbornet.com
Re: Number of days since 1/1/2000 mdonn@harbornet.com
Re: Number of days since 1/1/2000 <1usa@llenroc.ude.invalid>
Re: Number of days since 1/1/2000 <noreply@gunnar.cc>
Re: Number of days since 1/1/2000 <smallpond@juno.com>
Re: Number of days since 1/1/2000 <mothra@nowhereatall.com>
Re: perl data structure <jimsgibson@gmail.com>
Re: perl data structure <tlviewer@VISTAyahoo.com>
Perls of Wisdom from thedailywtf.com <1usa@llenroc.ude.invalid>
Re: Regular Expression to Replace UPPER Case Text with <joost@zeekat.nl>
Re: Regular Expression to Replace UPPER Case Text with <cartercc@gmail.com>
Website test module <ignoramus9014@NOSPAM.9014.invalid>
Re: Website test module <joost@zeekat.nl>
Re: Website test module <ignoramus9014@NOSPAM.9014.invalid>
Re: Website test module <ben@morrow.me.uk>
Re: Website test module <ignoramus9014@NOSPAM.9014.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Feb 2008 13:09:48 -0800 (PST)
From: Phil Powell <phillip.s.powell@gmail.com>
Subject: How do I add headers using WWW::Mechanize?
Message-Id: <eb96abd1-9037-42ad-80d3-95a3c900ac63@n75g2000hsh.googlegroups.com>
Consider my code snippet:
<code>
use strict;
use warnings;
use HTTP::Cookies;
use WWW::Mechanize;
use LWP::Debug qw(+);
my $mech = WWW::Mechanize->new();
$mech->agent_alias('Windows IE 6');
$mech->cookie_jar(HTTP::Cookies->new(autosave => 1));
$mech->add_header('UID' => 'phil', 'cn' => 'CN', 'id' => '777');
my $response = $mech->get('https://www.example.com');
die "Error at https://www.example.com\n", $response->status_line, "\n
Aborting" unless $response->is_success;
$response = $mech->response;
for my $key ($response->header_field_names()) {
print "response[$key] = ", $response->header($key), "\n";
}
</code>
I am trying to add new headers into the HTTP headers and yet I do not
see 'UID' nor 'cn' nor 'id' whenever I list all of the returned
headers even though I added them. What might I be doing wrong, and
thus, how can I fix it so that these three addtitional fields are
added to the HTTP headers?
Thanks
Phil
------------------------------
Date: Tue, 19 Feb 2008 22:14:29 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: How do I add headers using WWW::Mechanize?
Message-Id: <8763wkbqdm.fsf@zeekat.nl>
Phil Powell <phillip.s.powell@gmail.com> writes:
You're adding header to the request, but you're printing response
headers. The server may or may not use those headers in the response,
but if it's a web server it probably won't.
By the way, those look like LDAP fields. What are you trying to do?
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 19 Feb 2008 11:51:56 -0800
From: mdonn@harbornet.com
Subject: Re: Number of days since 1/1/2000
Message-Id: <jccmr3pbis8nvhmm5crhpn1l80cr45g6e2@4ax.com>
On Tue, 19 Feb 2008 18:48:02 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:
>mdonn@harbornet.com wrote in news:je7mr3lb2t4i95h9esljtdmn467j9ai1dt@
>4ax.com:
>
>> Not being a high-power programmer like you folks, I did it this way,
>> which should work until 2100.
>>
>> use strict;
>> use warnings;
>> my ($y, $yd) = (localtime(time))[5,7];
>> my $yrs = $y - 101;
>> my $ld = int ($yrs+1)/4;
>> my $dif = 365 * $yrs + $ld + $yd;
>> $dif++ if $y%4 == 0 && $yd > 59;
>> print "$dif\n";
>
>> KISS!!
>
>
>Simple & correct is better than simple & wrong.
>
>Compare your solution to the truly simple and elegant solution posted by
>Gunnar elsethread:
>
>use strict;
>use warnings;
>
>my %methods = (
> prima_donna_method => \&prima_donna_method,
> simple_method => \&simple_method,
>);
>
>for my $method ( sort keys %methods ) {
> printf "%20s: %d\n", $method, $methods{ $method }->();
>}
>
>sub prima_donna_method {
> my ($y, $yd) = (localtime(time))[5,7];
> my $yrs = $y - 101;
> my $ld = int ($yrs+1)/4;
> my $dif = 365 * $yrs + $ld + $yd;
> $dif++ if $y%4 == 0 && $yd > 59;
> return $dif;
>}
>
>use Time::Local;
>
>sub simple_method {
> my $start = timelocal 0, 0, 0, 1, 0, 2000;
> my $today = timelocal 0, 0, 0, (localtime)[3..5];
> return sprintf '%.0f', ($today - $start) / 86400;
>}
>
>__END__
>
>C:\Home\test> tt0.pl
> prima_donna_method: 2606
> simple_method: 2971
>
>Ooops. You are off by one year!
>
>Sinan
Yes, there were 2 bugs, maybe more. Here is the corrected code:
use strict;
use warnings;
my ($y, $yd) = (localtime(time))[5,7];
my $yrs = $y - 100;
print "$yrs\n";
my $ld = int (($yrs+1)/4);
my $dif = 365 * $yrs + $ld + $yd;
$dif++ if $y%4 == 0 && $yd > 59;
print $dif;
However, my point, which seems to have been missed by you and the other
folk, is that the original poster stressed that he/she was concerned
both about speed and memory. My code, since it has no loops and does
not depend on any modules, should be both faster and smaller than all
the other attempts.
------------------------------
Date: Tue, 19 Feb 2008 19:57:11 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Number of days since 1/1/2000
Message-Id: <Xns9A499816AD8B6asu1cornelledu@127.0.0.1>
mdonn@harbornet.com wrote in
news:jccmr3pbis8nvhmm5crhpn1l80cr45g6e2@4ax.com:
> On Tue, 19 Feb 2008 18:48:02 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:
>
>>mdonn@harbornet.com wrote in news:je7mr3lb2t4i95h9esljtdmn467j9ai1dt@
>>4ax.com:
>>
>>> Not being a high-power programmer like you folks, I did it this way,
>>> which should work until 2100.
>>>
>>> use strict;
>>> use warnings;
>>> my ($y, $yd) = (localtime(time))[5,7];
>>> my $yrs = $y - 101;
>>> my $ld = int ($yrs+1)/4;
>>> my $dif = 365 * $yrs + $ld + $yd;
>>> $dif++ if $y%4 == 0 && $yd > 59;
>>> print "$dif\n";
>>
>>> KISS!!
>>
>>
>>Simple & correct is better than simple & wrong.
>>
>>Compare your solution to the truly simple and elegant solution
>>posted by Gunnar elsethread:
...
> Yes, there were 2 bugs, maybe more. Here is the corrected code:
[ not worth my time ]
> However, my point, which seems to have been missed by you and the
> other folk, is that the original poster stressed that he/she was
> concerned both about speed and memory. My code, since it has no loops
> and does not depend on any modules, should be both faster and smaller
> than all the other attempts.
Go ahead, feel free to waste more of your time benchmarking.
http://thedailywtf.com/Articles/Perls-of-Wisdom.aspx
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.rehabitation.com/clpmisc.shtml>
------------------------------
Date: Tue, 19 Feb 2008 20:07:34 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Number of days since 1/1/2000
Message-Id: <h5dmr3pf2e31654lvevtfvr90gpatmd9t1@4ax.com>
mdonn@harbornet.com wrote:
>Yes, there were 2 bugs, maybe more. Here is the corrected code:
>
>use strict;
>use warnings;
>my ($y, $yd) = (localtime(time))[5,7];
>my $yrs = $y - 100;
>print "$yrs\n";
>my $ld = int (($yrs+1)/4);
>my $dif = 365 * $yrs + $ld + $yd;
>$dif++ if $y%4 == 0 && $yd > 59;
>print $dif;
>
>However, my point, which seems to have been missed by you and the other
>folk, is that the original poster stressed that he/she was concerned
>both about speed and memory. My code, since it has no loops and does
>not depend on any modules, should be both faster and smaller than all
>the other attempts.
But you are still doing a dozen different computations. I still don't
understand why a simple
$days = int( (time() - $EpochSecondsAt01012000 ))
/ 86400));
doesn't suffice? Why is everyone fixated on computing years and then
converting back into days when all you gain that way is trouble with leap
years?
Note: $EpochSecondsAt01012000 is a constant, I'm just to lazy to compute it.
Besides it may vary between systems.
jue
------------------------------
Date: Tue, 19 Feb 2008 12:16:45 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Number of days since 1/1/2000
Message-Id: <f7bfa725-3d34-42ba-bdc8-14302a11a776@e60g2000hsh.googlegroups.com>
On Feb 18, 2:20 pm, oprah.cho...@gmail.com wrote:
> I am using the following subroutine to calculate the number of days
> since 1/1/2000 . Is there any possible bug in it? I know I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.
>
The time on 1/1/2000 is unlikely to change. You don't need to
recalculate it. Just set it as a constant in your program
and you don't need any modules. Not many people recalculate
PI from a series expansion every time they use it.
use constant Y2000 => 946702800;
use constant Y2038 => 2145934800;
sub calc_days {
my $diff = time;
warn "Is this still right?" if $diff > Y2038;
$diff -= Y2000;
int($diff / 86400);
}
print calc_days(),"\n";
2971
------------------------------
Date: Tue, 19 Feb 2008 12:28:19 -0800
From: mdonn@harbornet.com
Subject: Re: Number of days since 1/1/2000
Message-Id: <ikemr314q645nqrd17h34271doq33vj5te@4ax.com>
On Tue, 19 Feb 2008 19:57:11 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:
>mdonn@harbornet.com wrote in
>news:jccmr3pbis8nvhmm5crhpn1l80cr45g6e2@4ax.com:
>
>> On Tue, 19 Feb 2008 18:48:02 GMT, "A. Sinan Unur"
>> <1usa@llenroc.ude.invalid> wrote:
>>
>>>mdonn@harbornet.com wrote in news:je7mr3lb2t4i95h9esljtdmn467j9ai1dt@
>>>4ax.com:
>>>
>>>> Not being a high-power programmer like you folks, I did it this way,
>>>> which should work until 2100.
>>>>
>>>> use strict;
>>>> use warnings;
>>>> my ($y, $yd) = (localtime(time))[5,7];
>>>> my $yrs = $y - 101;
>>>> my $ld = int ($yrs+1)/4;
>>>> my $dif = 365 * $yrs + $ld + $yd;
>>>> $dif++ if $y%4 == 0 && $yd > 59;
>>>> print "$dif\n";
>>>
>>>> KISS!!
>>>
>>>
>>>Simple & correct is better than simple & wrong.
>>>
>>>Compare your solution to the truly simple and elegant solution
>>>posted by Gunnar elsethread:
>
>...
>
>> Yes, there were 2 bugs, maybe more. Here is the corrected code:
>
>[ not worth my time ]
>
>> However, my point, which seems to have been missed by you and the
>> other folk, is that the original poster stressed that he/she was
>> concerned both about speed and memory. My code, since it has no loops
>> and does not depend on any modules, should be both faster and smaller
>> than all the other attempts.
>
>Go ahead, feel free to waste more of your time benchmarking.
>
>http://thedailywtf.com/Articles/Perls-of-Wisdom.aspx
>
>Sinan
Sorry to have bothered such a superior being as yourself. I have plenty
of time to waste (long retired). I do think that you are the primadonna
here.
------------------------------
Date: Tue, 19 Feb 2008 12:30:18 -0800
From: mdonn@harbornet.com
Subject: Re: Number of days since 1/1/2000
Message-Id: <80fmr3pi2fbneqv6i9gkknkoub26gsm30q@4ax.com>
On Tue, 19 Feb 2008 20:07:34 GMT, Jürgen Exner <jurgenex@hotmail.com>
wrote:
>mdonn@harbornet.com wrote:
>>Yes, there were 2 bugs, maybe more. Here is the corrected code:
>>
>>use strict;
>>use warnings;
>>my ($y, $yd) = (localtime(time))[5,7];
>>my $yrs = $y - 100;
>>print "$yrs\n";
>>my $ld = int (($yrs+1)/4);
>>my $dif = 365 * $yrs + $ld + $yd;
>>$dif++ if $y%4 == 0 && $yd > 59;
>>print $dif;
>>
>>However, my point, which seems to have been missed by you and the other
>>folk, is that the original poster stressed that he/she was concerned
>>both about speed and memory. My code, since it has no loops and does
>>not depend on any modules, should be both faster and smaller than all
>>the other attempts.
>
>But you are still doing a dozen different computations. I still don't
>understand why a simple
>
> $days = int( (time() - $EpochSecondsAt01012000 ))
> / 86400));
>
>doesn't suffice? Why is everyone fixated on computing years and then
>converting back into days when all you gain that way is trouble with leap
>years?
>
>Note: $EpochSecondsAt01012000 is a constant, I'm just to lazy to compute it.
>Besides it may vary between systems.
>
>jue
Better than mine.
------------------------------
Date: Tue, 19 Feb 2008 20:35:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Number of days since 1/1/2000
Message-Id: <Xns9A499E86FC8A2asu1cornelledu@127.0.0.1>
mdonn@harbornet.com wrote in
news:80fmr3pi2fbneqv6i9gkknkoub26gsm30q@4ax.com:
> On Tue, 19 Feb 2008 20:07:34 GMT, Jürgen Exner <jurgenex@hotmail.com>
> wrote:
>
...
>>But you are still doing a dozen different computations. I still don't
>>understand why a simple
>>
>> $days = int( (time() - $EpochSecondsAt01012000 ))
>> / 86400));
>>
>>doesn't suffice? Why is everyone fixated on computing years and then
>>converting back into days when all you gain that way is trouble with
>>leap years?
>>
>>Note: $EpochSecondsAt01012000 is a constant, I'm just to lazy to
>>compute it. Besides it may vary between systems.
>>
>>jue
>
> Better than mine.
That is my point, precisely.
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:61ur23F214sikU2
@mid.individual.net:
+> use Time::Local;
+> my $start = timelocal 0, 0, 0, 1, 0, 2000;
+> my $today = timelocal 0, 0, 0, (localtime)[3..5];
+> my $days = sprintf '%.0f', ($today - $start) / 86400;
Time::Local allows you to calculate the $EpochSecondsAt01012000. If you
want, you can calculate it once and then hardwire it into your program.
But all this error-prone grade school arithmetic is useless.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.rehabitation.com/clpmisc.shtml>
------------------------------
Date: Tue, 19 Feb 2008 22:42:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Number of days since 1/1/2000
Message-Id: <6210mjF20odinU1@mid.individual.net>
smallpond wrote:
> On Feb 18, 2:20 pm, oprah.cho...@gmail.com wrote:
>> ... to calculate the number of days since 1/1/2000
>
> The time on 1/1/2000 is unlikely to change. You don't need to
> recalculate it. Just set it as a constant in your program
> and you don't need any modules.
In the code below I make use of a constant SUMMERNIGHT which contains
what time() will return 15 minutes after midnight at June, 20.
C:\home>type test.pl
use Time::Local;
use constant Y2000 => 946702800;
use constant Y2038 => 2145934800;
use constant SUMMERNIGHT => 1213913700;
sub calc_days1 { # smallpond's code
my $diff = SUMMERNIGHT;
warn "Is this still right?" if $diff > Y2038;
$diff -= Y2000;
int($diff / 86400);
}
sub calc_days2 { # Gunnar's code
my $start = timelocal 0, 0, 0, 1, 0, 2000;
my $today = timelocal 0, 0, 0, (localtime SUMMERNIGHT)[3..5];
sprintf '%.0f', ($today - $start) / 86400;
}
print 'calc_days1: ', calc_days1(), "\n",
'calc_days2: ', calc_days2(), "\n";
C:\home>test.pl
calc_days1: 3092
calc_days2: 3093
Oops!!
Not using any module seems to be bad advice.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 19 Feb 2008 14:18:32 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Number of days since 1/1/2000
Message-Id: <c0efefa4-3309-4497-a412-68f05be5dd72@34g2000hsz.googlegroups.com>
On Feb 19, 4:42 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> smallpond wrote:
> > On Feb 18, 2:20 pm, oprah.cho...@gmail.com wrote:
> >> ... to calculate the number of days since 1/1/2000
>
> > The time on 1/1/2000 is unlikely to change. You don't need to
> > recalculate it. Just set it as a constant in your program
> > and you don't need any modules.
>
> In the code below I make use of a constant SUMMERNIGHT which contains
> what time() will return 15 minutes after midnight at June, 20.
>
> C:\home>type test.pl
> use Time::Local;
> use constant Y2000 => 946702800;
> use constant Y2038 => 2145934800;
> use constant SUMMERNIGHT => 1213913700;
>
> sub calc_days1 { # smallpond's code
> my $diff = SUMMERNIGHT;
> warn "Is this still right?" if $diff > Y2038;
> $diff -= Y2000;
> int($diff / 86400);
>
> }
>
> sub calc_days2 { # Gunnar's code
> my $start = timelocal 0, 0, 0, 1, 0, 2000;
> my $today = timelocal 0, 0, 0, (localtime SUMMERNIGHT)[3..5];
> sprintf '%.0f', ($today - $start) / 86400;
>
> }
>
> print 'calc_days1: ', calc_days1(), "\n",
> 'calc_days2: ', calc_days2(), "\n";
>
> C:\home>test.pl
> calc_days1: 3092
> calc_days2: 3093
>
> Oops!!
>
> Not using any module seems to be bad advice.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
oops indeed. I get 3092 for both. Perhaps you should
investigate DST in your two conversions to see which is
correct. I'm pretty sure that Unix clock seconds are
fairly constant.
------------------------------
Date: Tue, 19 Feb 2008 14:22:54 -0800
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: Number of days since 1/1/2000
Message-Id: <47bb61d7@usenet.ugs.com>
Hello,
<oprah.chopra@gmail.com> wrote in message
news:7c71334e-95bd-46da-bd83-78d7bb72d175@u10g2000prn.googlegroups.com...
>I am using the following subroutine to calculate the number of days
> since 1/1/2000 . Is there any possible bug in it? I know I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.
You may want to take a look at the DateTime project
http://datetime.perl.org/
Many very smart people have spent many hours making sure DateTime
calculations are correct. Why reinvent the wheel when you don't have to.
use strict;
use warnings;
use DateTime;
my $dt = DateTime->now;
my $base_date = DateTime->new(
year => 2000,
month => 1,
day => 1,
time_zone => 'UTC',
);
print int( $dt->jd - $base_date->jd );
I hope this helps
Mothra
------------------------------
Date: Tue, 19 Feb 2008 11:09:02 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perl data structure
Message-Id: <190220081109028536%jimsgibson@gmail.com>
In article
<6ea19315-2409-4fe4-9d34-7dd3346329d7@41g2000hsc.googlegroups.com>, BH
<Benson.Hoi@googlemail.com> wrote:
> Hi,
>
> I am reading in an comma separator file,
>
> line 1: Field 1, field 2, field 3.., field n
> line 2: Field 1, field 2, field 3.., field n
>
> I would like to create a data structure to representing the whole
> file.
>
> What is an efficient and easy way to store the above such that, for a
> given value for field i, I can extract an array of values for field j,
> where 1<=i,j<=n? It's a bit like asking what the best way to store a
> spreadsheet is.
>
> Hash of anonymous arrays? How will the syntax be?
The most efficient structure is probably an array of arrays. The syntax
for generating this structure is something like the following:
#!/usr/local/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @aoa;
while( <DATA> ) {
chomp;
push( @aoa, [ split /,/, $_ ]);
}
print Dumper(\@aoa);
__DATA__
Field 1.1, field 1.2, field 1.3
Field 2.1, field 2.2, field 2.3
You can access these elements with expressions such as $aoa[1][2],
which has the value ' field 2.3' (note the leading space, which can be
removed if it is a problem. Hint; change the regular expression used by
the split function).
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 19 Feb 2008 19:16:56 GMT
From: Mark Pryor <tlviewer@VISTAyahoo.com>
Subject: Re: perl data structure
Message-Id: <47bb2b27$0$30682$4c368faf@roadrunner.com>
On Tue, 19 Feb 2008 09:15:35 -0800, BH wrote:
> Hi,
>
> I am reading in an comma separator file,
>
> line 1: Field 1, field 2, field 3.., field n line 2: Field 1, field 2,
> field 3.., field n
>
> I would like to create a data structure to representing the whole file.
>
> What is an efficient and easy way to store the above such that, for a
> given value for field i, I can extract an array of values for field j,
> where 1<=i,j<=n? It's a bit like asking what the best way to store a
> spreadsheet is.
>
> Hash of anonymous arrays? How will the syntax be?
>
I've had good luck using Text::CSV_XS
I like to load into an AoA (array of anonymous arrays)
You can also use the Storable module to export the whole AoA to its own
file and avoid parsing with Text::CSV_XS (resource hog) each time you run
the script.
On subsequent runs use the ::Retrieve() call to reload into an AoA.
Your code will instantly be x-platform too if you find a PPD for
Text::CSV_XS to run on WinXP. Its out there.
--
Mark
------------------------------
Date: Tue, 19 Feb 2008 19:53:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Perls of Wisdom from thedailywtf.com
Message-Id: <Xns9A49976DE9088asu1cornelledu@127.0.0.1>
This covers so many standard arguments on this group.
http://thedailywtf.com/Articles/Perls-of-Wisdom.aspx
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.rehabitation.com/clpmisc.shtml>
------------------------------
Date: Tue, 19 Feb 2008 22:23:34 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Regular Expression to Replace UPPER Case Text with lower case text
Message-Id: <871w78bpyh.fsf@zeekat.nl>
ccc31807 <cartercc@gmail.com> writes:
> I understand that this is OT, but I'm just wondering ... Is there any
> good reason I shouldn't learn how to develop web apps in Lisp? I'm
> just now taking my first baby steps in constructing Lisp scripts that
> spit out HTML with data drawn from data stores, and as far as I can
> tell, Lisp potentially has some strengths that Perl does not have (or
> CF, .NET, JSP, Python, or any of the others.)
Lisp is a great language to develop in, so why not? You may have to
spend more time to find (and possibly fix) the right mix of libraries to
use for web apps but there is a lot of interesting web stuff going on in
the Lisp world.
http://www.lispcast.com/ has some interesting videos (the code is all
pretty low-level, though - there are much more comple CL web / model
frameworks out there).
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 19 Feb 2008 13:15:24 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Regular Expression to Replace UPPER Case Text with lower case text
Message-Id: <6d07c043-ada3-4e28-afd9-2278c28a44cf@i7g2000prf.googlegroups.com>
On Feb 19, 1:35 pm, Charlton Wilbur
> The notion that using Perl for web apps is *controversial* is,
> frankly, ludicrous.
'Controversial' in the sense of causing controversary. As your own
punch lines demonstrate. Suffice it to say that people have strong
opinions about the (un)suitability of Perl for web apps, or any other
kind of apps for that matter.
> The person who laughs at you for using Perl is the person you will
> leave in your dust, assuming you don't heed his advice.
Just got back to work after several hours out of the office and had my
ears filled with the INSTR() function in Access. Seems that they
needed to match two rather large text files with 'MTH-1101' in one
file with 'MTH1101' in the other file, and ended up using Access to
match the rows. Yeah, I hear you!
> From a technical point of view, there's no reason to avoid Lisp in web
> development. From a practical point of view, if you ever intend to
> hand this code off to someone else or to work with someone else,
> you'll need to find a Lisp enthusiast.
Same with Perl, as my course matching story demonstrates.
> And any theoretical strengths Lisp might have once had have long since
> been stolen by other languages; the practical ones, well, let's just
> say that the common criticism of Perl, that it's possible to write
> write-only code, is multiplied a thousandfold when you start dealing
> with Lisp's macro system. And then, on top of that, you have the
> rabid Lisp fanbase -- their own worst enemy.
Agree with every thing you said, except that Lisp, like Perl and other
technologies, has tasks for which it is suited. Those rabid fans? Just
because they are rabid doesn't mean that everything they claim is
false.
CC
------------------------------
Date: Tue, 19 Feb 2008 13:37:41 -0600
From: Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid>
Subject: Website test module
Message-Id: <4OSdndLSRZmYrSbanZ2dnUVZ_v6rnZ2d@giganews.com>
I would like to know what are the "most recommended" perl modules for
testing websites. For example, my typical task would be
- connect to IP address A
- request webpage B http://B/page.html
- check that it contacts a keyword C
What is important is that address A (my test or backup website) does
not necessarily match virtual host name B.
I read on Test::WWW::Mechanize, which I like a lot as I am very
familiar with WWW::Mechanize, but it does not seem to offer this
ability (connect to a given IP but use a unrelated virtual address).
Thanks
i
------------------------------
Date: Tue, 19 Feb 2008 20:51:35 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Website test module
Message-Id: <87prusbu7s.fsf@zeekat.nl>
Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid> writes:
> I would like to know what are the "most recommended" perl modules for
> testing websites. For example, my typical task would be
>
> - connect to IP address A
> - request webpage B http://B/page.html
> - check that it contacts a keyword C
I'm not sure what this means.
> What is important is that address A (my test or backup website) does
> not necessarily match virtual host name B.
>
> I read on Test::WWW::Mechanize, which I like a lot as I am very
> familiar with WWW::Mechanize, but it does not seem to offer this
> ability (connect to a given IP but use a unrelated virtual address).
So you want to access site A but with the hostname set to that of B?
The first thing in my mind is to set the IP address of B with the name
of A in the /etc/hosts file (there are similar files in various versions
windows, should you need to).
You probably do need root/administrator priviliges to set the hosts
file, though.
Another way could be to use a local HTTP proxy and connect through
that. I'm confident HTTP::Proxy will let you write something that
translates hostnames in a dozen lines or so - see its example scripts.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 19 Feb 2008 14:10:14 -0600
From: Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid>
Subject: Re: Website test module
Message-Id: <LYqdna3epM07qibanZ2dnUVZ_hninZ2d@giganews.com>
On 2008-02-19, Joost Diepenmaat <joost@zeekat.nl> wrote:
> Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid> writes:
>
>> I would like to know what are the "most recommended" perl modules for
>> testing websites. For example, my typical task would be
>>
>> - connect to IP address A
>> - request webpage B http://B/page.html
>> - check that it contacts a keyword C
>
> I'm not sure what this means.
>
>> What is important is that address A (my test or backup website) does
>> not necessarily match virtual host name B.
>>
>> I read on Test::WWW::Mechanize, which I like a lot as I am very
>> familiar with WWW::Mechanize, but it does not seem to offer this
>> ability (connect to a given IP but use a unrelated virtual address).
>
> So you want to access site A but with the hostname set to that of B?
> The first thing in my mind is to set the IP address of B with the name
> of A in the /etc/hosts file (there are similar files in various versions
> windows, should you need to).
You got it, yes, I want to use a certain virtual hostname, but access
an IP that does not match it (because I am testing a replacement
server).
For example, I am testing a replacement server for www.algebra.com.
The IP address for real algebra.com is 65.182.171.162 and it is in a
datacenter.
The replacement server is 10.1.2.3 and is in my basement, being built
and tested.
I want to access 10.1.2.3 and say "give me http://www.algebra.com/page.html".
i
> You probably do need root/administrator priviliges to set the hosts
> file, though.
>
> Another way could be to use a local HTTP proxy and connect through
> that. I'm confident HTTP::Proxy will let you write something that
> translates hostnames in a dozen lines or so - see its example scripts.
>
OK, that, in fact, is a great start, if I can use a proxy in this
manner I will be happy. Thanks
i
------------------------------
Date: Tue, 19 Feb 2008 20:39:16 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Website test module
Message-Id: <kcrr85-q1k2.ln1@osiris.mauzo.dyndns.org>
Quoth Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid>:
> I would like to know what are the "most recommended" perl modules for
> testing websites. For example, my typical task would be
>
> - connect to IP address A
> - request webpage B http://B/page.html
> - check that it contacts a keyword C
>
> What is important is that address A (my test or backup website) does
> not necessarily match virtual host name B.
>
> I read on Test::WWW::Mechanize, which I like a lot as I am very
> familiar with WWW::Mechanize, but it does not seem to offer this
> ability (connect to a given IP but use a unrelated virtual address).
You should be able to subclass LWP::Protocol::http, override
->_new_socket to map B->A and call SUPER::_new_socket, and then use
LWP::Protocol::implementor to set your new class as the implementation
to use for http. Then you should be able to just use WWW::Mech normally.
Something like (completely untested):
use LWP;
use WWW::Mechanize;
{
package My::LWP::Protocol::http;
our @ISA = 'LWP::Protocol::http';
my %fake = (
'B' => '192.168.1.2',
);
sub _new_socket {
my ($self, $host, $port, $timeout) = @_;
$fake{$host} and $host = $fake{$host};
return $self->SUPER::_new_socket($host, $port, $timeout);
}
LWP::Protocol::implementor http => __PACKAGE__;
}
my $M = WWW::Mechanize->new(...);
...
Ben
------------------------------
Date: Tue, 19 Feb 2008 15:49:48 -0600
From: Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid>
Subject: Re: Website test module
Message-Id: <0tidnclGsc1h0ybanZ2dnUVZ_r3inZ2d@giganews.com>
On 2008-02-19, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth Ignoramus9014 <ignoramus9014@NOSPAM.9014.invalid>:
>> I would like to know what are the "most recommended" perl modules for
>> testing websites. For example, my typical task would be
>>
>> - connect to IP address A
>> - request webpage B http://B/page.html
>> - check that it contacts a keyword C
>>
>> What is important is that address A (my test or backup website) does
>> not necessarily match virtual host name B.
>>
>> I read on Test::WWW::Mechanize, which I like a lot as I am very
>> familiar with WWW::Mechanize, but it does not seem to offer this
>> ability (connect to a given IP but use a unrelated virtual address).
>
> You should be able to subclass LWP::Protocol::http, override
> ->_new_socket to map B->A and call SUPER::_new_socket, and then use
> LWP::Protocol::implementor to set your new class as the implementation
> to use for http. Then you should be able to just use WWW::Mech normally.
> Something like (completely untested):
>
> use LWP;
> use WWW::Mechanize;
>
> {
> package My::LWP::Protocol::http;
>
> our @ISA = 'LWP::Protocol::http';
>
> my %fake = (
> 'B' => '192.168.1.2',
> );
>
> sub _new_socket {
> my ($self, $host, $port, $timeout) = @_;
> $fake{$host} and $host = $fake{$host};
> return $self->SUPER::_new_socket($host, $port, $timeout);
> }
>
> LWP::Protocol::implementor http => __PACKAGE__;
> }
>
> my $M = WWW::Mechanize->new(...);
>
> ...
>
> Ben
>
Ben, thanks, it is a little over my head, but I spent some time
trying.
I got to the point of running queries, but the _new_socket function
was never called.
Here's my actual code:
######################################################################
#!/usr/bin/perl
use LWP;
use WWW::Mechanize;
use Data::Dumper;
{
package My::LWP::Protocol::http;
use Data::Dumper;
use LWP::Protocol::http;
our @ISA = 'LWP::Protocol::http';
my %fake = (
'B' => '127.0.0.1',
);
sub _new_socket {
my ($self, $host, $port, $timeout) = @_;
print STDERR "HOST=$host\n";
exit 0;
$fake{$host} and $host = $fake{$host};
return $self->SUPER::_new_socket($host, $port, $timeout);
}
sub new {
return LWP::Protocol::http->new;
}
LWP::Protocol::implementor http => __PACKAGE__;
}
my $M = WWW::Mechanize->new();
my $resp = $M->get( 'http://www.algebra.com/robots.txt' );
print $resp->content;
------------------------------
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 1291
***************************************