[21889] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4093 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 10 09:06:14 2002

Date: Sun, 10 Nov 2002 06: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           Sun, 10 Nov 2002     Volume: 10 Number: 4093

Today's topics:
    Re: Can you Simplify My Code? <member@mainframeforum.com>
        Comparative in The Practice of Programming: New measure <fxn@hashref.com>
    Re: Comparative in The Practice of Programming: New mea <ccmcduff@mailbox.uq.edu.au>
    Re: help with arrays of arrays <nobody@dev.null>
    Re: help with arrays of arrays <vilmos@vilmos.org>
    Re: How to locate Perl Interpreter <nospam@satyam.net.in>
        if condition <euv01657@student.euv-frankfurt-o.de>
        LWP and https <kbilbee@pictureflipper.com>
    Re: LWP and https (Triniman)
    Re: Memory Usage When Reading Large (non crlf) Files (CK)
        perl and sendmail <nospam_stigerikson@yahoo.se>
    Re: wish fast method of counting of characters <newsComments17@sellers.com>
    Re: wish fast method of counting of characters <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Nov 2002 08:37:18 -0500
From: yisraelharris <member@mainframeforum.com>
Subject: Re: Can you Simplify My Code?
Message-Id: <3dce610e$1_2@news.onlynews.com>

2 valiant efforts, and still no responses to my question!



--
www.MainFrameForum.com - USENET Gateway


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

Date: 10 Nov 2002 11:08:59 +0100
From: Xavier Noria <fxn@hashref.com>
Subject: Comparative in The Practice of Programming: New measures
Message-Id: <87bs4x68jo.fsf@kodo.localdomain>

I have compared execution time of the programs of the comparative found
in The Practice of Programming[1]. In the next table there is a row for
each input file, whose size goes in the leftmost column, and a column
for each programming language. Times in seconds:


        |   C   |  Java |   C++ |  Perl |  Awk
   -----+-------+-------+-------+-------+------
   145K |  0.23 |  1.21 |  0.60 |  0.46 |  0.35
   933K |  0.84 |  3.04 |  2.60 |  1.19 |  1.78
   2.2M |  3.13 |  7.11 |  6.90 |  2.83 |  5.34
   4.2M |  7.20 |  9.30 | 12.71 |  4.98 | 12.25


I have uploaded a pair of graphs:

   * lines of code:  http://personal5.iddeo.es/ret007t5/lines.png
   * execution time: http://personal5.iddeo.es/ret007t5/performance.png

Note that the Perl version is the one that scales better, whereas Java
performs better than I expected and C++ gives surprising (?) bad times
for the big file.

This has been done in a PC with an Athlon XP 1700, 256M RAM, GNU/Debian
testing, and

   gcc 3.0,
   Sun's JSDK 1.4,
   g++ 3.0,
   Perl 5.8.0,
   GNU Awk 3.1.1.

C/C++ sources were compiled with -O2.

In case you don't know that comparative, the authors write a generator
of text based in Markov chains in those five languages: From an input
file you first build a structure that associates pairs of words with
words that follow them, that is, from

   foo bar baz foo bar zoo

first you build this

   (foo, bar) -> (baz, zoo)
   (bar, baz) -> (foo)
   (baz, foo) -> (bar)
   (bar, zoo) -> END

After that, text is generated taking a pair of consecutive words (word1,
word2), choosing a word from their associated list at random (word3),
and iterating considering now the pair (word2, word3) until you get END.

One has to be very careful interpreting those results, but I thought it
would be interesting sharing those results.

-- fxn

[*] http://cm.bell-labs.com/cm/cs/tpop/


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

Date: 10 Nov 2002 11:39:48 GMT
From: "Rodney McDuff" <ccmcduff@mailbox.uq.edu.au>
Subject: Re: Comparative in The Practice of Programming: New measures
Message-Id: <aqlgi4$2cd$1@bunyip.cc.uq.edu.au>

In a similar fashion  http://www.bagley.org/~doug/shootout/craps.shtml compares
a number of languages and again perl compares well.

