[28190] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9554 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 3 11:05:50 2006

Date: Thu, 3 Aug 2006 08: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           Thu, 3 Aug 2006     Volume: 10 Number: 9554

Today's topics:
        0th positin set when futzing with $[ <mritty@gmail.com>
        A good textbook for (xml) file/DB processing using perl ilh.cho@gmail.com
    Re: Curl/Perl http post performanc issue <simon.chao@fmr.com>
    Re: do not want to sort hash on key <syscjm@gwu.edu>
    Re: do not want to sort hash on key <jurgenex@hotmail.com>
        Editing windows policy.pol file <tseitlin@gmail.com>
    Re: Editing windows policy.pol file <1usa@llenroc.ude.invalid>
    Re: hash key and value <bik.mido@tiscalinet.it>
    Re: hash key and value <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 3 Aug 2006 07:51:39 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: 0th positin set when futzing with $[
Message-Id: <1154616699.331921.163230@m79g2000cwm.googlegroups.com>

First, I know, - I *know* - one should not play with the $[ variable,
and I would never ever do so in "real" code.  Another thread mentioned
the variable, and I was bored, so I started playing.  That being said,
I see the following results:

$ perl -le'
$[ = 7;
@foo = qw/alpha beta gamma/;
print "$_ => $foo[$_]" for 0 .. $#foo;
'
0 => alpha
1 =>
2 =>
3 =>
4 => alpha
5 => beta
6 => gamma
7 => alpha
8 => beta
9 => gamma

I can understand positions 7-9 being set.  7 is the first position of
the array now.  And I can understand position 4-6 being set.  This is
for the "wraparound" feature that we normally see when $[ hasn't been
altered and we access negative indices .  But can anyone explain to me
why the position 0 is set?  (and yes, I know -w would give me three
"use of uninitialized" warnings for 1-3 above.  Not relevant to my
question, so I omitted it).

I do not see any similar results when printing the values of, say -10
through 3 if $[ has not been altered.  So I assume this is specific to
the 0th position, after $[ has been modified...

This is perl, v5.8.4 built for sun4-solaris

Paul Lalli



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

Date: 3 Aug 2006 07:41:35 -0700
From: ilh.cho@gmail.com
Subject: A good textbook for (xml) file/DB processing using perl (or Java, PHP, ...)?
Message-Id: <1154616095.841230.313260@b28g2000cwb.googlegroups.com>

Hello,

I am looking for a good textbook that covers techniques of processing
files in different forms (flat, tagged, indexed, xml, ...) which also
has some coverage on database processing.
Any recommendation?

Thanks,

cho



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

Date: 3 Aug 2006 07:05:16 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: Curl/Perl http post performanc issue
Message-Id: <1154613915.928576.157050@i3g2000cwc.googlegroups.com>


wkhedr wrote:
> We have a Perl program that has to do thousands of secure http post
> requests to a web server as efficient as we could.
> The web server sends back a big XML structure in every request.
>
> We used Curl because it allowed us to deal with secured requests.
>
> Curl by default uses http 1.1.
>
> When we ask Curl to use http 1.0, we get average response time of 40
> millisecond during our stress tests.
>
> The response time is good but the problem is it's not releasing the
> CPU's while waiting for the response. It's supposed to be like a disk
> I/O where it should not be using the CPU. So the CPU utilization goes
> up to 99% with multithreads of testing.
>
> When we run the tests using http 1.1, the response time was 2 seconds
> :)
>
> Using http 1.1 and asking Curl to disable "Expect: 100-continue" by
> using header "Expect:",
> we were able to reach response time of 120 milliseconds and the CPU
> usage was cut by almost 90%.
>
> The question is: how can we get the best of the two settings: have the
> same low CPU usage as http 1.1 and reduce the response time from 120 ms
> to 40 ms as http 1.0?


p.s. the version of curl is:
$ ./curl --version
curl 7.15.4 (powerpc-ibm-aix5.2.0.0) libcurl/7.15.4 OpenSSL/0.9.8b
Protocols: tftp ftp telnet dict ldap http file https ftps
Features: IPv6 Largefile NTLM SSL

and the Perl module we are using is:
WWW::Curl::Easy 3.01



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

Date: Thu, 03 Aug 2006 09:46:09 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: do not want to sort hash on key
Message-Id: <12d3vh1ot6c9a08@corp.supernews.com>

niraj.kumar.ait@gmail.com wrote:
> My hash automatically sort the data on key. 

No it doesn't.  Hashes are not sorted, or even ordered.

> I do not want to sort data
> I just want to store the data in the way I store it.Is there any way
> 

The data is not sorted.  Why do you think it is sorted?
Post a short, *complete* script that replicates the problem.
Tell us what it does, and what you think it should be doing.


Chris Mattern


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

Date: Thu, 03 Aug 2006 14:02:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: do not want to sort hash on key
Message-Id: <LlnAg.9830$j9.9508@trnddc02>

niraj.kumar.ait@gmail.com wrote:
> My hash automatically sort the data on key.

Hashes are mappings from text to scalar, they do not have any order or 
sequence. Claiming a hash is sorted is like saying the length() function 
(which maps from text to natural numbers) is sorted.

What you might be seeing is that when printing the keys of the hash they 
happen to be printed in some sorted order. While this is not totally 
impossible the probability of this happening is extremely(!) low.

>  I do not want to sort data

Hashes by definition don't. On the contrary, for better data management they 
deliberately pseudo-randomize the keys.

> I just want to store the data in the way I store it.

Then don't use a hash. Hashes don't have sequences or orders.

> Is there any way

Sure. Use an array.

jue





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

Date: 3 Aug 2006 06:34:17 -0700
From: "Art" <tseitlin@gmail.com>
Subject: Editing windows policy.pol file
Message-Id: <1154612057.106216.299530@i3g2000cwc.googlegroups.com>

Does anyone knows how to edit windows policy.pol file from a script?

Thanks.



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

Date: Thu, 03 Aug 2006 14:12:16 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Editing windows policy.pol file
Message-Id: <Xns981467E6E65asu1cornelledu@127.0.0.1>

"Art" <tseitlin@gmail.com> wrote in news:1154612057.106216.299530
@i3g2000cwc.googlegroups.com:

> Does anyone knows how to edit windows policy.pol file from a script?

http://www.google.com/search?q=windows+policy+perl

See the first hit.

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: 3 Aug 2006 16:12:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: hash key and value
Message-Id: <d804d25nao3nqg6li63tsu3bb7l5ci27fi@4ax.com>

On Thu, 03 Aug 2006 04:26:48 GMT, "a" <a@mail.com> wrote:

>I have two hashes with the same set of keys but referring to 2 different
>value sets.

So far so fine.

>I need to do the following:
>foreach $key (@keys){
>%hash1($key) / %hash2($key)
>}

This pseudo code is so far from anything that could possibly be
syntactically and semantically correct in Perl that it can hardly shed
any light on your actual problem, and instead it leaves us having to
do guesses about it. At this point a verbal description would be
better. One possible guess may be the following: all of the values of
your hashes are numbers and in particular those of the second hash are
non-null, so you want to divide the values of the first hash by the
corresponding ones from the second hash. Now, what do you want to do?
Gather the results? Just print them? I'll assume the latter: so

  print $hash1{$_}/$hash2{$_}, "\n" for keys $hash1;

should suffice. Note that this trusts your claim that both hashes
share the same keys. You may want to "enforce" this circumstance by
using an HoA data structure, thus having e.g.

  print $hash{$_}[0]/$hash{$_}[1], "\n" for keys $hash;

>Is there any way to extract the value from the hash by the specified key?

If your hash is %hash, then $hash{$key} is the *value* associated to
the *key* $key. But this is basic perl syntax you should be aware of.
Just in doubt: you did check the first few chapters of whatever
introductory perl book/tutorial/whatever you're using, didn't you?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 03 Aug 2006 10:44:06 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: hash key and value
Message-Id: <g69k65phoax.fsf@CN1374059D0130.kendall.corp.akamai.com>

On  3 Aug 2006, a@mail.com wrote:

> I have two hashes with the same set of keys but referring to 2 different
> value sets.
> I need to do the following:
> foreach $key (@keys){
> %hash1($key) / %hash2($key)
> }
> Is there any way to extract the value from the hash by the specified key?

You need to use {} instead of () to tell Perl to give you the value in
the hash for that key (I won't repeat the correct answer given in
another followup).

Regarding your data structures, it's usually more effective to keep
the data in one multi-level hash (hash of hashes, or HoH):

my %data = (
            key1 => { subkey1 => data11, subkey2 => data12 },
            key2 => { subkey1 => data21, subkey2 => data22 },
 ...
           );

instead of keeping two hashes with identical keys.

In your particular example, perhaps this would work

my %data = ( 
            key1 => { number => 5, divisor => 3 },
            key2 => { number => 8, divisor => 2 },
 ...
           );

Then you can access the data like this

foreach my $key (keys %data) # note "my $key" and how we don't need
                             # @keys anymore
{
 # don't divide by zero - you could do something other than dying here
 die "Illegal zero divisor for key $key" unless $data{$key}->{divisor};

 my $result = $data{$key}->{number} / $data{$key}->{divisor};
}

Ted


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

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


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