[28244] in Perl-Users-Digest
Perl-Users Digest, Issue: 9608 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 15 14:05:53 2006
Date: Tue, 15 Aug 2006 11:05:07 -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 Tue, 15 Aug 2006 Volume: 10 Number: 9608
Today's topics:
Re: Accessing a container objects state from aggregated <dbasch@yahoo.com>
Re: Accessing a container objects state from aggregated <1usa@llenroc.ude.invalid>
Re: Accessing a container objects state from aggregated anno4000@radom.zrz.tu-berlin.de
Beginner: little rand() question in a long posting ... <mstep@t-online.de>
Re: Beginner: little rand() question in a long posting <mritty@gmail.com>
Re: Beginner: little rand() question in a long posting <mstep@t-online.de>
Re: Beginner: little rand() question in a long posting <tzz@lifelogs.com>
Re: current directory name in perl <dennishancy@eaton.com>
Re: current directory name in perl <rvtol+news@isolution.nl>
Re: current directory name in perl <jurgenex@hotmail.com>
Re: current directory name in perl <1usa@llenroc.ude.invalid>
Re: current directory name in perl <tzz@lifelogs.com>
Re: File does not exist: /home/virtual/site2/fst/var/ww <jurgenex@hotmail.com>
LWP post with cookie syntax <dont_bug_me@all.uk>
Re: LWP post with cookie syntax <uri@stemsystems.com>
Re: LWP post with cookie syntax <mritty@gmail.com>
Re: My multipost-detecting usenet bot (David Filmer) <john@castleamber.com>
Re: My multipost-detecting usenet bot (David Filmer) <john@castleamber.com>
NetInquire <d2rk@yandex.ru>
Re: NetInquire <no@email.com>
Re: Parsing text to array <tzz@lifelogs.com>
perl dbi driver for microsoft sql? <bootiack@yahoo.com>
Re: Proposal: extending perldoc -f <nospam-abuse@ilyaz.org>
Re: Publicly flog David Filmer for writing multi-post f <john@castleamber.com>
Re: string and time question <jurgenex@hotmail.com>
Website Interface Zyad.Tamimi@gmail.com
Re: Website Interface usenet@DavidFilmer.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Aug 2006 10:25:25 -0700
From: "Derek Basch" <dbasch@yahoo.com>
Subject: Re: Accessing a container objects state from aggregated objects
Message-Id: <1155662725.339425.225090@75g2000cwc.googlegroups.com>
> This looks like a has-a situation with delegation of methods to member
> objects. That is a standard technique. Whether there is a better one
> in your situation isn't clear because you haven't described what the
> situation is.
>
> Anno
Yes, that is the situation that I was going for. Here is a description
of what I am using this technique for:
I have Members of a club and the Members have a Membership. So, Member
aggregates Membership.
The Member object holds some state information about the member such as
their address. I was wondering what the best way of accessing a Member
container objects address state from the aggregated object Membership
was.
Should I pass a reference to the Member object to the Membership object
in the Member constructor?
package Member;
sub new {
........
bless ($self, $class);
$self->{'membership_dev'} = Membership_dev->new($self);
return $self;
}
Is that the best way?
Thanks,
Derek Basch
------------------------------
Date: Tue, 15 Aug 2006 17:54:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Accessing a container objects state from aggregated objects
Message-Id: <Xns98208D9E9DD05asu1cornelledu@127.0.0.1>
"Derek Basch" <dbasch@yahoo.com> wrote in
news:1155662725.339425.225090@75g2000cwc.googlegroups.com:
>> This looks like a has-a situation with delegation of methods to
>> member objects. That is a standard technique. Whether there is a
>> better one in your situation isn't clear because you haven't
>> described what the situation is.
...
> Yes, that is the situation that I was going for. Here is a description
> of what I am using this technique for:
>
> I have Members of a club and the Members have a Membership. So, Member
> aggregates Membership.
>
> The Member object holds some state information about the member such
> as their address. I was wondering what the best way of accessing a
> Member container objects address state from the aggregated object
> Membership was.
>
> Should I pass a reference to the Member object to the Membership
> object in the Member constructor?
>
> package Member;
> sub new {
> ........
> bless ($self, $class);
> $self->{'membership_dev'} = Membership_dev->new($self);
> return $self;
>
> }
Wait a second. Each Member has a Membership object. I am not sure why
each Membership object needs to know its owner.
I am not sure why you need separate Member and Membership classes, but I
will assume that is appropriate.
Now, I would think that you would only access the Membership objects
through their owners.
Without knowing anything else about your design, I would put an accessor
for the Membership object in Member instead of using a hash reference.
That way, the internal details of the Member object are not exposed.
I am including an example below.
#!/usr/bin/perl
package Membership;
use strict;
use warnings;
use Readonly;
Readonly::Array our @fields => qw(id group email);
sub new {
my $class = shift;
my %args;
@args{ @fields } = @{ %{ $_[0] } }{ @fields };
bless \%args => $class;
}
sub get_id { $_[0]->{id} }
sub get_group { $_[0]->{group} }
sub get_email { $_[0]->{email} }
package Member;
use strict;
use warnings;
use Readonly;
Readonly::Array our @fields => qw( first_name last_name membership );
sub new {
my $class = shift;
my %args;
@args{ @fields } = @{ %{ $_[0] }}{ @fields };
bless \%args => $class;
}
sub get_membership { $_[0]->{ membership } }
sub get_first_name { $_[0]->{ first_name } }
sub get_last_name { $_[0]->{ last_name } }
package main;
use strict;
use warnings;
my $m = Member->new(
{
first_name => 'Tester',
last_name => 'Testing',
membership => Membership->new(
{
id => 'test',
group => 'users',
email => 'test@example.com',
}
),
}
);
printf "Member: %s %s\n", $m->get_first_name, $m->get_last_name;
print "Details:\n\tID: ", $m->get_membership->get_id,
"\n\tGroup: ", $m->get_membership->get_group,
"\n\tEmail: ", $m->get_membership->get_email, "\n";
__END__
D:\UseNet\clpmisc\member> m
Member: Tester Testing
Details:
ID: test
Group: users
Email: test@example.com
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 15 Aug 2006 18:00:54 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Accessing a container objects state from aggregated objects
Message-Id: <4kegemFbja84U1@news.dfncis.de>
Derek Basch <dbasch@yahoo.com> wrote in comp.lang.perl.misc:
> > This looks like a has-a situation with delegation of methods to member
> > objects. That is a standard technique. Whether there is a better one
> > in your situation isn't clear because you haven't described what the
> > situation is.
> >
> > Anno
>
> Yes, that is the situation that I was going for. Here is a description
> of what I am using this technique for:
>
> I have Members of a club and the Members have a Membership. So, Member
> aggregates Membership.
>
> The Member object holds some state information about the member such as
> their address. I was wondering what the best way of accessing a Member
> container objects address state from the aggregated object Membership
> was.
>
> Should I pass a reference to the Member object to the Membership object
> in the Member constructor?
>
> package Member;
> sub new {
> ........
> bless ($self, $class);
> $self->{'membership_dev'} = Membership_dev->new($self);
> return $self;
>
> }
>
> Is that the best way?
It is one way. If I'm not mistaken you're creating a cyclic reference
there, so you'd need a destructor in one of the classes to resolve that,
or use weak refs.
Alternatives are passing the Member object (or just the address) as
a parameter to the Membership method(s) that need(s) to know. Or
make the Membership method a Member method (to which, presumably,
the specific membership would have to be passed).
I'm sure there are other ways. Which one is "best" is ultimately
a design decision you must answer yourself.
Anno
------------------------------
Date: Tue, 15 Aug 2006 17:27:16 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Beginner: little rand() question in a long posting ...
Message-Id: <C107B474.2A36D%mstep@t-online.de>
Hello happy Perlers,
a beginner has to struggle with many mysterious problems. One of these
problems is, to ask a question shortly, so excuse me for this long posting.
I have tried to put in a script a random number. I read the perlfaq4 ("How
do I get a random number between X and Y?") and made my first "random steps"
with this script, which is working fine:
#!/usr/bin/perl
# here a subroutine found in: % perldoc perlfaq4
my $random_number = random_int_in(50,120);
sub random_int_in ($$)
{
my($min, $max) = @_;
# Assumes that the two arguments are integers themselves!
return $min if $min == $max;
($min, $max) = ($max, $min) if $min > $max;
return $min + int rand(1 + $max - $min);
}
print "here it comes: my first random number, I hope: \n\t$random_number
!!\n\nWOW! It's workin :-) \n\n";
my $random_number2 = random_int_in(1,7);
my $random_number3 = "1.$random_number2";
print "there is coming a second random Number! \n\t$random_number2\n\nWOW!
It's still workin :-)\n\n";
print "there is coming a third random Number! \n\t$random_number3\n\nWOW!
It's still workin :-)\n\n";
I am integrating it into my script, producing a LaTeX - file, but I get
mysterious error messages:
main::random_int_in() called too early to check prototype at ./calc_hours.pl
line 54.
Argument "185.88 / 1.8" isn't numeric in sprintf at ./calc_hours.pl line 63,
<IN> line 61 ...
This script is long, sorry:
#!/usr/bin/perl
use strict;
use warnings;
#### Files #################
my $in_file = 'calc_hours_in.tex';
open IN, "< $in_file" or die "Could not open your in_file: $!";
my $out_file = 'calc_hours.tex';
open OUT, "> $out_file" or die "Connot create your out_file: $!";
####END Files ##############
my $latex_head = <<"EOF";
\\documentclass[a4]{scrartcl}
\\usepackage[utf8]{inputenc}
\\usepackage{ltxtable}
\\clubpenalty = 10000
\\widowpenalty = 10000
\\begin{document}
Fahrer\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\hfill
{Monat}\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_
\\begin{longtable}[c]{| c | c | c | c | c | c | c | c |}
\\hline
\\multicolumn{8}{| c |}{\\textbf{Tageseinnahmen/Arbeitsnachweis}} \\\\
\\hline
& & & \\multicolumn{5}{ c |}{\\textbf{Arbeitszeit}} \\\\
\\hline
\\textbf{Datum} & \\textbf{Umsatz 7\\%} & \\textbf{Umsatz 16\\%} &
\\textbf{Beginn} & \\textbf{Pause} & \\textbf{Ende} & \\textbf{Stunden} &
\\textbf{Km-Gesamt} \\\\
\\hline
EOF
my $latex_foot = <<EOF;
\\end{longtable}
\\end{document}
EOF
print OUT "$latex_head";
####Variables###############
my $date1 = '';
my $date2 = '';
my @lines_in = '';
my @lines_out = '';
my $sum = 0;
my $sum_total = 0;
my $sum_total_sb = 0;
####End Variables###########
####Read in and work########
while ( <IN> ) {
/^(\w+, +[\d.]+)/ and $date1 = $1;
if (/^TOTAL/) { push @lines_in, "$date1\t$_"};
}
my $random_number = random_int_in(5,8);
foreach my $line (@lines_in) {
($sum) = $line =~ /([\d.]+)\s+$/;
($date2) = $line =~ /^(\w+, +[\d.]+)/;
$sum_total += $sum if $sum;
$sum *= 0.40 if $sum;
$sum_total_sb += $sum if $sum;
my $random_km = "1.$random_number";
my $km_tag = "$sum / $random_km" if $sum;
$km_tag = sprintf("%.2f", $km_tag) if $sum;
my $begin = 6;
my $end = $begin + 8;
my $hours = $end - $begin;
push (@lines_out,
"$date2\t&\t$sum\t&\tUmsatz16\t&\t$begin\t&\t$random_km\t&\t$end\t&\t$hours\
t&\t$km_tag\\\\\n" ) if $sum;
}
####END Read in and work####
####Output##################
print OUT "@lines_out";
print OUT "Gesamt:\t&\t$sum_total_sb\t&\t&\t&\t&\t&\t&\\\\\n";
print OUT $latex_foot;
####END Output##############
sub random_int_in ($$)
{
my($min, $max) = @_;
# Assumes that the two arguments are integers themselves!
return $min if $min == $max;
($min, $max) = ($max, $min) if $min > $max;
return $min + int rand(1 + $max - $min);
}
close OUT;
close IN;
The IN-File ( calc_hours_in.tex ) contains many lines, from which I read in
only the TOTALs and work on it ...
Son, 16.07.2006 37086.40 15445.00 808 19.50 3156.30
Mon, 17.07.2006 37667.00 15769.20 817 19.50 3621.00
TOTAL 580.60 324.20 9 0.00 464.70
Mon, 17.07.2006 37667.00 15769.20 817 19.50 3621.00
Die, 18.07.2006 37936.50 15929.60 823 19.50 3857.80
TOTAL 269.50 160.40 6 0.00 236.80
------------------------------
Date: 15 Aug 2006 08:39:32 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Beginner: little rand() question in a long posting ...
Message-Id: <1155656371.993228.239040@75g2000cwc.googlegroups.com>
Marek Stepanek wrote:
> a beginner has to struggle with many mysterious problems. One of these
> problems is, to ask a question shortly, so excuse me for this long posting.
>
> I have tried to put in a script a random number. I read the perlfaq4 ("How
> do I get a random number between X and Y?") and made my first "random steps"
> with this script, which is working fine:
>
> #!/usr/bin/perl
Always include the lines:
use strict;
use warnings;
right below the shebang
> # here a subroutine found in: % perldoc perlfaq4
>
> my $random_number = random_int_in(50,120);
>
> sub random_int_in ($$)
> {
<snip>
> I am integrating it into my script, producing a LaTeX - file, but I get
> mysterious error messages:
Error messages in perl are not mysterious. They are very well
explained by reading:
perldoc perldiag
Even better, you can put the line:
use diagnostics;
at the top of your script, and cause Perl to look up the description of
the error messages for you.
> main::random_int_in() called too early to check prototype at ./calc_hours.pl
> line 54.
This means exactly what it says. Your subroutine has a prototype, but
you called the subroutine before you declared it. Hence the prototype
could not be checked. Define the subroutine first. Or at least
declare it first. See: perldoc perlsub
<snip>
> my $random_km = "1.$random_number";
> my $km_tag = "$sum / $random_km" if $sum;
> $km_tag = sprintf("%.2f", $km_tag) if $sum;
> Argument "185.88 / 1.8" isn't numeric in sprintf at ./calc_hours.pl line 63,
> <IN> line 61 ...
You assigned $km_tag to a string: "185.88 / 1.8". I assume you meant
to assign it to a numerical computation (ie, the result of 185.88
divided by 1.8). If that's the case, remove the quotes in the third
quoted line above:
my $km_tag = $sum / $random_km if $sum;
> This script is long, sorry:
Don't be sorry... just don't do it. Post a short-but-complete script
that demonstrates your error. That should be one of your first steps
towards debugging a problem to begin with.
Paul Lalli
------------------------------
Date: Tue, 15 Aug 2006 18:15:21 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Beginner: little rand() question in a long posting ...
Message-Id: <C107BFB9.2A374%mstep@t-online.de>
On 15.08.2006 17:39, in article
1155656371.993228.239040@75g2000cwc.googlegroups.com, "Paul Lalli"
<mritty@gmail.com> wrote:
>
> Paul Lalli
>
Thank you Paul, for your help. I have to work a lot again!
marek
------------------------------
Date: Tue, 15 Aug 2006 13:00:11 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Beginner: little rand() question in a long posting ...
Message-Id: <g69odum6ijo.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 15 Aug 2006, mstep@t-online.de wrote:
> Argument "185.88 / 1.8" isn't numeric in sprintf at ./calc_hours.pl line 63,
> <IN> line 61 ...
...
> $sum_total += $sum if $sum;
> $sum *= 0.40 if $sum;
> $sum_total_sb += $sum if $sum;
> my $random_km = "1.$random_number";
> my $km_tag = "$sum / $random_km" if $sum;
> $km_tag = sprintf("%.2f", $km_tag) if $sum;
Hi Marek,
I wanted to mention two things in addition to Paul Lalli's comments.
First, you have "STATEMENT if $sum" many times. Just use one if:
if ($sum)
{
a;
b;
c;
}
I also don't think you need to do it exactly this way - what will
happen if $sum is zero? I don't think any of the statements I quoted
need to be skipped, since the numbers won't change. Perhaps you want
"if (defined $sum)" instead, if $sum is undefined sometimes.
Second, you are generating $random_km with "1.NUMBER" and the random
number is between 5 and 8. You really want to use some math here; the
proper solution is (I think)
$random_km = 1.5 + rand(0.3); # random between 1.5 and 1.7999...
which will give you random numbers between 1.5 and 1.7999999... (but
never 1.8). I hope I understood what you are trying to do. The
function you have is fine, but may be overkill for your needs. If you
need the number to have only N digits of precision, use sprintf() as
you already use it for $km_tag to get 2 digits of floating point
precision.
Check out "perldoc -f rand" for more info.
Ted
------------------------------
Date: 15 Aug 2006 07:26:28 -0700
From: "dennishancy@eaton.com" <dennishancy@eaton.com>
Subject: Re: current directory name in perl
Message-Id: <1155651988.791384.323350@i42g2000cwa.googlegroups.com>
Ok, here's the situation:
from the command line, I am typing:
c:\perl d:\someDirName\scriptName.pl
My goal is to figure out the path name where the script is located
(d:\someDirName)
Here is one solution using regular expressions:
my($dirNm, $fileNm) =3D $0 =3D~ m/^(.*\\)(.*)$/;
This will give me the full directory name in $dirNm. Open to
suggestions if there is another way.
--------------------------------------
J=FCrgen Exner wrote:
> [Do not top-post/fullquote; trying to fix]
> dennishancy@eaton.com wrote:
> > dennishancy@eaton.com wrote:
> >> Is there a function in perl that will tell me the directory name of
> >> the currently running script?
> >
> > I have the value "c:\someDirName\scriptName.pl" stored in a variable.
>
> Now what the heck are you asking for?
> 1: A function that returns the current working directory?
> 2: A function that returns the path for script?
> 3: The path part from an absolute file name?
>
> Your 'description' could be asking for any of these.
> 1: perldoc CWD
> 2: perldoc FindBin
> 3: perldoc File::Basename
>=20
> jue
------------------------------
Date: Tue, 15 Aug 2006 16:40:38 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: current directory name in perl
Message-Id: <ebstnh.12k.1@news.isolution.nl>
dennishancy@eaton.com schreef:
[don't top-post!]
> My goal is to figure out the path name where the script is located
> my($dirNm, $fileNm) = $0 =~ m/^(.*\\)(.*)$/;
That would fail with "perl D:../scriptName.pl".
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Tue, 15 Aug 2006 14:57:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: current directory name in perl
Message-Id: <khlEg.13331$hH1.7169@trnddc08>
[Do you still instist on TOFU? Bad!]
dennishancy@eaton.com wrote:
> Ok, here's the situation:
>
> from the command line, I am typing:
> c:\perl d:\someDirName\scriptName.pl
>
> My goal is to figure out the path name where the script is located
> (d:\someDirName)
As has been said before several times: The FindBin module will get you that
information
perldoc FindBin
> Here is one solution using regular expressions:
> my($dirNm, $fileNm) = $0 =~ m/^(.*\\)(.*)$/;
> This will give me the full directory name in $dirNm. Open to
> suggestions if there is another way.
But here you are trying to solve a different question: Given an absolute
file name, how to extract the path?
As has been said before several times: The File::Basename module will get
you that information.
perldoc File::Basename
Those two questions are not identical
jue
------------------------------
Date: Tue, 15 Aug 2006 14:58:09 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: current directory name in perl
Message-Id: <Xns98206F9668671asu1cornelledu@132.236.56.8>
"dennishancy@eaton.com" <dennishancy@eaton.com> wrote in
news:1155651988.791384.323350@i42g2000cwa.googlegroups.com:
> Ok, here's the situation:
>
> from the command line, I am typing:
>
> c:\perl d:\someDirName\scriptName.pl
Really? You have the perl binary installed in the root directory of the C
drive?
> My goal is to figure out the path name where the script is located
> (d:\someDirName)
perldoc FindBin
> Here is one solution using regular expressions:
>
>
> my($dirNm, $fileNm) = $0 =~ m/^(.*\\)(.*)$/;
perldoc File::Basename
Anyway, I am probably talking to myself, you are still top-posting, full-
quoting, and ignoring the obvious solutions given (I don't think GG has
killfile functionality), so here you go: *PLONK*
Sinan
------------------------------
Date: Tue, 15 Aug 2006 11:01:49 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: current directory name in perl
Message-Id: <g69ac6682le.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 15 Aug 2006, dennishancy@eaton.com wrote:
> Ok, here's the situation:
>
> from the command line, I am typing:
>
> c:\perl d:\someDirName\scriptName.pl
>
>
>
> My goal is to figure out the path name where the script is located
> (d:\someDirName)
>
>
> Here is one solution using regular expressions:
>
>
> my($dirNm, $fileNm) = $0 =~ m/^(.*\\)(.*)$/;
>
>
> This will give me the full directory name in $dirNm. Open to
> suggestions if there is another way.
I think you want to use File::Basename:
perldoc File::Basename
It's really simple, just use fileparse(), or basename() and dirname()
separately in the example above.
Ted
------------------------------
Date: Tue, 15 Aug 2006 14:10:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: File does not exist: /home/virtual/site2/fst/var/www/html/favicon.ico--?
Message-Id: <IBkEg.7560$5M.1206@trnddc02>
rallabs@adelphia.net wrote:
> My error log contains multiple instances of the line
> File does not exist: /home/virtual/site2/fst/var/www/html/favicon.ico
> [...] Does anyone know what this is about?
Sure. That file does not exist.
jue
------------------------------
Date: Tue, 15 Aug 2006 15:23:37 GMT
From: Jeff <dont_bug_me@all.uk>
Subject: LWP post with cookie syntax
Message-Id: <ZFlEg.8192$xp2.2965@newsread1.news.pas.earthlink.net>
I need to use LWP to send a post that has a Set-Cookie header.
It looks to me something like this:
require LWP;
my $browser = LWP::UserAgent->new;
my
$response=$browser->post('/some/where/somescript.pl',$post_ref,'Set-Cookie'
=>'some_cookie=some_value');
Except, not that!
I had tried adding this before the post line:
$browser->cookie_jar({'some_cookie'=>'some_value'}); but it appears
that does not get added to the header.
What have I done wrong?
Jeff
------------------------------
Date: Tue, 15 Aug 2006 11:51:30 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: LWP post with cookie syntax
Message-Id: <x7r6zingjh.fsf@mail.sysarch.com>
>>>>> "J" == Jeff <dont_bug_me@all.uk> writes:
J> I need to use LWP to send a post that has a Set-Cookie header.
J> It looks to me something like this:
J> require LWP;
J> my $browser = LWP::UserAgent->new;
J> my
J> $response=$browser->post('/some/where/somescript.pl',$post_ref,'Set-Cookie'
J> =>'some_cookie=some_value');
cookie headers are more than just key=value. that is why there is a
cookie jar object.
J> Except, not that!
J> I had tried adding this before the post line:
J> $browser->cookie_jar({'some_cookie'=>'some_value'}); but it appears
J> that does not get added to the header.
i don't know that method but this is documented and works (will need
changes for your needs):
# this is a way of getting old cookies in this project. change to your
# needs
my $cookie_jar = $self->{'cookie_jar'} ||=
( $self->{'cookies_text'} ?
Load( $self->{'cookies_text'} ) :
HTTP::Cookies->new() ) ;
$cookie_jar->add_cookie_header( $request ) ;
my $response = $ua->request( $request ) ;
$cookie_jar->extract_cookies( $response ) ;
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: 15 Aug 2006 08:55:05 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: LWP post with cookie syntax
Message-Id: <1155657305.515848.35410@p79g2000cwp.googlegroups.com>
Jeff wrote:
> I need to use LWP to send a post that has a Set-Cookie header.
>
> It looks to me something like this:
>
> require LWP;
> my $browser = LWP::UserAgent->new;
>
> my
> $response=$browser->post('/some/where/somescript.pl',$post_ref,'Set-Cookie'
> =>'some_cookie=some_value');
>
> Except, not that!
No, definately not that. Can you explain what part of the
documentation (which you did read, right?) led you to believe that was
the correct syntax for a post() method?
=================================
$ua->post( $url, \%form )
$ua->post( $url, \@form )
$ua->post( $url, \%form, $field_name => $value, ... )
This method will dispatch a POST request on the given $url, with %form
or @form providing the key/value pairs for the fill-in form content.
Additional headers and content options are the same as for the get()
method.
=================================
> I had tried adding this before the post line:
>
> $browser->cookie_jar({'some_cookie'=>'some_value'}); but it appears
> that does not get added to the header.
>
> What have I done wrong?
Not read the documentation. Please do read the docs for LWP::UserAgent
and HTTP::Cookies. In particular, you will see that passing a hash-ref
to the cookie_jar() method is a shortcut for creating a new
HTTP::Cookies object, passing that hashref as a constructor. When you
then read the HTTP::Cookies documentation, you will see that you cannot
simply set a key/value pair in that constructor. You have to construct
it using a file in which to store the cookies, and then add a cookie to
the cookie jar. THEN you can pass that cookie jar to the cookie_jar()
method.
If you have both modules installed, you can read the documentation by
typing each of the following at your command line:
perldoc LWP::UserAgent
perldoc HTTP::Cookies
Paul Lalli
------------------------------
Date: 15 Aug 2006 17:49:15 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: My multipost-detecting usenet bot (David Filmer)
Message-Id: <Xns98208269D47CCcastleamber@130.133.1.4>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On 15 Aug 2006 00:01:10 GMT, John Bokma <john@castleamber.com> wrote:
>
>>which also explains crossposting, which is the recommended way to post
> ^^^^^
> ^^^^^ [*]
>>a single message to more then one group, if such is really needed.
>
> [*] is also frowned upon, but
Not really, but it's abused a lot, and it's the abuse that's frowned upon.
Note the "really needed", a lot of crossposters get that wrong ;-)
But you're right, maybe it should made a bit stronger.
Personally I don't have a problem with a crosspost if it's really needed
*and* has the follow-up to header set to the most appropriate group. Also
the number of groups should be limited in most cases.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 15 Aug 2006 17:51:51 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: My multipost-detecting usenet bot (David Filmer)
Message-Id: <Xns982082DAE5648castleamber@130.133.1.4>
"Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
> On 08/14/2006 05:28 PM, usenet@DavidFilmer.com wrote:
>> [...]
>> If I've angered or annoyed anyone, I do apologize. I had no such
>> intent.
>> [...]
>
> Thank you Mr. Filmer. I can see how the 'bot would reduce a
> lot of work, but, as you've acknowledged, its message was a
> little long and harsh.
>
> Whatever you do, please don't release the code. Hip-ç-rime
> would make usenet a nightmare with it.
Uhm? People who need such programs can just download them including
software to auto-cancel and repost massively.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 15 Aug 2006 10:35:38 -0700
From: "d2rk" <d2rk@yandex.ru>
Subject: NetInquire
Message-Id: <1155663338.128212.104840@74g2000cwt.googlegroups.com>
I have problem. After transfer site from hosting to dedicated server,
one of the scripts stoped working:
== script.pl ===================================================
($data,$error)=inquiry("http://www.hostname.com/dir/file.html");
use LWP::Simple;
use LWP::UserAgent;
use URI::URL;
use HTTP::Request;
use HTTP::Headers;
sub inquiry
{
my $uri=shift;
my $hdrs=new HTTP::Headers(Accept=>'text/html');
my $ua =new LWP::UserAgent;
$ua->agent("Robot");
$ua->timeout(10);
my $response=$ua->request(HTTP::Request->new(GET=>$uri,$hdrs));
if( $response->is_success ){ return
($response->content,$response->content_length) }
else{ return (0,$response->status_line) }
}
================================================================
Result: 500 Can't connect to www.hostname.com:80 (Bad hostname
'www.hostname.com')
Script is working on other server's, telnet too.
Some people say, that this is due to the fact that DNS is tuned wrong.
------------------------------
Date: Tue, 15 Aug 2006 18:39:48 +0100
From: Brian Wakem <no@email.com>
Subject: Re: NetInquire
Message-Id: <4kef6kFbs0l0U1@individual.net>
d2rk wrote:
> I have problem. After transfer site from hosting to dedicated server,
> one of the scripts stoped working:
>
> == script.pl ===================================================
>
> ($data,$error)=inquiry("http://www.hostname.com/dir/file.html");
>
> use LWP::Simple;
> use LWP::UserAgent;
> use URI::URL;
> use HTTP::Request;
> use HTTP::Headers;
>
> sub inquiry
> {
> my $uri=shift;
> my $hdrs=new HTTP::Headers(Accept=>'text/html');
> my $ua =new LWP::UserAgent;
> $ua->agent("Robot");
> $ua->timeout(10);
> my $response=$ua->request(HTTP::Request->new(GET=>$uri,$hdrs));
> if( $response->is_success ){ return
> ($response->content,$response->content_length) }
> else{ return (0,$response->status_line) }
> }
>
> ================================================================
>
> Result: 500 Can't connect to www.hostname.com:80 (Bad hostname
> 'www.hostname.com')
>
> Script is working on other server's, telnet too.
>
> Some people say, that this is due to the fact that DNS is tuned wrong.
It is either a DNS error or the domain doesn't exist.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Tue, 15 Aug 2006 10:21:58 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Parsing text to array
Message-Id: <g69lkpq84ft.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 14 Aug 2006, anno4000@radom.zrz.tu-berlin.de wrote:
> I also think that deciding which of map() and grep() is more fundamental
> is besides the point. They are builtins that make new lists of given
> lists. sort() is a third one, and splice() could also be mentioned.
> Other list-transformers, though not named functions, are hash-, array-
> and list slices. Their common message is that arrays and/or lists can
> be treated as the unit of computation instead of the scalars that make
> them up.
>
> Where applicable this simplifies the thought process and along with it
> the program. The simplification is fundamental and usually results in
> tight code, meaning a lot of stuff happens in just a few lines.
>
> It also means that if you have understood a few lines, you have understood
> a lot about the program. Tight code, in this sense, *will* take a few
> extra reading skills and may still take more time to read than that many
> lines of more pedestrian broader code. Some of the required techniques,
> like reading parts of the code back-to-front, are admittedly awkward.
>
> This is offset by the fundamental simplification that comes with working
> with aggregates as units. Since the unit of computation is more complex
> (hiding details), the thought process is simplified.
>
> That is why I think this programming style is *good* style in the
> sense of making it easier to understand the program. Where applicable.
Those are excellent points, Anno. In my experience map() and grep()
are very difficult for beginners, but that in no way takes away from
their general utility and beauty. In fact a while ago I wrote a
beginner-oriented article on functional programming in Perl ("it's
just as good if we fake it"):
http://www-128.ibm.com/developerworks/opensource/library/l-road4.html
which tries to explain FP gently (working up to the Schwartzian and
Guttman-Rosler transforms). Whether map() and grep() are fundamental
is, I think, a matter of personal opinion, but we can all agree they
are not easy to master.
Sadly, my second example in the article uses map() for the side
effect. The shame!
Anyhow, I'm just saying that I do agree with you, but think it's good
to either comment well or consider a simpler approach when you're
putting together FP and a beginner :)
Ted
------------------------------
Date: 15 Aug 2006 11:00:40 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: perl dbi driver for microsoft sql?
Message-Id: <1155664840.081404.242760@h48g2000cwc.googlegroups.com>
where do i find dbi driver for micrsoft sql?
------------------------------
Date: Tue, 15 Aug 2006 17:14:59 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Proposal: extending perldoc -f
Message-Id: <ebsvej$1vgu$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<usenet@DavidFilmer.com>], who wrote in article <1155376557.087963.74700@m79g2000cwm.googlegroups.com>:
> IMHO, EACH AND EVERY Perl keyword should resolve by "perodoc -f" even
> if it simply points to a more relevant perldoc (as you, Michelle,
> wisely imply).
Why do it halfway? IMO, `perldoc -f' should show the docs, not
pointers to docs.
Yours,
Ilya
------------------------------
Date: 15 Aug 2006 17:46:40 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <Xns982081F9F3CAFcastleamber@130.133.1.4>
usenet@DavidFilmer.com wrote:
> John Bokma wrote:
>> "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
>> > I don't give kudos to Bokma too often, but I do right now.
>> > Thanks John Bokma.
>>
>> You're welcome ;-)
>
> Group hug!!!
Aaaawwww :-D
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: Tue, 15 Aug 2006 14:09:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: string and time question
Message-Id: <8AkEg.7558$5M.4734@trnddc02>
a wrote:
> 1> Let say,
> my $str = "abcd";
> How can I do the following,
> $str = $str + 1 make $str becomes "abce"?
Auto-increment works on strings jsut fine:
$str++
> 2> Is it possible to do the following?
> for(k=1;k<9;k++){
> do something
> wait for 10second
> }
Sure:
for my $k (1..9){
do something;
sleep 10;
}
jue
------------------------------
Date: 15 Aug 2006 10:25:05 -0700
From: Zyad.Tamimi@gmail.com
Subject: Website Interface
Message-Id: <1155662704.946878.103150@i42g2000cwa.googlegroups.com>
Hi all,
Hopefully somebody can help me with this relatively simple task =)
I have a list of names and what I am attempting to do is connect to a
website and search for all the names in the websites directory. Is
there a simple module in CPAN that can help me do this?
if you need further clarification let me know.
Thanks in advance!
Zyad
------------------------------
Date: 15 Aug 2006 10:46:15 -0700
From: usenet@DavidFilmer.com
Subject: Re: Website Interface
Message-Id: <1155663974.991820.276660@i3g2000cwc.googlegroups.com>
Zyad.Tamimi@gmail.com wrote:
> I have a list of names and what I am attempting to do is connect to a
> website and search for all the names in the websites directory. Is
> there a simple module in CPAN that can help me do this?
Maybe so... People try to do this to my webserver all the time ;-)
Of course, any halfway-configured webserver won't let it happen (and
there's nothing you can do about it, prehaps short of some type of
exploit).
Actually, CPAN has very few programs - it has lots of modules which are
used to build programs. If you think you can go to CPAN and download a
functional program to do something then you are mistaken about how CPAN
really works.
If you can do what you want to do from a browser, you can (probably)
use WWW::Mechanize to do it in Perl. If the webserver is so poorly
configured that it will reveal its directory and file structure (say,
by omitting the name of the index document) then you can easily slurp
that info. But otherwise, forget it.
--
David Filmer (http://DavidFilmer.com)
------------------------------
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 9608
***************************************