[28219] in Perl-Users-Digest
Perl-Users Digest, Issue: 9583 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 9 18:05:53 2006
Date: Wed, 9 Aug 2006 15:05:08 -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 Wed, 9 Aug 2006 Volume: 10 Number: 9583
Today's topics:
Re: 50+ bits of arithmetic in a 32-bit bag xhoster@gmail.com
@_ deprecated? <broeisito@gmail.com>
Re: @_ deprecated? xhoster@gmail.com
Re: @_ deprecated? <john@castleamber.com>
Re: @_ deprecated? <broeisito@gmail.com>
Re: Array::Diff help understanding it <hpbenton@scripps.edu>
Re: Array::Diff help understanding it <hpbenton@scripps.edu>
Re: Array::Diff help understanding it <mritty@gmail.com>
Re: Cannot authenticate to NNTP server with Net::NNTP a usenet@DavidFilmer.com
Re: Cannot authenticate to NNTP server with Net::NNTP a <rvtol+news@isolution.nl>
Re: convert structured strings to possibly deep hash of <DJStunks@gmail.com>
Re: convert structured strings to possibly deep hash of <1usa@llenroc.ude.invalid>
Re: convert structured strings to possibly deep hash of <uri@stemsystems.com>
How to send command line options into test scripts? <yusufm@gmail.com>
Re: How to send command line options into test scripts? <mgarrish@gmail.com>
Re: How to send command line options into test scripts? <yusufm@gmail.com>
Re: How to use OO and package? <john@castleamber.com>
LWP seems to hang <mike.smith@amd.com>
Re: LWP seems to hang <john@castleamber.com>
match 2D patterns with perl <fangqq@gmail.com>
Re: match 2D patterns with perl <john@castleamber.com>
Re: Read socket using both <> and sysread() <uri@stemsystems.com>
Re: Read socket using both <> and sysread() <nospam-abuse@ilyaz.org>
Re: Read socket using both <> and sysread() <uri@stemsystems.com>
replace text with "/" in file quickcur@yahoo.com
Re: replace text with "/" in file <mritty@gmail.com>
Re: replace text with "/" in file <1usa@llenroc.ude.invalid>
Re: replace text with "/" in file <tadmc@augustmail.com>
Re: Solved:: Printing Hash Marks During File Download <hlarons@yahoo.com>
Re: Test::Harness and test values. <yusufm@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 09 Aug 2006 18:38:35 GMT
From: xhoster@gmail.com
Subject: Re: 50+ bits of arithmetic in a 32-bit bag
Message-Id: <20060809144758.952$gN@newsreader.com>
mailbox@cpacker.org wrote:
> Our implementation of Perl under AIX
> doesn't support 64-bit integer arithmetic;
> so says "perl -V".
>
> A search of these newsgroups turned up a
> test of this fact as follows:
>
> $two += 2;
> $x = $two ** 63 + 25;
> $y = $two ** 63 + 30;
> if($x == $y) {print "64 bits not supported\n"}
> else {print "64 bits supported\n"}
>
> I found that it would give an affirmative
> result if I used up to 55 instead of 63.
> This suggests that a floating-point
> format with a seven-byte fraction is
> being invoked. Perhaps that's the native
> floating-point of the AIX box?
> At any rate, barring followups to the
> contrary, I'll assume that I can treat
> our Perl as having a 55-bit integer
> arithmetic capability for accumulating
> sums, at least.
That is a poor assumption. Just because the $x and $y are not identical
does not mean that they are what they are supposed to be.
On my machine, your test also passes for 55, but a more rigorous test
does not:
$ perl -le '$foo=55; print((2**$foo+30)-(2**$foo+25))'
8
I'm pretty sure that 5 != 8, so 55 bits is right out. On my machine, 52 is
high as I would go.
$ perl -le '$foo=52; foreach (1..1e7) { my $y =
((2**$foo+$_+1)-(2**$foo+$_));
die $_ unless $y == 1}'
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 9 Aug 2006 13:59:41 -0700
From: "broeisito@gmail.com" <broeisito@gmail.com>
Subject: @_ deprecated?
Message-Id: <1155157181.734841.226140@b28g2000cwb.googlegroups.com>
Hello,
I wrote the following code to read what processor is in a linux box.
But I get the following error:
Use of implicit split to @_ is deprecated at cpu.pl line 17.
Can someone possibly explain to me what I'm doing wrong here?
Here is the code.
================== begin ======================
#!/usr/bin/perl
use strict;
use warnings;
my $CPU_FILE = "/proc/cpuinfo";
if(-e $CPU_FILE && -r $CPU_FILE && -f $CPU_FILE)
{
open CPU, $CPU_FILE;
}
while(<CPU>)
{
if(/model.name/)
{
split;
print "The processor is an $_[3] $_[4] $_[5] running at $_[7]\n";
}
}
close CPU;
================== end ======================
BTW... this is my first perl code... so don;t flame my programming
style yet!!
Cheers,
Broeisi
------------------------------
Date: 09 Aug 2006 21:07:57 GMT
From: xhoster@gmail.com
Subject: Re: @_ deprecated?
Message-Id: <20060809171722.203$DS@newsreader.com>
"broeisito@gmail.com" <broeisito@gmail.com> wrote:
> Hello,
>
> I wrote the following code to read what processor is in a linux box.
> But I get the following error:
>
> Use of implicit split to @_ is deprecated at cpu.pl line 17.
> Can someone possibly explain to me what I'm doing wrong here?
Yes, you are not using the documentation properly.
from perldoc perldiag:
Use of implicit split to @_ is deprecated
(D deprecated) It makes a lot of work for the compiler
when you clobber a subroutine's argument list, so it's
better if you assign the results of a split() explic-
itly to an array (or list).
Cheers,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 9 Aug 2006 21:24:49 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: @_ deprecated?
Message-Id: <Xns981AA6F63AA55castleamber@130.133.1.4>
"broeisito@gmail.com" <broeisito@gmail.com> wrote:
> Hello,
Don't scare us with a wrong subject :-)
> I wrote the following code to read what processor is in a linux box.
> But I get the following error:
>
> Use of implicit split to @_ is deprecated at cpu.pl line 17.
So the implicit split to @_ is deprecated.
^^^^^^^^^^^^^^
> Can someone possibly explain to me what I'm doing wrong here?
>
> Here is the code.
>
> ================== begin ======================
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $CPU_FILE = "/proc/cpuinfo";
>
> if(-e $CPU_FILE && -r $CPU_FILE && -f $CPU_FILE)
> {
> open CPU, $CPU_FILE;
> }
You *don't* check what open returns. Moreover, de rest of your code
assumes it always works.
replace the if {} with:
-f $CPU_FILE or die "'$CPU_FILE' is not a regular file";
open my $fh, $CPU_FILE or die "Can't open '$CPU_FILE' for reading: $!";
> while(<CPU>)
> {
> if(/model.name/)
> {
> split;
The problem is here, you split to @_, which is deprecated, see:
perldoc -f split
> print "The processor is an $_[3] $_[4] $_[5] running at
> $_[7]\n";
> }
> }
I would do the while loop like:
while ( my $line = <$fh> ) {
$line =~ /model\.name/ or next;
my @data = split /\s+/, $line; # not sure about the pattern
print "The processor .. $data[ 0 ] $data[ 1 ] ...\n";
}
close $fh or die "Can't close '$CPU_FILE' after reading: $!";
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 9 Aug 2006 14:28:59 -0700
From: "broeisito@gmail.com" <broeisito@gmail.com>
Subject: Re: @_ deprecated?
Message-Id: <1155158939.039124.75730@n13g2000cwa.googlegroups.com>
Guys,
Thanks a lot for your answers.
I will make better use of the documentation.
I'm just new at perl.
I will make the changes to my script.
Thanks a lot.
Cheers,
Broeisi
John Bokma wrote:
> "broeisito@gmail.com" <broeisito@gmail.com> wrote:
>
> > Hello,
>
> Don't scare us with a wrong subject :-)
>
> > I wrote the following code to read what processor is in a linux box.
> > But I get the following error:
> >
> > Use of implicit split to @_ is deprecated at cpu.pl line 17.
>
> So the implicit split to @_ is deprecated.
> ^^^^^^^^^^^^^^
>
>
> > Can someone possibly explain to me what I'm doing wrong here?
> >
> > Here is the code.
> >
> > ================== begin ======================
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > my $CPU_FILE = "/proc/cpuinfo";
> >
> > if(-e $CPU_FILE && -r $CPU_FILE && -f $CPU_FILE)
> > {
> > open CPU, $CPU_FILE;
> > }
>
> You *don't* check what open returns. Moreover, de rest of your code
> assumes it always works.
>
> replace the if {} with:
>
> -f $CPU_FILE or die "'$CPU_FILE' is not a regular file";
> open my $fh, $CPU_FILE or die "Can't open '$CPU_FILE' for reading: $!";
>
> > while(<CPU>)
> > {
> > if(/model.name/)
> > {
> > split;
>
> The problem is here, you split to @_, which is deprecated, see:
> perldoc -f split
>
> > print "The processor is an $_[3] $_[4] $_[5] running at
> > $_[7]\n";
> > }
> > }
>
> I would do the while loop like:
>
> while ( my $line = <$fh> ) {
>
> $line =~ /model\.name/ or next;
>
> my @data = split /\s+/, $line; # not sure about the pattern
> print "The processor .. $data[ 0 ] $data[ 1 ] ...\n";
> }
>
> close $fh or die "Can't close '$CPU_FILE' after reading: $!";
>
>
> --
> John Bokma Freelance software developer
> &
> Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 9 Aug 2006 11:24:58 -0700
From: "PB0711" <hpbenton@scripps.edu>
Subject: Re: Array::Diff help understanding it
Message-Id: <1155147898.435120.10030@n13g2000cwa.googlegroups.com>
:) :) :)
Thank you for your helpful relply. I am happy to say that I am now on
my linux machine and not remembering my scribles from my paper and
posting from windoze.
"
while (my $line=<Prot>){
if ($line=~/<prot_desc>(.*)<\/prot_desc>/){ # finds protein name
$pro_name=$1;
@pep=-1;
}elsif($line=~/<pep_seq>(.*)<\/pep_seq>/){# finds pep sequence
@pep=uniq(@pep);
push (@pep, $1);
}
$HOA_protein{$pro_name}=[@pep]; # makes a HOA
}
#there is another one of these for @gene hense where it comes from
my $out_file="maggieXML.csv";
open OUT, ">$out_file" or die "Cannot write to file,$!\n";
for $pro_name(keys %HOA_protein){
my $con = Array::Diff->diff($HOA_protein{$pro_name},
$HOA_gene{$gene_name});
print OUT "$pro_name,@{$con->added()}\n";
print OUT "Present in Gene, @{$con->deleted()}\n";
}
"
Currently, with the line "print OUT "$pro_name,@{$con->added()}\n";" I
am still getting a reference as my output. If there is another module
that you can recommend for me I would be happy to use that as well.
------------------------------
Date: 9 Aug 2006 11:39:44 -0700
From: "PB0711" <hpbenton@scripps.edu>
Subject: Re: Array::Diff help understanding it
Message-Id: <1155148783.818780.57920@h48g2000cwc.googlegroups.com>
PB0711 wrote:
> :) :) :)
> Thank you for your helpful relply. I am happy to say that I am now on
> my linux machine and not remembering my scribles from my paper and
> posting from windoze.
> "
> while (my $line=<Prot>){
> if ($line=~/<prot_desc>(.*)<\/prot_desc>/){ # finds protein name
> $pro_name=$1;
> @pep=-1;
> }elsif($line=~/<pep_seq>(.*)<\/pep_seq>/){# finds pep sequence
> @pep=uniq(@pep);
> push (@pep, $1);
> }
> $HOA_protein{$pro_name}=[@pep]; # makes a HOA
> }
> #there is another one of these for @gene hense where it comes from
> my $out_file="maggieXML.csv";
> open OUT, ">$out_file" or die "Cannot write to file,$!\n";
>
> for $pro_name(keys %HOA_protein){
> my $con = Array::Diff->diff($HOA_protein{$pro_name},
> $HOA_gene{$gene_name});
> print OUT "$pro_name,@{$con->added()}\n";
> print OUT "Present in Gene, @{$con->deleted()}\n";
> }
> "
> Currently, with the line "print OUT "$pro_name,@{$con->added()}\n";" I
> am still getting a reference as my output. If there is another module
> that you can recommend for me I would be happy to use that as well.
Agh, put a space in between " print OUT "$pro_name,
@{$con->added()}\n"; " name and the @{$....
Thanks
------------------------------
Date: 9 Aug 2006 11:42:55 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Array::Diff help understanding it
Message-Id: <1155148974.945723.50920@i42g2000cwa.googlegroups.com>
PB0711 wrote:
> :) :) :)
> Thank you for your helpful relply.
You're welcome. You can best show your gratefulness by following my
requests in my first reply. First, read the Posting Guidelines, and
follow them. Specifically, Quote the material you are reply to - AFTER
trimming it down to the relevant bits, and beging your new post below
that material. Second, post a SHORT but COMPLETE script *that we can
run* by copy and pasting. Third, show the input and output of the
script. Without that information, I have no advice for you; I cannot
tell what parts of your script are logic errors, what parts are getting
bad data, etc.
Paul Lalli
------------------------------
Date: 9 Aug 2006 11:12:01 -0700
From: usenet@DavidFilmer.com
Subject: Re: Cannot authenticate to NNTP server with Net::NNTP authinfo()
Message-Id: <1155147121.069717.312630@m79g2000cwm.googlegroups.com>
Dr.Ruud wrote:
> print '=> code:', $nntp->code, "\n" ;
> print '=> mesg:', $nntp->message, "\n" ;
Hmmm. Where did you dig these methods up? They're not in the module's
perldocs...
Even so, neither the code nor the messages seem especially useful...
Failure:
=> code:599
=> mesg:Connection closed
Success:
=> code:230
=> mesg:New news follows.
I don't have my NNTP secret decoder ring handy, so I'm not sure if a
code 599 gives any indication of WHY it failed, but the message is not
very helpful. I wouldn't consider this information on-par with what
would normally be expected of $!
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Wed, 9 Aug 2006 20:36:10 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Cannot authenticate to NNTP server with Net::NNTP authinfo()
Message-Id: <ebdh2j.1go.1@news.isolution.nl>
usenet@DavidFilmer.com schreef:
> Dr.Ruud:
>> print '=> code:', $nntp->code, "\n" ;
>> print '=> mesg:', $nntp->message, "\n" ;
>
> Hmmm. Where did you dig these methods up?
NNTP.pm etc.
> Even so, neither the code nor the messages seem especially useful...
$nntp->newnews or die $nntp->code ." ". $nntp->message ;
There can be a better way; consult clp.modules (I x-posted) or the
author.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 9 Aug 2006 11:18:32 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: convert structured strings to possibly deep hash of hashes
Message-Id: <1155147511.956018.53320@p79g2000cwp.googlegroups.com>
Michele Dondi wrote:
> On 9 Aug 2006 05:31:53 -0700, "Brian McCauley" <nobull67@gmail.com>
> wrote:
>
> >> my $last=\%dirhash;
> >> $last=$last->{$_} ||= {} for split qr|/|;
> >
> >I generally prefer to avoid the extra level of empty hash wth a double
> >reference and autovivification.
> >
> >my $last=\\%dirhash;
> >$last=\$$last->{$_} for split qr|/|;
>
> Cool! Hadn't thought of it and I was just thinking: I wish perl would
> autovivify this too...
you two are too clever... :)
-jp
------------------------------
Date: Wed, 09 Aug 2006 18:57:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: convert structured strings to possibly deep hash of hashes
Message-Id: <Xns981A9855E8DACasu1cornelledu@127.0.0.1>
anno4000@radom.zrz.tu-berlin.de wrote in news:4jum1bF9svqfU1
@news.dfncis.de:
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
>> Uri Guttman <uri@stemsystems.com> wrote in
>> news:x7psf9apgt.fsf@mail.sysarch.com:
>>
>> > i have similar code in my autoviv tutorial at:
>> >
>> > http://sysarch.com/Perl/autoviv.txt
>>
>> Looking at your deep_exists sub:
>>
>> sub deep_exists {
...
>>
>> return 0 unless exists( $hash_ref->{$key} ) ;
>> # ^^^^^^^^
>> # Shouldn't this be a plain return ?
>> #
>
> Absolutely not!
...
> If you called deep_exists in a map like this:
>
> my @res = map deep_exists( $_, @keys), @hashes;
>
> you'd expect an array as long as @hashes filled with true and
> false values, not an array of only true values, as many as were
> returned.
Ah-a! It makes a lot of sense with the usage example you give above.
I can think of some other usage scenarios where the other way seems to
make sense to me, but since I have never written code that uses a
deep_exists style test, I'll assume that the example you give is the
appropriate case to consider. Thank you for the clarification.
Sinan
--
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: Wed, 09 Aug 2006 16:36:12 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: convert structured strings to possibly deep hash of hashes
Message-Id: <x7lkpx8x4z.fsf@mail.sysarch.com>
>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:
ASU> anno4000@radom.zrz.tu-berlin.de wrote in news:4jum1bF9svqfU1
ASU> @news.dfncis.de:
>> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
>>> Uri Guttman <uri@stemsystems.com> wrote in
>>> news:x7psf9apgt.fsf@mail.sysarch.com:
>>>
>>> > i have similar code in my autoviv tutorial at:
>>> >
>>> > http://sysarch.com/Perl/autoviv.txt
>>>
>>> Looking at your deep_exists sub:
>>>
>>> sub deep_exists {
ASU> ...
>>>
>>> return 0 unless exists( $hash_ref->{$key} ) ;
>>> # ^^^^^^^^
>>> # Shouldn't this be a plain return ?
>>> #
>>
>> Absolutely not!
ASU> ...
>> If you called deep_exists in a map like this:
>>
>> my @res = map deep_exists( $_, @keys), @hashes;
>>
>> you'd expect an array as long as @hashes filled with true and
>> false values, not an array of only true values, as many as were
>> returned.
and that could be fixed by calling scalar on deep_exists.
ASU> Ah-a! It makes a lot of sense with the usage example you give above.
ASU> I can think of some other usage scenarios where the other way
ASU> seems to make sense to me, but since I have never written code
ASU> that uses a deep_exists style test, I'll assume that the example
ASU> you give is the appropriate case to consider. Thank you for the
ASU> clarification.
the issue of what to return for boolean is split. i currently prefer
plain return as in stem it is needed in message delivery to denote NO
VALUE returned as those methods are called in list context. return undef
is a legit return and will cause a return message sent back whereas
plain return won't.
if you call something as in the map case above or in an arg list and do
a plain return you get an empty list which will be thrown away. so some
coders claim the sub should handle that and return a scalar value or a
real undef. i say the caller should force the scalar context if they
want a scalar value in a list context. the caller knows more about what
they want and they can control things with scalar. what if you did want
an empty list when assigning to an array and not a single entry with
undef? the caller cannot fix that without a special case checking for
just undef in the first slot. so i say my way of using a plain return is
more flexible and puts the onus on the caller to do the correct thing
with the result. plain return was designed to return undef in scalar and
() in list so it would be false in both scalar and list contexts. just
using scalar() will make that work in a list context and is clearer to
the reader that you are expecting a scalar (boolean) there.
now, i wrote that tutorial a long time ago and that code isn't something
i use. i would probably keep a literal false there if i used it since it
only can return a boolean but i am also leaning to a plain return due to
my reasoning above. in my production code i always use plain return (as
is required in stem).
but this was a good argument for now i have logical backing for my
answer. a caller can use scalar in a list context to handle a plain
return but there is no easy way to fix the problem of a literal undef
boolean returned to an array.
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: 9 Aug 2006 12:25:00 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: How to send command line options into test scripts?
Message-Id: <1155151499.984469.307650@h48g2000cwc.googlegroups.com>
Hi,
Does anyone know how to send command line options into test scripts
from prove?
For instance, I want to call the test file "t" with the options:
--log somefile --output=true
but I can't seem to find out how to do it from prove. I tried using the
$Test::Harness::switches var, but that does not seem to do it.
I didn't post any code because this is not a code question.
------------------------------
Date: 9 Aug 2006 13:18:30 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155154710.378177.267750@m73g2000cwd.googlegroups.com>
yusuf wrote:
>
> Does anyone know how to send command line options into test scripts
> from prove?
>
>
> I didn't post any code because this is not a code question.
Then it's not a question to post to a perl coding group, is it?
Matt
------------------------------
Date: 9 Aug 2006 13:43:51 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155156231.035801.146730@n13g2000cwa.googlegroups.com>
> Then it's not a question to post to a perl coding group, is it?
But its a perl question right? Which group should it go to?
------------------------------
Date: 9 Aug 2006 19:50:51 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to use OO and package?
Message-Id: <Xns981A9707FB30Ccastleamber@130.133.1.4>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On 8 Aug 2006 19:10:46 GMT, John Bokma <john@castleamber.com> wrote:
>
>>> http://perlmonks.org/?node_id=559798
>>
>>Just read it really fast, but does the author want something like:
>>
>>
>>my $factory = use Some::Very::Long::But::Unique::Module::Name;
>>my $obj = $factory->new;
>
> Precisely. But it's not the whole story. The whole discussion, along
> with some of the links provided there, is interesting and far from
> trivial.
Yes, I skipped a bit through it, and will read it better later. Thanks.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 9 Aug 2006 12:21:52 -0700
From: "masmith27" <mike.smith@amd.com>
Subject: LWP seems to hang
Message-Id: <1155151312.679360.319880@b28g2000cwb.googlegroups.com>
Hello, I have made a very simple script in perl that uses LWP to visit
a few local webpages. The script has to execute without any user
interaction after the computer has finished booting. When the computer
boots up it starts the script and tries to get the first webpage. The
script then seems to hang after making the request, and setting the
timeout has no effect. The strange part is that if I hit any key a few
times the script then gets the webpage and continues normally.
LWP::Debug gives the following:
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking 127.0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking 0.0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking 0.1 for cookies
HTTP::Cookies::add_cookie_header: Checking .1 for cookies
LWP::UserAgent::send_request: GET https://127.0.0.1:2381/webpage.php
LWP::UserAgent::need_proxy: Not proxied
LWP::Protocol::http::request: ()
and that's where it stops unless I hit a key or two on the keyboard.
This makes me think that for some reason perl is waiting for something
from stdin but there is nothing I can see that would make this the
case. The script works fine after hitting a few keys or after logging
into the system and issuing a command to run the script, but I need it
to run automatically using init.d. Is there a fix for something like
this? Or something I should check? I'm running out of ideas. The
relevant portion of the code is given below.
#!/usr/bin/perl -w
use LWP;
use HTTP::Cookies;
my $browser = LWP::UserAgent->new;
$browser->timeout("15");
$browser->cookie_jar( HTTP::Cookies->new('file' => '/tmp/cookies.lwp',
'autosave' => 1,
));
push @{ $browser->requests_redirectable }, 'POST';
$url = 'https://127.0.0.1:2381/webpage.php
$response = $browser->get($url);
die "Can't get $url -- ", $response->status_line unless
$response->is_success;
------------------------------
Date: 9 Aug 2006 21:13:53 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: LWP seems to hang
Message-Id: <Xns981AA51BDCA85castleamber@130.133.1.4>
"masmith27" <mike.smith@amd.com> wrote:
> #!/usr/bin/perl -w
remove the -w
add:
use strict;
use warnings;
> use LWP;
> use HTTP::Cookies;
>
> my $browser = LWP::UserAgent->new;
>
> $browser->timeout("15");
15 is a number, why do you use "" ?
> $browser->cookie_jar( HTTP::Cookies->new('file' => '/tmp/cookies.lwp',
> 'autosave' => 1,
> ));
note that the '' around file and autosave are not needed thanks to some
magic => does to the LHS.
> push @{ $browser->requests_redirectable }, 'POST';
>
> $url = 'https://127.0.0.1:2381/webpage.php
my $url = ....
> $response = $browser->get($url);
my $response = ...
> die "Can't get $url -- ", $response->status_line unless
> $response->is_success;
I prefer:
$response->is_success or
die " ...... ";
Which I read as: for the next steps it's important that the response is
successfull, otherwise we die.
The "15" might be the cause of your timeout not working.
Also note that you need support for https installed (Crypt::SSLeay for
example) but I assume you have that installed otherwise LWP would
complain.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 9 Aug 2006 13:44:07 -0700
From: "FangQ" <fangqq@gmail.com>
Subject: match 2D patterns with perl
Message-Id: <1155156247.832376.104600@m73g2000cwd.googlegroups.com>
hi
I am doing a very interesting work. The altimate goal is to generate a
new style of bitmap font from an existing one. This involves finding
and replacing 2D patterns.
Here is an example, the original glyph looks like
0000000000000000
1111111111111111
0000000000000000
0011111110000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0011111110000000
0010000010000000
0000000000000000
0000000000000000
0000000000000000
which contains a square-like pattern. I want to change it to
0000000000000000
1111111111111111
0000000000000000
0001111100000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0001111100000000
0000000000000000
0000000000000000
0000000000000000
which has a rounded rectangle. Note that the all-0-regions in the two
glyphs can have other patterns, but I want to keep them the same. Note
2: the edge-lengths of the square pattern could be different from one
to another, one glyph may contain multiple of these square patterns.
here is my question:
1. can I do this maching and replacement easily in perl? can you give
me a short example?
2. if not, what is the best tool for this purpose? (I can always write
loops and exhaust all possible combinations with C or other programming
languages, but I think they are not elegant.)
thanks
Qianqian
------------------------------
Date: 9 Aug 2006 21:30:50 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: match 2D patterns with perl
Message-Id: <Xns981AA7FBD1BDEcastleamber@130.133.1.4>
"FangQ" <fangqq@gmail.com> wrote:
> 1. can I do this maching and replacement easily in perl? can you give
> me a short example?
If you just want to change the 6 indicated 1's to zeroes in each, it's a
piece of cake to do that. But not sure if you want to do that.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: Wed, 09 Aug 2006 16:39:07 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Read socket using both <> and sysread()
Message-Id: <x7hd0l8x04.fsf@mail.sysarch.com>
>>>>> "x" == xhoster <xhoster@gmail.com> writes:
x> Yohan N. Leder <ynleder@nspark.org> wrote:
>> Hello. In the framework of a dialog with an ESMTP server, I would like
>> to alternate some incoming socket reading using <> (when server replies
>> with a single line) and sysread() (when server replies with several
>> lines), is there something to take care with this kind of alternance ?
x> Why not just use read() instead of sysread()?
that works but since the api is the same, all you get is more buffering
with read with no benefits. sockets already have buffering so there is
no need for more in the user space. having done tons of c and socket
stuff before, sysread is my choice as it is just a wrapper around c's
read.
but maybe your point is mixing read with <> and that could work if done
carefully (it is more a protocol and implementation problem then). it is
just not my style so i would never do that.
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: Wed, 9 Aug 2006 20:45:53 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Read socket using both <> and sysread()
Message-Id: <ebdhi1$dps$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Uri Guttman
<uri@stemsystems.com>], who wrote in article <x7hd0lap5i.fsf@mail.sysarch.com>:
> do you know the difference between <> and sysread? the docs or faq
> (not sure where ATM) strongly state that you should never mix them on a
> single handle unless you are extremely sure of what you are doing. the
> problem is that <> uses stdio which will buffer input from the handle
I must object to (details of) this statement:
a) AFAIU: most probably, stdio is not going to be used with
contemporary Perls (should be enabled by a compile option of perl);
nowadays Perl uses its own (and very buggy) buffering routines;
b) Perl core knows perfectly well when an unbuffered operation follows
a buffered one (same as for read/write mixes).
So it is a bug in PerlIO that the necessary seek()s needed on such a
boundary are not performed.
Hope this helps,
Ilya
------------------------------
Date: Wed, 09 Aug 2006 16:55:16 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Read socket using both <> and sysread()
Message-Id: <x7wt9h7hor.fsf@mail.sysarch.com>
>>>>> "IZ" == Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
IZ> [A complimentary Cc of this posting was sent to
IZ> Uri Guttman
IZ> <uri@stemsystems.com>], who wrote in article <x7hd0lap5i.fsf@mail.sysarch.com>:
>> do you know the difference between <> and sysread? the docs or faq
>> (not sure where ATM) strongly state that you should never mix them on a
>> single handle unless you are extremely sure of what you are doing. the
>> problem is that <> uses stdio which will buffer input from the handle
IZ> I must object to (details of) this statement:
IZ> a) AFAIU: most probably, stdio is not going to be used with
IZ> contemporary Perls (should be enabled by a compile option of perl);
IZ> nowadays Perl uses its own (and very buggy) buffering routines;
makes no difference from the point of view of <> vs sysread. i don't
care if it is stdio or perlio, they both buffer.
IZ> b) Perl core knows perfectly well when an unbuffered operation follows
IZ> a buffered one (same as for read/write mixes).
IZ> So it is a bug in PerlIO that the necessary seek()s needed on such a
IZ> boundary are not performed.
hmm, you should know better. this is doing reads on a SOCKET. seek
doesn't apply there so perl would have to trap any sysread calls and
check if there is anything in the buffer and return that and possibly
even do more kernel reads to satisfy the read request size. sounds like
something only you would like. i will stick to pure sysread and do my
own buffering. been doing that for 25 years so it is second nature.
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: 9 Aug 2006 11:05:25 -0700
From: quickcur@yahoo.com
Subject: replace text with "/" in file
Message-Id: <1155146724.972564.164270@i42g2000cwa.googlegroups.com>
Hi, I have a file, in which I have "/home/user/my/good". I would like
to replace all instance to "/opt/somthing". How can I do it with perl?
Thanks,
qq
------------------------------
Date: 9 Aug 2006 11:07:49 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: replace text with "/" in file
Message-Id: <1155146869.455637.317920@p79g2000cwp.googlegroups.com>
quick...@yahoo.com wrote:
> Hi, I have a file, in which I have "/home/user/my/good". I would like
> to replace all instance to "/opt/somthing". How can I do it with perl?
What have you tried so far? How has it failed to work for you?
Read up on regular expressions and the search-and-replace operator at:
perldoc perlretut
You may also be interested in "in-place editing". Search for the -i
option in
perldoc perlrun
Once you've made an attempt, if it doesn't work the way you want, post
a short-but-complete script that demonstrates the problems you're
having.
Paul Lalli
------------------------------
Date: Wed, 09 Aug 2006 19:01:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: replace text with "/" in file
Message-Id: <Xns981A990358D92asu1cornelledu@127.0.0.1>
"Paul Lalli" <mritty@gmail.com> wrote in news:1155146869.455637.317920
@p79g2000cwp.googlegroups.com:
> quick...@yahoo.com wrote:
>> Hi, I have a file, in which I have "/home/user/my/good". I would like
>> to replace all instance to "/opt/somthing". How can I do it with
perl?
>
> What have you tried so far? How has it failed to work for you?
>
> Read up on regular expressions and the search-and-replace operator at:
> perldoc perlretut
>
> You may also be interested in "in-place editing". Search for the -i
> option in perldoc perlrun
>
> Once you've made an attempt, if it doesn't work the way you want, post
> a short-but-complete script that demonstrates the problems you're
> having.
Maybe the OP is not aware that he can write
s{/home/user/my/good}{/opt/somthing}g
that is, use another character than / in the substitution operator.
Still, the OP would be well served to read the docs before posting
again.
Sinan
--
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: Wed, 9 Aug 2006 16:55:58 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: replace text with "/" in file
Message-Id: <slrnedkmfe.kov.tadmc@magna.augustmail.com>
quickcur@yahoo.com <quickcur@yahoo.com> wrote:
> Subject: replace text with "/" in file
If you want to match a literal slash character then you need to either:
escape the slash by putting a backslash character in front of it
or
use a pattern match delimiter that does not appear in your pattern
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 09 Aug 2006 18:09:28 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Re: Solved:: Printing Hash Marks During File Download
Message-Id: <slrnedk96o.g6.hlarons@Beagle.mylocal.net>
On 8 Aug 2006 13:34:21 -0700, usenet@DavidFilmer.com wrote
in comp.lang.perl.misc:
> HaroldWho wrote:
>> BTW, I learned this from perlvar:
>> "Because loading in the IO::Handle class is an expensive operation, you
>> should learn how to use the regular built-in variables."
>
> FWIW, the least expensive option is not always best. See the discussion
> on autoflushing pp224-226 in 'Perl Best Practices' by Damian Conway.
> If you don't have this book, you should (and it's too bad Dr. Conway
> didn't write it 8 years ago so I could have learned good Perl
> programming practices from the beginning).
Thanks for the reference; I don't have it. I've been using Perl Cookbook and
Programming Perl.
HW
--
Powered by Slackware 10.2 Linux -- Kernel 2.6.13
News Reader slrn 0.9.8.1
------------------------------
Date: 9 Aug 2006 12:00:35 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: Re: Test::Harness and test values.
Message-Id: <1155150035.363776.298170@p79g2000cwp.googlegroups.com>
>
> my $all_ok;
>
> eval {
> $all_ok = runtests( @test_programs );
> };
>
> warn "Something bad happened : $@" if $@;
>
> # Go on to print:
>
> print "Onward\n";
>
> __END__
>
> You probably want to use the
> 'prove' utility rather than
> using Test::Harness directly:
I tried it, and it printed out everything fine. So I don't understand
why it didn't print it out before the eval {}, since there doesn't seem
to have been any errors.
------------------------------
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 9583
***************************************