[27462] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9080 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 23 18:05:57 2006

Date: Thu, 23 Mar 2006 15:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 23 Mar 2006     Volume: 10 Number: 9080

Today's topics:
        Calculations with ',' as decimal delimiter <news@chaos-net.de>
    Re: Calculations with ',' as decimal delimiter (Anno Siegel)
    Re: Calculations with ',' as decimal delimiter <news@chaos-net.de>
    Re: Calculations with ',' as decimal delimiter (Anno Siegel)
        LWP and HTTP HEAD <news@chaos-net.de>
    Re: LWP and HTTP HEAD <glex_no-spam@qwest-spam-no.invalid>
    Re: LWP and HTTP HEAD <no@email.com>
    Re: LWP and HTTP HEAD <news@chaos-net.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Mar 2006 21:21:51 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Calculations with ',' as decimal delimiter
Message-Id: <slrne260qv.2ol.news@maki.homeunix.net>

hello together,

Is it possible to use coma (,) as decimal delimiter for some
calculations.
I have a loop and want to get rid of the substitution:

	while($condition) {
        $value =~ s/,/./;
        $sum+=$value;
	}

$value contains values like '1,05', '2,35' and so on.
$sum is supposed to contain the sum also with a ',' as decimal
delimiter.

Any sugestions will be appreciated.

Best regards
Martin 

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


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

Date: 23 Mar 2006 21:06:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Calculations with ',' as decimal delimiter
Message-Id: <48ggvgFjuo9rU1@news.dfncis.de>

Martin Kissner  <news@chaos-net.de> wrote in comp.lang.perl.misc:
> hello together,
> 
> Is it possible to use coma (,) as decimal delimiter for some
> calculations.
> I have a loop and want to get rid of the substitution:
> 
> 	while($condition) {
>         $value =~ s/,/./;
>         $sum+=$value;
> 	}
> 
> $value contains values like '1,05', '2,35' and so on.
> $sum is supposed to contain the sum also with a ',' as decimal
> delimiter.

Numbers are numbers.  They don't have a specific decimal separator.
That is (like the base) entirely a matter of a string representation.

If your system supports locale, you can use that:

    use locale;
    use POSIX qw( strtod);
    POSIX::setlocale( POSIX::LC_NUMERIC(), 'de_DE');

    print strtod( '12,34') + strtod( '56,78'), "\n";

perldoc perllocale, perldoc locale, perldoc POSIX for details.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 23 Mar 2006 22:36:22 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Calculations with ',' as decimal delimiter
Message-Id: <slrne2656m.2ol.news@maki.homeunix.net>

Anno Siegel wrote :

> If your system supports locale, you can use that:
>
>     use locale;
>     use POSIX qw( strtod);
>     POSIX::setlocale( POSIX::LC_NUMERIC(), 'de_DE');
>
>     print strtod( '12,34') + strtod( '56,78'), "\n";

Thank you.
This works perfectly.
But it looks like more "work" than the replacement I used before.

One more question:
I changed 
	$value =~ s/,/./
	# calculation 
	$value =~ s/\./,/ 
top
	$value =~ tr/,/./ 
	# calculation 
	$value =~ tr/./,/ 

Am I right that the second is more efficient?

Best regards
Martin 

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


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

Date: 23 Mar 2006 22:12:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Calculations with ',' as decimal delimiter
Message-Id: <48gkplFk57vcU2@news.dfncis.de>

Martin Kissner  <news@chaos-net.de> wrote in comp.lang.perl.misc:
> Anno Siegel wrote :
> 
> > If your system supports locale, you can use that:
> >
> >     use locale;
> >     use POSIX qw( strtod);
> >     POSIX::setlocale( POSIX::LC_NUMERIC(), 'de_DE');
> >
> >     print strtod( '12,34') + strtod( '56,78'), "\n";
> 
> Thank you.
> This works perfectly.
> But it looks like more "work" than the replacement I used before.
> 
> One more question:
> I changed 
> 	$value =~ s/,/./
> 	# calculation 
> 	$value =~ s/\./,/ 
> top
> 	$value =~ tr/,/./ 
> 	# calculation 
> 	$value =~ tr/./,/ 
> 
> Am I right that the second is more efficient?

