[31744] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3007 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 27 14:09:23 2010

Date: Sun, 27 Jun 2010 11:09:05 -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           Sun, 27 Jun 2010     Volume: 11 Number: 3007

Today's topics:
    Re: Accessing Web Site Files Questions <edgrsprj@ix.netcom.com>
    Re: Accessing Web Site Files Questions <edgrsprj@ix.netcom.com>
    Re: Accessing Web Site Files Questions <edgrsprj@ix.netcom.com>
    Re: Accessing Web Site Files Questions <RedGrittyBrick@SpamWeary.invalid>
    Re: Accessing Web Site Files Questions <edgrsprj@ix.netcom.com>
    Re: Accessing Web Site Files Questions <edgrsprj@ix.netcom.com>
    Re: bulk flush input <willem@turtle.stack.nl>
    Re: bulk flush input <rvtol+usenet@xs4all.nl>
    Re: How to generate random number without replacement? <tadmc@seesig.invalid>
    Re: Proposing a new module: Parallel::Loops <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 26 Jun 2010 21:25:46 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <2e2dneOescQxK7vRnZ2dnUVZ_hudnZ2d@earthlink.com>

"Tad McClellan" <tadmc@seesig.invalid> wrote in message 
news:slrni2c1v8.pie.tadmc@tadbox.sbcglobal.net...

>    perldoc LWP::Simple
> has this as its first example:
>    perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
> That works fine for me.

As I said, I checked multiple documentations including the ActiveState info 
and the Perl FAQ.

That command was one that was tried with both my high speed service, dialup 
service, in a compiled program, from the Windows DOS command line, from the 
Windows Run command line and in a DOS batch file.

It needs to have the following form to run without a format error message:

perl -MLWP::Simple -e "getprint 'http://www.sn.no'"

And the error that I keep getting for that (or any other Web site) is:

500 Can't connect to www.sn.no:80 (Bad hostname 'www.sn.no') 
(URL:http://www.sn.no)

It might be an ActiveState + Widows problem.  Quite often I have trouble 
getting commands to work properly as they appear in the documentation.  It 
frequently takes a while to get the right format.  Then they work fine from 
that point on.

PPM connects properly to the Internet and downloads modules.  So some type 
of command does work.




------------------------------

Date: Sat, 26 Jun 2010 21:35:14 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <zbqdnbSeZYN5JbvRnZ2dnUVZ_vSdnZ2d@earthlink.com>

"Jens Thoms Toerring" <jt@toerring.de> wrote in message 
news:88mb75Fu53U1@mid.uni-berlin.de...

>> use LWP::Simple;
>> LWP::Simple::getprint("http://www.webhost.com/file.txt");
>
> And that should work - it does for me when putting it into a
> Perl script or using e.g.
>
> perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
>
> from the command line. Getting error messages about not being
> able to access the web server could be the result of a mis-
> configured system, that you entered an incorrect URL or that


My browser will read the http://www.sn.nl Web site.  And PPM works.  So my 
system is connecting.  But I keep getting a error that says:

500 Can't connect to www.sn.no:80 (Bad hostname 'www.sn.no')
(URL:http://www.sn.no)

And on occasion some other type of error will appear.

As you proposed, perhaps this is some type of an ActiveState - Windows 
configuration problem.



------------------------------

Date: Sat, 26 Jun 2010 21:48:09 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <Jpudnbvz9Jt3JrvRnZ2dnUVZ_rCdnZ2d@earthlink.com>

"RedGrittyBrick" <RedGrittyBrick@SpamWeary.invalid> wrote in message 
news:Ta-dnd0wOoCH1bvRnZ2dnUVZ7tednZ2d@bt.com...

>>      perl -MLWP::Simple -e 'getprint "http://www.sn.no"'

No variation of that command works in a compiled program or from the command 
line.  The error message is generally:

500 Can't connect to www.sn.no:80 (Bad hostname 'www.sn.no')
(URL:http://www.sn.no)

However, my browser will read that site.  And PPM works.  So that system is 
able to access Web sites.




------------------------------

Date: Sun, 27 Jun 2010 10:59:17 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <LoOdnTcPU5xnvbrRnZ2dnUVZ7o2dnZ2d@bt.com>

On 27/06/2010 03:25, E.D.G. wrote:
> "Tad McClellan" <tadmc@seesig.invalid> wrote in message
> news:slrni2c1v8.pie.tadmc@tadbox.sbcglobal.net...
>
>> perldoc LWP::Simple
>> has this as its first example:
>> perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
>> That works fine for me.
>
>
> perl -MLWP::Simple -e "getprint 'http://www.sn.no'"
>
> And the error that I keep getting for that (or any other Web site) is:
>
> 500 Can't connect to www.sn.no:80 (Bad hostname 'www.sn.no')
> (URL:http://www.sn.no)
>
> It might be an ActiveState + Widows problem. Quite often I have trouble
> getting commands to work properly as they appear in the documentation.
> It frequently takes a while to get the right format. Then they work fine
> from that point on.
>
> PPM connects properly to the Internet and downloads modules. So some
> type of command does work.
>

1) Use nslookup to test Windows' resolution of domain names

C:\> nslookup www.sn.no
Server:  xxxxxxxxxxx
Address:  nnnnnnnnnnnn

Non-authoritative answer:
Name:    sn.no
Address:  85.252.127.171
Aliases:  www.sn.no


2) Check for any proxy settings that are checked for by LWP::Simple (via 
LWP::UserAgent)

C:\> set http
http_proxy=http://1.2.3.4:8080

You can temporarily remove a proxy setting...
C:\> set http_proxy=


-- 
RGB


------------------------------

Date: Sun, 27 Jun 2010 12:37:29 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <7vKdnZkol_LEEbrRnZ2dnUVZ_umdnZ2d@earthlink.com>

"E.D.G." <edgrsprj@ix.netcom.com> wrote in message 
news:OtadnesmsqezEbjRnZ2dnUVZ_u-dnZ2d@earthlink.com...

> use LWP::Simple;
> LWP::Simple::getprint("http://www.webhost.com/file.txt");
>

Problem Solved  -  It was a virus software blocking problem!

       The notes posted in response to my first enquiry provided enough 
information to make it possible to use some logic to determine the nature of 
this problem.

       Since people responded that they were not having any trouble with the 
above Web site access command, since my browser could access Web sites, and 
since the Perl PPM program worked, that suggested that something might be 
blocking my Perl program's access to the Web site.  And that turned out to 
be the case.

       My virus software decided to block that specific Perl application 
without sending me an easily recognizable warning note stating that it was 
doing that.  And after using some logic and determining that that might be 
the case I tried the command on a different computer with different virus 
software.  That one did the same thing.  However, the virus program clearly 
indicated that it was blocking the application.  And I knew how to tell it 
to let the Perl application run.  It worked.  So, now all I need to do is 
get my other virus program to let the application run.  That should not be 
difficult.

       This particular program application is quite important in my opinion. 
And the Newsgroups are important because they can provide people with some 
fresh approaches when they run into a problem like that.  As anyone who does 
much programming knows, there are times when you have a code error that is 
invisible to you for some reason.  An easy solution can be to let someone 
else look at the code.  He or she might spot the error in a few minutes.

Thanks to all for the suggestions.



------------------------------

Date: Sun, 27 Jun 2010 12:53:46 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Accessing Web Site Files Questions
Message-Id: <pp-dnbqCkZW2DbrRnZ2dnUVZ_hydnZ2d@earthlink.com>

"RedGrittyBrick" <RedGrittyBrick@SpamWeary.invalid> wrote in message 
news:LoOdnTcPU5xnvbrRnZ2dnUVZ7o2dnZ2d@bt.com...

>> perl -MLWP::Simple -e "getprint 'http://www.sn.no'"
> 1) Use nslookup to test Windows' resolution of domain names
> 2) Check for any proxy settings that are checked for by LWP::Simple (via

       Thanks for the helpful suggestions.  As one of my other notes 
explained, after hearing from other people that the command worked for them 
and by applying some logic I was able to determine that the command was 
being blocked by my virus software.

       Over the years, each time I have attempted a Perl program application 
to run that was dramatically different from ones I have used in the past it 
took a while to get through a new group of bugs.  And this is the first time 
that I tried to have a Perl program go out on the Internet and read data 
from Web site files.  I have a potentially important freeware program that 
is presently available to government scientists and independent researchers 
around the world.  And I am trying to add a feature to it that will enable 
it to access data files from one of my Web sites and use them in its 
calculations.  The data change each week.  And if people had to keep 
manually downloading the new data they would get tired of doing that and 
probably stop using the program regardless of its value.

       Having run into that blocking problem myself I can now add a note to 
the ReadMe files warning program users to check their virus software if the 
program won't download data for them.



------------------------------

Date: Sun, 27 Jun 2010 09:11:19 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: bulk flush input
Message-Id: <slrni2e5dn.slj.willem@turtle.stack.nl>

Tad McClellan wrote:
) I almost called Willem on the "usually" part, until I re-read
) the "Context" section in
)
)     perldoc perldata
)
)     ...
)
)     User-defined subroutines may choose to care whether they are being
)     called in a void, scalar, or list context.
)
) void context always translates to scalar context for built-in functions.
)
) void context usually translates to scalar context for user-defined functions.