>I have compared execution time of the programs of the comparative found
>in The Practice of Programming[1]. In the next table there is a row for
>each input file, whose size goes in the leftmost column, and a column
>for each programming language. Times in seconds:
>
>
>        |   C   |  Java |   C++ |  Perl |  Awk
>   -----+-------+-------+-------+-------+------
>   145K |  0.23 |  1.21 |  0.60 |  0.46 |  0.35
>   933K |  0.84 |  3.04 |  2.60 |  1.19 |  1.78
>   2.2M |  3.13 |  7.11 |  6.90 |  2.83 |  5.34
>   4.2M |  7.20 |  9.30 | 12.71 |  4.98 | 12.25
>
>
>I have uploaded a pair of graphs:
>
>   * lines of code:  <a href="http://personal5.iddeo.es/ret007t5/lines.png">http://personal5.iddeo.es/ret007t5/lines.png</a>
>   * execution time: <a href="http://personal5.iddeo.es/ret007t5/performance.png">http://personal5.iddeo.es/ret007t5/performance.png</a>
>
>Note that the Perl version is the one that scales better, whereas Java
>performs better than I expected and C++ gives surprising (?) bad times
>for the big file.
>
>This has been done in a PC with an Athlon XP 1700, 256M RAM, GNU/Debian
>testing, and
>
>   gcc 3.0,
>   Sun's JSDK 1.4,
>   g++ 3.0,
>   Perl 5.8.0,
>   GNU Awk 3.1.1.
>
>C/C++ sources were compiled with -O2.
>
>In case you don't know that comparative, the authors write a generator
>of text based in Markov chains in those five languages: From an input
>file you first build a structure that associates pairs of words with
>words that follow them, that is, from
>
>   foo bar baz foo bar zoo
>
>first you build this
>
>   (foo, bar) -> (baz, zoo)
>   (bar, baz) -> (foo)
>   (baz, foo) -> (bar)
>   (bar, zoo) -> END
>
>After that, text is generated taking a pair of consecutive words (word1,
>word2), choosing a word from their associated list at random (word3),
>and iterating considering now the pair (word2, word3) until you get END.
>
>One has to be very careful interpreting those results, but I thought it
>would be interesting sharing those results.
>
>-- fxn
>
>[*] <a href="http://cm.bell-labs.com/cm/cs/tpop/">http://cm.bell-labs.com/cm/cs/tpop/</a>
>
>




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

Date: Sun, 10 Nov 2002 05:11:23 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: help with arrays of arrays
Message-Id: <3DCDEA4C.1000600@dev.null>



Randy wrote:

> I have a file that is a list of users, the location of a certain file
> in their home directory, the word yes or no, and the version of the
> file:
> 
> $user/t$file/t$safe/t$version


Presumably the delimiters are tab (\t) characters, not /t.