In theory, yes.  It won't make a difference in practice.  I'd still
use tr/// because it's the simplest tool that does the job.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 23 Mar 2006 20:16:02 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: LWP and HTTP HEAD
Message-Id: <slrne25svi.sc.news@maki.homeunix.net>

hello together,

I want to capture all HTTP headers a webserver sends for a website using
LWP. I have checked perldoc LWP and perldoc LWP::Simple but did't find
anything helpful.
Gogle also didn't bring me any further.

I tried this script giving th URL as an argument (i.e.
http://www.google.com)
---
i#!/usr/bin/perl

use warnings;
use strict;
use LWP;

my $url = shift;
my $agent   = LWP::UserAgent->new;
my $request = HTTP::Request->new(HEAD   => $url);

my $response = $agent->request($request);

print $response->content;
print $response->header("Content-type"),"\n";
---

I thought the content of a HEAD request would be all header but
obviously that is wrong. If I know the specific header (here
Content-type) I get the value of it. But I want to get *all* headers.

The function head($url) of LWP::Simple only returns the following 5
values: "$content_type, $document_length, $modified_time, $expires,
$server".

How can I capture all headers of a HTTP Request using LWP?

Thanks in advance.
Best regards
Martin 

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


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

Date: Thu, 23 Mar 2006 14:23:24 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: LWP and HTTP HEAD
Message-Id: <rsDUf.40$eT5.1079@news.uswest.net>

Martin Kissner wrote:

> How can I capture all headers of a HTTP Request using LWP?

use LWP;

my $url = 'http://blah.blah.com/';
my $agent   = LWP::UserAgent->new;
my $request = HTTP::Request->new( GET => $url );
my $response = $agent->request($request);
print $response->headers->as_string;

perldoc HTTP::Headers


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

Date: Thu, 23 Mar 2006 22:04:08 +0000
From: Brian Wakem <no@email.com>
Subject: Re: LWP and HTTP HEAD
Message-Id: <48gkaoFjomikU1@individual.net>

Martin Kissner wrote:

> hello together,
> 
> I want to capture all HTTP headers a webserver sends for a website using
> LWP. I have checked perldoc LWP and perldoc LWP::Simple but did't find
> anything helpful.
> Gogle also didn't bring me any further.
> 
> I tried this script giving th URL as an argument (i.e.
> http://www.google.com)
> ---
> i#!/usr/bin/perl
> 
> use warnings;
> use strict;
> use LWP;
> 
> my $url = shift;
> my $agent   = LWP::UserAgent->new;
> my $request = HTTP::Request->new(HEAD   => $url);
> 
> my $response = $agent->request($request);
> 
> print $response->content;
> print $response->header("Content-type"),"\n";
> ---
> 
> I thought the content of a HEAD request would be all header but
> obviously that is wrong. If I know the specific header (here
> Content-type) I get the value of it. But I want to get *all* headers.
> 
> The function head($url) of LWP::Simple only returns the following 5
> values: "$content_type, $document_length, $modified_time, $expires,
> $server".
> 
> How can I capture all headers of a HTTP Request using LWP?
> 
> Thanks in advance.
> Best regards
> Martin
> 

my $ua = LWP::UserAgent->new();
my $res = $ua->head($url);
print $res->as_string;


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: Thu, 23 Mar 2006 23:34:11 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: LWP and HTTP HEAD
Message-Id: <slrne268j3.2ol.news@maki.homeunix.net>

J. Gleixner wrote :
> Martin Kissner wrote:
>
>> How can I capture all headers of a HTTP Request using LWP?
>
> use LWP;
>
> my $url = 'http://blah.blah.com/';
> my $agent   = LWP::UserAgent->new;
> my $request = HTTP::Request->new( GET => $url );
> my $response = $agent->request($request);
> print $response->headers->as_string;
>
> perldoc HTTP::Headers

Thank you. This works (almost) perfectly.

When I compare the results to a telnet session I always get three
additional fileds (the values are from de.yahoo.com):

Client-Date: Thu, 23 Mar 2006 21:55:37 GMT
Client-Peer: 217.12.3.11:80
Client-Response-Num: 1

These are produced by LWP an not part of the server's response.
AFAIK they are not even part of the HTTP spec.
Why are thes returned as "header fields"?

Best regards
Martin 

-- 
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


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

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 9080
***************************************


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