What about map ?

AFAIK, when you call <map> in void context, it turns into a <for> internally.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Sun, 27 Jun 2010 11:42:12 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: bulk flush input
Message-Id: <4c271cf5$0$22920$e4fe514c@news.xs4all.nl>

Willem wrote:

> AFAIK, when you call <map> in void context, it turns into a <for> internally.

Don't think that.

For example, in some older versions of Perl, a map inside a map only 
releases memory in the outsidest map, which can make things horrible.

-- 
Ruud


------------------------------

Date: Sat, 26 Jun 2010 17:26:23 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to generate random number without replacement?
Message-Id: <slrni2cvbp.qv6.tadmc@tadbox.sbcglobal.net>

David Combs <dkcombs@panix.com> wrote:

> I see it 


You see what "it"?


> differently.


Differently from what?


> He's got every right to get pissed off from time to time.


Who "he"?


Please follow the standard practice of quoting some context in followups.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Sat, 26 Jun 2010 21:52:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Proposing a new module: Parallel::Loops
Message-Id: <ss5if7-o5p1.ln1@osiris.mauzo.dyndns.org>


Quoth =?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?= <4ux6as402@sneakemail.com>:
> Commenting on Ben's post out of order:
> 
> > > I'm worried though that people will forget to call $pl->joinAll()!
> >
> > Stick it in DESTROY.
> 
> I don't see how that would help. I'm thinking of a user writing
> something like:
> 
> $pl->share(\%results);
> foreach (0..4) {
>     $pl->async(sub { $results{$_} = foobar($_) } );
> }
> $pl->joinAll();
> useResults(\%results);
> 
> In this case, at the time of the call to useResults, %results will
> contain the finished results from all forked processes because $pl-
> >joinAll() waits for them all to finish. If $pl->joinAll() doesn't get
> called, the user will most likely see an empty %results. I don't see
> how DESTROY comes in to play here or could help.

Well, if the user wrote

    my %results;
    {
        my $pl = Parallel::Loops->new;
        $pl->share(\%results);
        $pl->async(sub { $results{$_} = foobar($_) })
            for 0..4;
    }
    useResults \%results;

then a call to ->joinAll in DESTROY would ensure it was called. Since
variables (particularly those containing potentially-expensive object,
like $pl) should be minimally-scoped, this would be the correct way to
write that code.