> 
> I have made an array of arrays:
> 
> while(<FILE>){
>         chomp;
>         my($user,$file,$safe,$version) = split /\t/;
>         $users{$user} = "$file\t$safe\t$version";
>


This is not an array of arrays, this is a hash (of scalars).


> What I need to know is how to make a conditional statement, like
> 
> while $users{$safe}=no {


You almost certainly mean $users{$safe} eq 'no'


> 
> do something
> }
> 
> and if $users{$safe}=yes
> ignore and go on to the next line 
> 


Using a multi-level hash wasn't a bad idea, just carry it out, kind of 
like this:

my %users;
while(<FILE>){
	chomp;
         my($user,$file,$safe,$version) = split /\t/;
         $users{$user} = [$file,$safe,$version];
};

Then you can test to see whether $users{$user}->[1] eq 'no'

For more info, see the perllol and perlreftut manpages.



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

Date: 09 Nov 2002 21:31:15 -0800
From: Vilmos Soti <vilmos@vilmos.org>
Subject: Re: help with arrays of arrays
Message-Id: <87znsif0t8.fsf@my.vilmos.lan>

Randy <nospam@rostie.net> writes:

> I have a file that is a list of users, the location of a certain file
> in their home directory, the word yes or no, and the version of the
> file:
> 
> $user/t$file/t$safe/t$version
> 
> I have made an array of arrays:
> 
> while(<FILE>){
>         chomp;
>         my($user,$file,$safe,$version) = split /\t/;
>         $users{$user} = "$file\t$safe\t$version";

It is not a array of arrays.

> What I need to know is how to make a conditional statement, like
> 
> while $users{$safe}=no {
> 
> do something
> }
> 
> and if $users{$safe}=yes
> ignore and go on to the next line 

What about it:

while (<FILE>) {
	chomp;
	($user, $file, $safe, $version) = split /\t/;
	$users{$user}{file} = $file;
	$users{$user}{safe} = $safe;
	$users{$user}{version} = $version;
}

 ...

foreach $user (keys %users) {
	next if "$users{$user}{safe}" eq "yes";
	# here comes your stuff
}

Vilmos


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

Date: Sun, 10 Nov 2002 12:33:03 +0000 (UTC)
From: bansidhar <nospam@satyam.net.in>
Subject: Re: How to locate Perl Interpreter
Message-Id: <Xns92C2BB336FEE8bansidharsatyamnetin@202.54.1.25>

nobull@mail.com wrote in
news:4dafc536.0211071017.42f57cff@posting.google.com: 

Thanks for the clarification.

I was trying to find out that is there any way to find out the server 
capibilities (Not by hacking) like perl interpreter installed, If installed 
Where? cgi-bin directory, OS etc.,

This was for a script installation client (for people with no programming 
experience).

Just wanted to know is there a simple way to do this (without going for the 
hit and miss methode.

again thanks for the help

regards
bansidhar


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

Date: Sun, 10 Nov 2002 13:46:00 +0100
From: magda muskala <euv01657@student.euv-frankfurt-o.de>
Subject: if condition
Message-Id: <Pine.GSO.4.43.0211101318120.14478-100000@viadukt.euv-frankfurt-o.de>

hi,


first of all -
much thanx for juergen for helping me.
anyway, i am sorry for my last mail (it was misunderstood - i was
going to send it to german group).

i got one more question.
it is a part of cgi script.
open (P, "bio.txt") or die "Cannot open bio.txt: $!\n";
while (<P>)
{
        if ($_ =~ /^$uid/)

        {
                $ok = 1;
        }
}
close (P);
if ($ok == 1)
{
        open (I, "<bio.txt") or die "Cannot open: 'bio.txt' $!\n";
        open (O, ">tmp.txt") or die "Cannot open 'tmp.txt' $!\n";
        while (<I>)
        {
                print O unless (/^$benutzer/);
        }


        close(I); close(O);
        rename("tmp.txt","bio.txt");

}
else
{
        print "This UID doesn't exist!";
        print "<br><br><br><a href=\"http://\">Zurueck<br></a>\n";

}

if i run it from the page, it works fine.
but if i run it from the console, the whole content of bio.txt is deleted.

shouldn't it jump to else {}? if i run it from console the $uid
variable doesn't (it is read as query string)

tia
greetings
magda
http://viadukt.euv-frankfurt-o.de/~euv01657
magdalena.muskala@euv-frankfurt-o.de



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

Date: Sat, 09 Nov 2002 23:16:08 GMT
From: "Kevin Bilbee" <kbilbee@pictureflipper.com>
Subject: LWP and https
Message-Id: <YGgz9.3216$Dl1.260997266@newssvr21.news.prodigy.com>

The floolwing code produces the following error message seemingly from the
server.
501 Protocol scheme 'https' is not supported
But when I go directly to the url from a web browser it functions without
issue

The server requires 128bit SSL. I am stumped.

OS for the script is W2K
Web server IIS
The per version is 5.2.2 I have asked Intenland to update but to no avail.

Does LWP support 128bit SSL?
If not how can I accomplish communicating with a 128bit SSL site over HTTPS?
If it does what am I doing wrong?

Thank you in advance for any help.
Kevin Bilbee



###############################################################
 # I place this here so all print statements go to the browser
 print "Content-type: text/html\n\n";

 use HTTP::Request::Common;
 use LWP::UserAgent;
 use CGI 'param';

 %hash = ();
 $hash{x_Version} = "3.1";
 $hash{x_Delim_Data} = "True";
 $hash{x_Login} = "testLogin";
 $hash{x_Password} = "tesetPassword";
 $hash{x_Type} = "AUTH_CAPTURE";
 $hash{x_Method} = "CC";
 $hash{x_Test_Request} = "True";

 foreach $name (param) {
   $hash{$name} = param($name);
 }

 $hash{x_Amount} = param("x_Amount");
 if ($hash{x_Amount} == 'other') {
  $hash{x_Amount} = param('c_other_amount');
 }

 $hash{x_Card_Num} = param("x_Card_Num");
 $month = param("x_month");
 $year = param("x_year");
 $hash{x_Exp_Date} =  "$month$year" ;


 # this is where we sent the request and get the response from the server
 $ua = LWP::UserAgent->new;
 $response = $ua->request(POST
'https://tools.standardabrasives.com/tools/test.asp', [%hash]);

#---------------------------------------------------------------------------
----------------------------#
# This is the response to the user after processing the card and placing the
data into the database     #
#---------------------------------------------------------------------------
----------------------------#
 print $response->status_line . "\n";
 print "<html><head><title></title></head><body>";
 print $response->content;
 print "</body></html>";






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

Date: 10 Nov 2002 05:27:26 -0800
From: jason.alphonse@alum.dartmouth.org (Triniman)
Subject: Re: LWP and https
Message-Id: <3b7960ec.0211100527.501063e4@posting.google.com>

LWP doesn't currently support the HTTPS scheme.

What you might want to check out is Net::SSLeay.
Available on CPAN as per normal, it lets you do https requests.

Jason Alphonse
Webmaster,
Quickbrowse.com

"Kevin Bilbee" <kbilbee@pictureflipper.com> wrote in message news:<YGgz9.3216$Dl1.260997266@newssvr21.news.prodigy.com>...
> The floolwing code produces the following error message seemingly from the
> server.
> 501 Protocol scheme 'https' is not supported
> But when I go directly to the url from a web browser it functions without
> issue
> 
> The server requires 128bit SSL. I am stumped.
> 
> OS for the script is W2K
> Web server IIS
> The per version is 5.2.2 I have asked Intenland to update but to no avail.
> 
> Does LWP support 128bit SSL?
> If not how can I accomplish communicating with a 128bit SSL site over HTTPS?
> If it does what am I doing wrong?
> 
> Thank you in advance for any help.
> Kevin Bilbee
> 
> 
> 
> ###############################################################
>  # I place this here so all print statements go to the browser
>  print "Content-type: text/html\n\n";
> 
>  use HTTP::Request::Common;
>  use LWP::UserAgent;
>  use CGI 'param';
> 
>  %hash = ();
>  $hash{x_Version} = "3.1";
>  $hash{x_Delim_Data} = "True";
>  $hash{x_Login} = "testLogin";
>  $hash{x_Password} = "tesetPassword";
>  $hash{x_Type} = "AUTH_CAPTURE";
>  $hash{x_Method} = "CC";
>  $hash{x_Test_Request} = "True";
> 
>  foreach $name (param) {
>    $hash{$name} = param($name);
>  }
> 
>  $hash{x_Amount} = param("x_Amount");
>  if ($hash{x_Amount} == 'other') {
>   $hash{x_Amount} = param('c_other_amount');
>  }
> 
>  $hash{x_Card_Num} = param("x_Card_Num");
>  $month = param("x_month");
>  $year = param("x_year");
>  $hash{x_Exp_Date} =  "$month$year" ;
> 
> 
>  # this is where we sent the request and get the response from the server
>  $ua = LWP::UserAgent->new;
>  $response = $ua->request(POST
> 'https://tools.standardabrasives.com/tools/test.asp', [%hash]);
> 
> #---------------------------------------------------------------------------
> ----------------------------#
> # This is the response to the user after processing the card and placing the
> data into the database     #
> #---------------------------------------------------------------------------
> ----------------------------#
>  print $response->status_line . "\n";
>  print "<html><head><title></title></head><body>";
>  print $response->content;
>  print "</body></html>";


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

Date: 9 Nov 2002 21:39:06 -0800
From: fw58959@hotmail.com (CK)
Subject: Re: Memory Usage When Reading Large (non crlf) Files
Message-Id: <c0367340.0211092139.369a5026@posting.google.com>

fw58959@hotmail.com (CK) wrote in message news:<c0367340.0211091242.ed77c45@posting.google.com>...
> Brian McCauley <nobull@mail.com> wrote in message news:<u93cqb5062.fsf@wcl-l.bham.ac.uk>...
> > fw58959@hotmail.com (CK) writes:

> 
> Thank you for the reply.
> 
> It appears I am running version 5.005_03 of perl.
> 
> $count is never bigger than 30.
> 
> The perl -e 'for ( 1 .. 100000000 ) { print; last; }' returns 1
> immediately.
> 
> I will try getting a more recent version to see if that makes a
> difference.  By posting the snippet I was seeing if anyone had seen a
> problem with memory in a similar program structure.  I didn't want to
> scare someone off by posting a large chunk of code.  I will look into
> doing as you suggest if a newer version of perl doesn't help.
> 
> Thanks again for taking the time to comment.
> 
> ./CK


And I have discovered the problem.  It would appear that there are two
versions of perl installed on this machine -- the local build that our
jumpstart procedure puts on and the one that comes builtin with
Solaris 8.  The local build one is 5.004_01 and the Solaris 8 one
which is 5.005_03.  My program was using the local build 5.004_01
version.  As soon as I changed my program to use the 5.005_03 version
memory usage stays at a constant 2.6 MB whereas before it would go to
1GB before croaking.

Thanks to all for listening.

 ./CK


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

Date: Sun, 10 Nov 2002 14:16:06 +0100
From: stig <nospam_stigerikson@yahoo.se>
Subject: perl and sendmail
Message-Id: <aqlm6r$85i$1@oden.abc.se>

hi
i am using perl 5.8 and sendmail
i also use the Mail::Mailer

however one thing happens that i do not understand.
if i specify to use the local sendmail:
$mailer = Mail::Mailer->new("sendmail");
i get "we do not realy" errors

if i instead specify to use smtp at the same local server
$mailer = Mail::Mailer->new("smtp", "this.host.com");
it works without problem.

i checked the /etc/mail/ip_allow file
it contains:
localhost
localhost.localdomain
this.host.com

does not sendmail look in that file when running sendmail but only when 
getting SMTP-requests?

any suggestions to make it possible to send with /usr/lib/sendmail?


thanks
stig


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

Date: Sun, 10 Nov 2002 07:39:52 GMT
From: John Sellers <newsComments17@sellers.com>
Subject: Re: wish fast method of counting of characters
Message-Id: <3DCE0D36.9020206@sellers.com>

Thanks for your response.  Of anyone in this thread you are the one who 
best stuck to the topic the best and unlike Perl Girl actually READ my 
code, in which case she wouldn't gotten "no Cigar".  Benchmark 
suggestion well taken and useful (Perl Girl brought this up too, to her 
credit).

For this reason I will answer your question.  I don't chomp() string 
since in real aplication I will analyze over 30000 lines and one sub 
call to delete and 30000 trivial arithmetics are probably cheaper than 
30000 sub calls to chomp()s or chop()s.

Thanks again for your on-target comments.

John W. Krahn wrote:
[SNIP]
>># START TIME CRITICAL CODE
>>@asciiList = unpack( "C*", $nextString );
>>foreach $anAsciiNumber (@asciiList) {
>>     # does the hash context conversion of $anAsciiNumber to string slow
>>     # things down?
>>     $count{$anAsciiNumber}++
>>}
>># END TIME CRITICAL CODE
>>
>>$ordNewline = ord("\n");
>>delete $count{$ordNewline};
> 
> 
> Why don't you just chomp() the string _before_ you count characters?
> 
> 
> 
[SNIP]



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

Date: Sun, 10 Nov 2002 09:26:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: wish fast method of counting of characters
Message-Id: <3DCE263E.9DEB102F@acm.org>

[ Please do not top-post ]


John Sellers wrote:
> 
> John W. Krahn wrote:
> [SNIP]
> >># START TIME CRITICAL CODE
> >>@asciiList = unpack( "C*", $nextString );
> >>foreach $anAsciiNumber (@asciiList) {
> >>     # does the hash context conversion of $anAsciiNumber to string slow
> >>     # things down?
> >>     $count{$anAsciiNumber}++
> >>}
> >># END TIME CRITICAL CODE
> >>
> >>$ordNewline = ord("\n");
> >>delete $count{$ordNewline};
> >
> > Why don't you just chomp() the string _before_ you count characters?
> 
> I don't chomp() string
> since in real aplication I will analyze over 30000 lines and one sub
> call to delete and 30000 trivial arithmetics are probably cheaper than
> 30000 sub calls to chomp()s or chop()s.

chomp() is almost always faster then other methods.

#!/usr/bin/perl
use warnings;
use strict;
use Benchmark qw/cmpthese/;

my @data = ( join( '', 'a' .. 'z' ) . "\n" ) x 1000;

cmpthese( 3000, {
    chomp1 => sub {
        my @stuff = @data;
        chomp @stuff;
        my %count;

        for my $string ( @stuff ) {
            $count{ord substr $string, $_, 1}++ for 0..length($string)-1;
            }

        return \%count;
        },
    chomp2 => sub {
        my @stuff = @data;
        my %count;

        for my $string ( @stuff ) {
            chomp $string;
            $count{ord substr $string, $_, 1}++ for 0..length($string)-1;
            }

        return \%count;
        },
    delete => sub {
        my @stuff = @data;
        my %count;

        for my $string ( @stuff ) {
            $count{ord substr $string, $_, 1}++ for 0..length($string)-1;
            }

        delete $count{ ord( "\n" ) };
        return \%count;
        },
    } );
__END__

Benchmark: timing 3000 iterations of chomp1, chomp2, delete...
    chomp1: 742 wallclock secs (682.85 usr + 13.69 sys = 696.54 CPU) @  4.31/s (n=3000)
    chomp2: 709 wallclock secs (649.09 usr +  6.47 sys = 655.56 CPU) @  4.58/s (n=3000)
    delete: 744 wallclock secs (699.94 usr +  5.33 sys = 705.27 CPU) @  4.25/s (n=3000)
         Rate delete chomp1 chomp2
delete 4.25/s     --    -1%    -7%
chomp1 4.31/s     1%     --    -6%
chomp2 4.58/s     8%     6%     --



John
-- 
use Perl;
program
fulfillment


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

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.  

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


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