> > They're not global. %output can be scoped as tightly as you like around
> > the async call: async takes a closure, so it will make available (either
> > shared or as copies) any lexicals in scope at the time. (This is why $_
> > won't work: it isn't a lexical.)
> 
> I think I haven't made my concern clear. Is it possible to do:
> 
>     my %resultsForCalc1 : Shared($pl1);
> 
> and have the sharing associated with a particular Parallel::Loops
> instance (so my attribute handler gets a reference to $pl1, not the
> string '$pl1')?

Not easily. Apart from anything else, attribute declarations are
processed at compile-time, before your objects have been constructed.

I was still looking at the question 'why aren't you simply using
forks?'. forks handles all this for you.

> If so, cool. Don't read any further, I'm satisified (BTW, How?). If
> not, lets say one does this:
> 
>     my %resultsForCalc1 : Shared;
>     my $pl1 = Parallel::Loops->new(4);
>     $pl1->foreach([0..9], sub {
>         $resultsForCalc11{$_} = doSomething($_);
>     }
>     useResults(\%resultsForCalc1);
> 
>     # Block above duplicated, just s/1/2/g
>     my %resultsForCalc2 : Shared;
>     my $pl2 = Parallel::Loops->new(4);
>     $pl1->foreach([0..9], sub {
>         $resultsForCalc12{$_} = doSomething($_);
>     }
>     useResults(\%resultsForCalc1);
> 
> Wouldn't the list ( \%resultsForCalc1, \%resultsForCalc2 ) have to be
> global?

When you say 'global' you mean 'shared in all P::L instances', right?
Is this a problem? Since (presumably) you would be tying the variable in
the attr handler, just make sure DESTROY and UNTIE for the tied object
take it off the current list. That way, when the shared variable goes
out of scope it will no longer be considered a candidate for sharing.

(You don't even need to do that if you just weaken the refs in your
master list. Perl will replace any that go out of scope with undef.)

I don't know how P::L deals with copying the results back. Presumably
you have no idea whether a variable has been modified in the sub-process
or not? What do you do if two sub-processes change the same shared var
in different ways?

> How would I/perl keep track of that the user only wants to
> share %resultsForCalc1 in the first calculation and only
> %resultsForCalc2 in the second?
> 
> By the way, how would one avoid that %foo gets handled as shared in
> the following case, since it has gone out of scope?
> 
>     {
>         my %foo : Shared;
>     }
>     my %resultsForCalc1 : Shared;
>     my $pl1 = Parallel::Loops->new(4);
>     $pl1->foreach([0..9], sub {
>         $resultsForCalc11{$_} = doSomething($_);
>     }
>     useResults(\%resultsForCalc1);
> 
> I don't (yet?) see how I can detect which of the hashes with the
> "Shared" attribute that are in scope at the time of the $pl1-
> >foreach() call.
> 
> But even if I could detect which of all the shared hashes that were in
> scope "now", that may not be what the user wants. There could be other
> reasons that the user wants %resultsForCalc1 (from way above) in an
> outer scope and not have it shared in some of the calculations where
> it happens to be in scope.
> 
> Perhaps we're getting a little off-topic here, but now I'm curious
> about the attributes business! ;-)

Not OT at all.

FWIW, I would cast this API rather differently. You don't seem to be
trying to emulate the forks API of 'you can do anything you like', but
instead restricting yourself to iterating over a list. In that case, why
not have the API like

    my $PL = Parallel::Loops->new(sub { dosomething($_) });
    my %results = $PL->foreach(0..9);

No need for any tying, and there's no chance of forgetting the
'->joinAll' since you don't get the results until it's been done. (The
subproc that runs the closure will, of course, get a COW copy of
anything currently in scope, so there's no need to worry about sharing
'read-only' data.)

Ben



------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3007
***************************************


home help back first fref pref prev next nref lref last post