[29838] in Perl-Users-Digest
Perl-Users Digest, Issue: 1081 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 29 21:09:49 2007
Date: Thu, 29 Nov 2007 18:09:14 -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, 29 Nov 2007 Volume: 11 Number: 1081
Today's topics:
any personalized page scripts out there? <jcharth@gmail.com>
Re: any personalized page scripts out there? <smallpond@juno.com>
Re: equivalent controls <bik.mido@tiscalinet.it>
Re: Errors using installing perl modules <ben@morrow.me.uk>
Re: Errors using installing perl modules <gabrielepetrone@gmail.com>
Re: How to persist and query a hash lookup in memory wi <jack_posemsky@yahoo.com>
Re: How to persist and query a hash lookup in memory wi <glex_no-spam@qwest-spam-no.invalid>
Re: How to persist and query a hash lookup in memory wi <ben@morrow.me.uk>
Re: How to persist and query a hash lookup in memory wi <jack_posemsky@yahoo.com>
keeping http session between requests zawszedamian_p@gazeta.pl
Re: keeping http session between requests <ben@morrow.me.uk>
Re: keeping http session between requests <spamtrap@dot-app.org>
Re: page 124 of the camel book <bik.mido@tiscalinet.it>
Re: page 124 of the camel book <bik.mido@tiscalinet.it>
Re: page 124 of the camel book <bik.mido@tiscalinet.it>
Re: page 124 of the camel book <uri@stemsystems.com>
Re: retrieving news messages <bik.mido@tiscalinet.it>
Sorted Hash <palexvs@gmail.com>
Re: Sorted Hash <ben@morrow.me.uk>
Re: Sorted Hash <1usa@llenroc.ude.invalid>
Re: SvUOK always fails on 64bit platform <nospam-abuse@ilyaz.org>
Re: SvUOK always fails on 64bit platform <ben@morrow.me.uk>
URGENT Req: Perl Developer - PA - 6 months <chiruezn@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 29 Nov 2007 11:20:40 -0800 (PST)
From: joe <jcharth@gmail.com>
Subject: any personalized page scripts out there?
Message-Id: <972297be-0565-4cfb-a15c-f0a05900082d@r60g2000hsc.googlegroups.com>
Hello does anyone know of any scripts that will allow users to set
which links they want to see in a page? thanks.
------------------------------
Date: Thu, 29 Nov 2007 12:55:42 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: any personalized page scripts out there?
Message-Id: <ea9bdb31-df0a-4be2-98ad-bedd48f83ea5@f3g2000hsg.googlegroups.com>
On Nov 29, 2:20 pm, joe <jcha...@gmail.com> wrote:
> Hello does anyone know of any scripts that will allow users to set
> which links they want to see in a page? thanks.
perl is unable to change the wants of users.
Were you thinking of having this perl code run on a web server
or on a client of some kind?
--S
------------------------------
Date: Thu, 29 Nov 2007 23:54:39 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: equivalent controls
Message-Id: <4nguk3pshs972vf3uka0mnnlcps5d80c9k@4ax.com>
On Wed, 28 Nov 2007 21:21:41 -0700, "Wade Ward" <wade@zaxfuuq.net>
wrote:
>> while ($power < 6 and $x_calc < 10) {
>> $x_calc++;
>> $power++;
>> print "x calc is $x_calc\n";
>> print "x_calc out is $x_calc\n";
>> print "power out is $power\n";
>> while ($x_calc <= 7.5 ){
>> $power++;
>> $x_calc++;
>> print "power in is $power\n";
>> print "x_calc in is $x_calc\n";
>> }
>> $x_calc = $penultimate;
>> };
>>
>> It also reduced the number of lines from 20 to 14 and IMHO is much more
>> readable, too.
>It sure looks like I'm torturing the syntax, but I got contract68 to work:
[snip]
> do {{
>$term = $base**$power;
>print STDOUT "term is $term \n";
>print STDOUT "current is $penultimate \n";
I can't understand... Juergen posted code that's equivalent to yours
but looks much cleaner and more readable. Why are you throwing in this
do {{ madness again?
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, 29 Nov 2007 20:01:19 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Errors using installing perl modules
Message-Id: <fdi325-c93.ln1@osiris.mauzo.dyndns.org>
Quoth Manuel <gabrielepetrone@gmail.com>:
> i normally used ppm to install perl modules on windows and i never had
> any problems. I just switched to linux (xubuntu) and i'm trying to
> install WWW::Mechanize but it does not work.
If you are using the perl that came with your system, I generally find
it's easier to install Perl modules using the system package manager
where it supports them. You get all the goodies of your package manager
that CPAN.pm doesn't do, like the ability to uninstall and automatic
upgrades. Since Ubuntu is Debian-based, and Debian are one of the better
OS distributors with regard to packaging Perl modules I would expect
WWW::Mech to be there.
> This is what i did ( root user):
>
> root@server:~/Desktop# perl -MCPAN -e shell
> Terminal does not support AddHistory.
>
> cpan shell -- CPAN exploration and modules installation (v1.7601)
> ReadLine support available (try 'install Bundle::CPAN')
> cpan> install WWW::Mechanize
> Running install for module WWW::Mechanize
> Running make for P/PE/PETDANCE/WWW-Mechanize-1.32.tar.gz
<snip<
>
> Checking if your kit is complete...
> Looks good
> Writing Makefile for WWW::Mechanize
> -- NOT OK
Doesn't look like you've done anything wrong to me... The next step is
to try 'look WWW::Mechanize', which will drop you in a shell in the
WWW::Mechanize directory, and try running
perl Makefile.PL
make
make install
by hand. If there is an INSTALL or README file you could read it, to see
if there are any particular issues with this module that CPAN.pm doesn't
know about. If Makefile.PL still fails (that is, if it doesn't generate
a Makefile) then post the transcript again and we'll have another look
:).
Ben
------------------------------
Date: Thu, 29 Nov 2007 15:30:50 -0800 (PST)
From: Manuel <gabrielepetrone@gmail.com>
Subject: Re: Errors using installing perl modules
Message-Id: <51b49444-01d7-4e90-a0ff-6247572247e8@s12g2000prg.googlegroups.com>
On 29 Nov, 21:01, Ben Morrow <b...@morrow.me.uk> wrote:
> Doesn't look like you've done anything wrong to me... The next step is
> to try 'look WWW::Mechanize', which will drop you in a shell in the
> WWW::Mechanize directory, and try running
>
> perl Makefile.PL
> make
> make install
>
Hey Ben,
yes that worked for me! thanx so much from italy :)
------------------------------
Date: Thu, 29 Nov 2007 13:56:23 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <f9b9842e-596d-4441-a961-c4e133d49e88@a39g2000pre.googlegroups.com>
On Nov 29, 9:56 am, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <7c5df670-d214-40c2-b59d-9ba1f5785...@s36g2000prg.googlegroups.com>,
>
>
>
>
>
> <jackposem...@yahoo.com> wrote:
> > On Nov 28, 6:37 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> > > Jack wrote:
> > > > Hi I have a web application that needs to on an adhoc basis query a
> > > > hash lookup which should be persisted in memory - I have seen this
> > > > module "Persistent::Memory - A Persistent Class implemented using
> > > > Memory (RAM)" but I wanted to see if there was a much simpler approach
> > > > to taking a hash map and making it 'callable' while persisted in
> > > > memory using standard features not requiring a special Perl module
> > > > install..
>
> > > > Any thoughts would be appreciated.
>
> > > Why not a tied hash? See e.g. "perldoc DB_File".
>
> > > --
> > > Gunnar Hjalmarsson
> > > Email:http://www.gunnar.cc/cgi-bin/contact.pl
>
> > Hi and thank you however that looks too complex - just trying to put a
> > hash in memory, why is that so hard to do ? Is there a simpler way ?
>
> Your question is confusing. All Perl variables, including hashes, are
> in memory. The trick to achieving "persistence" between execution
> instances of your web application is to have the data on a permanent
> data store, such as a disk file. Memory variables disappear once your
> Perl process terminates. Using a tied hash, per Gunnar's suggestion, is
> one way to accomplish this. There are others, such as using the
> Storable module to serialize your hash so you can write it to memory.
>
> I have not use Persistent::Memory, but you might want to check out the
> Persistent::File module instead. Both of those modules seem to be part
> of the Persistent framework of Perl modules.
>
> See
> <http://search.cpan.org/~dwinters/Persistent-Base-0.52/lib/Persistent.po
> d>
>
> --
> Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com- Hide quoted text -
>
> - Show quoted text -
Thanks I am willing to install Perl Modules, really wondering if there
is a native ability to do it out of the box in Perl. I got persistent
memory to work but its not clear how to "pin" a hash lookup into
memory since .pl files and the persistent memory code example itself
are only as good as the life of the execution of the script !! Still
not clear how to hold a has in Memory - even if you were to create a
windows service out of it with activestate PDK, not clear how to write
the script so the script doesnt stop execution but sits and waits for
a socket connection or something.. Do I just have script 1 generate
a hash with "sleep forever" and then script 2 can call that hash ??
I dont want to use another database for this. So, not using another
DB, how does one pin and persist and then query a hash in memory using
perl or a perl module.
Thanks for the help all !
Jack
------------------------------
Date: Thu, 29 Nov 2007 17:43:39 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <474f4eab$0$513$815e3792@news.qwest.net>
Jack wrote:
[...]
> So, not using another DB
If you're already using a Database then just store the data there, why
would you use another Database to store it?
>how does one pin and persist and then query a hash in memory using
> perl or a perl module.
Whatever 'pin' a hash means.
Why do you want to do this? Maybe that's the real problem. You
think that's what you want to do, but it's really not needed.
You could have a daemon running, that reads/creates the hash and
then it would have the data in memory. You could then then connect
to it via a socket, but why the heck do you want to do all of
that? That's really not Perl 101 and I'm pretty sure you'd
end up spending a lot of time understanding it and trying to get it
working, however it'll take 20-seconds to write and will be very
fast, using a tied hash.
There are a lot of examples online and you can read the documentation
that comes with perl.
perldoc DB_File
If you want to go the whole daemon and IPC/socket route:
perldoc perlipc
------------------------------
Date: Thu, 29 Nov 2007 23:35:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <7vu325-9e4.ln1@osiris.mauzo.dyndns.org>
Quoth Jack <jack_posemsky@yahoo.com>:
<snip: some sort of persistant shared memory>
>
> Thanks I am willing to install Perl Modules, really wondering if there
> is a native ability to do it out of the box in Perl.
Well, on systems that support it you can use SysV shared memory, for
which Perl natively has the raw shm* calls. This doesn't work on
Windows, though.
You could try IPC::Shareable for Unix and Win32::MMF::Shareable (which
has the same interface) for Win32, which provide an easier interface to
shared memory.
Another alternative would be mmap, using the Sys::MMap module. mmap is
substantially better behaved than SysV shm, and portable to Windows.
> I got persistent memory to work but its not clear how to "pin" a hash
> lookup into memory since .pl files and the persistent memory code
> example itself are only as good as the life of the execution of the
> script !!
In what sense then is this memory 'persistent'? I think you are rather
confused about what is and isn't possible under modern operating
systems: unless you take steps to prevent it, all memory allocated by a
process is released when that process exits. This is a feature :).
Ben
------------------------------
Date: Thu, 29 Nov 2007 17:06:50 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: Re: How to persist and query a hash lookup in memory with Perl ?
Message-Id: <33e7713a-e6ad-4568-b046-bcc79c8d5846@a35g2000prf.googlegroups.com>
On Nov 29, 3:35 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Jack <jack_posem...@yahoo.com>:
> <snip: some sort of persistant shared memory>
>
>
>
> > Thanks I am willing to install Perl Modules, really wondering if there
> > is a native ability to do it out of the box in Perl.
>
> Well, on systems that support it you can use SysV shared memory, for
> which Perl natively has the raw shm* calls. This doesn't work on
> Windows, though.
>
> You could try IPC::Shareable for Unix and Win32::MMF::Shareable (which
> has the same interface) for Win32, which provide an easier interface to
> shared memory.
>
> Another alternative would be mmap, using the Sys::MMap module. mmap is
> substantially better behaved than SysV shm, and portable to Windows.
>
> > I got persistent memory to work but its not clear how to "pin" a hash
> > lookup into memory since .pl files and the persistent memory code
> > example itself are only as good as the life of the execution of the
> > script !!
>
> In what sense then is this memory 'persistent'? I think you are rather
> confused about what is and isn't possible under modern operating
> systems: unless you take steps to prevent it, all memory allocated by a
> process is released when that process exits. This is a feature :).
>
> Ben
ok.. lets talk with code - I got this to work with DB_File.. my
fundamental question is, once you create the tied hash like the below,
and the program is done executing, how do I access the hash and query
it from another Perl execution program ?? I tried using the API
interface afterwards as described here http://perldoc.perl.org/DB_File.html
, see the error at bottom:
### RUN PROGRAM 1 #####
use warnings ;
use strict ;
use DB_File ;
our (%h, $k, $v) ; unlink "fruit" ;
tie %h, "DB_File", "fruit", O_RDWR|O_CREAT, 0666, $DB_HASH
or die "Cannot open file 'fruit': $!\n"; # Add a few key/
value pairs to the file
$h{"apple"} = "red" ;
$h{"orange"} = "orange" ;
$h{"banana"} = "yellow" ;
$h{"tomato"} = "red" ; # Check for existence of a key
print "Banana Exists\n\n" if $h{"banana"} ; # Delete a key/
value pair.
delete $h{"apple"} ; # print the contents of the file
while (($k, $v) = each %h)
{ print "$k -> $v\n" }
untie %h ;
#####START SEPARATE PROGRAM 2 ###
use warnings ;
use strict ;
use DB_File ;
$db = tie %h, "DB_File", "testfile1" ;
foreach (keys %h)
{ print "$_\n" }
### PROGRAM 2 ERRORS:
Global symbol "$db" requires explicit package name at
test_dbfile1_query.pl .
Global symbol "%h" requires explicit package name at
test_dbfile1_query.pl .
Global symbol "%h" requires explicit package name at
test_dbfile1_query.pl 5.
Execution of test_dbfile1_query.pl aborted due to compilation errors.
------------------------------
Date: Thu, 29 Nov 2007 11:19:47 -0800 (PST)
From: zawszedamian_p@gazeta.pl
Subject: keeping http session between requests
Message-Id: <5a943e39-d774-4d4c-97a7-7eed843ce716@j20g2000hsi.googlegroups.com>
I was trying to download page and keep http session between requests
like this:
my $request = HTTP::Request->new(GET => $URL_login_page);
my $response = $browser->request($request);
# save cookie
$cookie = $response->header("Set-cookie"); # here cookie is not null
$request = HTTP::Request->new(GET => $URL_get_data);
# set saved cookie
$request->header("Set-cookie", $cookie);
but it does not work - session is not not forwarded to second request,
cookie's gone
how can I keep session between requests?
thanks for your help
------------------------------
Date: Thu, 29 Nov 2007 20:23:11 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: keeping http session between requests
Message-Id: <fmj325-hi3.ln1@osiris.mauzo.dyndns.org>
Quoth zawszedamian_p@gazeta.pl:
> I was trying to download page and keep http session between requests
> like this:
>
<snip>
>
> but it does not work - session is not not forwarded to second request,
> cookie's gone
>
> how can I keep session between requests?
Use the cookie_jar option the LWP::UserAgent->new.
Ben
------------------------------
Date: Thu, 29 Nov 2007 15:47:05 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: keeping http session between requests
Message-Id: <m11wa8dbjq.fsf@dot-app.org>
zawszedamian_p@gazeta.pl writes:
> I was trying to download page and keep http session between requests
> like this:
>
> my $request = HTTP::Request->new(GET => $URL_login_page);
> my $response = $browser->request($request);
> # save cookie
> $cookie = $response->header("Set-cookie"); # here cookie is not null
>
> $request = HTTP::Request->new(GET => $URL_get_data);
> # set saved cookie
> $request->header("Set-cookie", $cookie);
>
> but it does not work - session is not not forwarded to second request,
> cookie's gone
>
> how can I keep session between requests?
You might want to have a look at WWW::Mechanize.
sherm--
--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 29 Nov 2007 23:34:07 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: page 124 of the camel book
Message-Id: <eifuk39i35q2fi41aa4gtvffkb0nu34vl0@4ax.com>
On Tue, 27 Nov 2007 18:11:28 -0700, "Wade Ward" <wade@zaxfuuq.net>
wrote:
>Control loops are strange things. For better or worse, I'm gonna try to get
>back on the perl horse that has bucked me off fifty times already on this
>one simple prog. I was astonished when I couldn't
>break;
>, like you do in C.
By all accounts, you can. What's the problem?
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, 29 Nov 2007 23:36:01 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: page 124 of the camel book
Message-Id: <jjfuk31jgnh8k2m78qd1fjhs3fbhcjt023@4ax.com>
On Wed, 28 Nov 2007 01:43:40 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>May I suggest you take an introductory class in structured programming? Then
>you don't need those remnants of goto.
>Yes, there are rare circumstances where breaking out of a loop in its middle
>seems to be convenient. But is never a necessity and usually indicates the
>programmer is not all that familiar with modern program design.
IIUC, this is much of a FUD attack. What's so bad about goto is that
it is unrestricted goto; OTOH last, next and redo are tamed forms of
goto and they just make for clearer syntax. I don't feel holding say a
$goon flag variable could be regarded as a superior solution.
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, 29 Nov 2007 23:39:25 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: page 124 of the camel book
Message-Id: <trfuk3p8rie39i5q9autfev5lr9he48qjq@4ax.com>
On Thu, 29 Nov 2007 02:37:55 GMT, Uri Guttman <uri@stemsystems.com>
wrote:
> WW> do {{
> WW> $x_sought = $x_sought - 1;
> WW> # last if $x_sought < 0;
> WW> print STDOUT "x sought is $x_sought\n";
>
> WW> }} until $x_sought < 0;
> WW> }} until $x_calc < 0;
>
>do while is bad enough in perl (rarely needed, i never use it) but
>do/until is horrible. invert those boolean tests and use while. but
>better would be to invert those into proper while loops.
And do {{ ... }} until is... well, what's worse than "horrible"?
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: Fri, 30 Nov 2007 00:01:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: page 124 of the camel book
Message-Id: <x7k5o0sisp.fsf@mail.sysarch.com>
>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:
MD> On Thu, 29 Nov 2007 02:37:55 GMT, Uri Guttman <uri@stemsystems.com>
MD> wrote:
WW> do {{
WW> $x_sought = $x_sought - 1;
WW> # last if $x_sought < 0;
WW> print STDOUT "x sought is $x_sought\n";
>>
WW> }} until $x_sought < 0;
WW> }} until $x_calc < 0;
>>
>> do while is bad enough in perl (rarely needed, i never use it) but
>> do/until is horrible. invert those boolean tests and use while. but
>> better would be to invert those into proper while loops.
MD> And do {{ ... }} until is... well, what's worse than "horrible"?
wardish?
he does seem to want to code in the worst way possible!
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: Thu, 29 Nov 2007 23:32:24 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: retrieving news messages
Message-Id: <k7fuk3p0mp7giso1bk8dq26bpo1tc8nd5h@4ax.com>
On Wed, 28 Nov 2007 23:03:22 -0800, David Harmon <source@netcom.com>
wrote:
>> my $nntp = Net::NNTP->new('newsgroups.comcast.net', { Debug => 1} );
>> die "Unable to create NNTP object" unless $nntp;
>>
>>You have got to get those two statements working before proceeding
>>any further.
>
>It appears to me, that style of passing arguments to Net::NNTP->new
>cannot work. I see this code in Net/NNTP.pm:
Yes, the issue was resolved some months ago. How gentle of you to turn
it up again...
>sub new
>{
> my $self = shift;
> my $type = ref($self) || $self;
> my ($host,%arg);
> if (@_ % 2) {
> $host = shift ;
> %arg = @_;
> } else {
> %arg = @_;
> $host=delete $arg{Host};
> }
[snip]
>The above looks wrong to me; I think it ought to be more like
>
> if (not (@_ % 2)) {
No, that's exactly what's intended. If you don't like what's intended,
then it's a wholly different problem. If you have a list with an odd
number of elements, then one is shifted off to be assigned to $host.
The remaining ones are interpreted as "named" parameters and put into
a hash. Otherwise, the parameters are assigned to a hash in the first
place.
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, 29 Nov 2007 15:33:08 -0800 (PST)
From: "palexvs@gmail.com" <palexvs@gmail.com>
Subject: Sorted Hash
Message-Id: <a1ddaad2-89c6-4b01-bd39-2e27e36ffe39@b40g2000prf.googlegroups.com>
I filled hash and then printed it (sorted by key):
my %hs = (
key10 => 5,
key5 => b,
aey9 => 7,
)
foreach my $k (sort keys %hs) { print "$k $hs{$k}\n"; }
key - string ([0-9A-F]{72}), 50K records.
How do it more effective?
------------------------------
Date: Fri, 30 Nov 2007 00:09:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Sorted Hash
Message-Id: <2v0425-an4.ln1@osiris.mauzo.dyndns.org>
Quoth "palexvs@gmail.com" <palexvs@gmail.com>:
> I filled hash and then printed it (sorted by key):
> my %hs = (
> key10 => 5,
> key5 => b,
> aey9 => 7,
> )
> foreach my $k (sort keys %hs) { print "$k $hs{$k}\n"; }
>
> key - string ([0-9A-F]{72}), 50K records.
> How do it more effective?
Tie::IxHash, or maintain an array of keys yourself. See perldoc -q
sorted.
Ben
------------------------------
Date: Fri, 30 Nov 2007 01:13:41 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Sorted Hash
Message-Id: <Xns99F7CDC51277Fasu1cornelledu@127.0.0.1>
"palexvs@gmail.com" <palexvs@gmail.com> wrote in news:a1ddaad2-89c6-4b01-
bd39-2e27e36ffe39@b40g2000prf.googlegroups.com:
> I filled hash and then printed it (sorted by key):
> my %hs = (
> key10 => 5,
> key5 => b,
> aey9 => 7,
> )
> foreach my $k (sort keys %hs) { print "$k $hs{$k}\n"; }
>
> key - string ([0-9A-F]{72}), 50K records.
> How do it more effective?
Well, depends on what you mean by 'more effective'.
If you are talking about speed, note that the only place where you can
really get any meaningful improvement is IO.
I am using Windows XP SP2 with ActiveState Perl 5.8.8.822 on an Intel Core
Duo 1.66 Mhz with 1 GB physical memory with a whole bunch of other apps
open.
Let's start with:
#!/usr/bin/perl
use strict;
use warnings;
my %hash;
for my $k ( 1 .. 50_000 ) {
$hash{ make_key() } = $k;
}
### printing code here
sub make_key {
join('', map { sprintf( '%.16f', $_ ) } (rand, rand, rand, rand) );
}
__END__
C:\DOCUME~1\asu1\LOCALS~1\Temp\t> timethis t
TimeThis : Command Line : t
TimeThis : Start Time : Thu Nov 29 19:32:35 2007
TimeThis : End Time : Thu Nov 29 19:32:36 2007
TimeThis : Elapsed Time : 00:00:01.109
So, let's add printing to this script:
my @keys = sort keys %hash;
print "$_ $hash{$_}\n" for @keys;
TimeThis : Command Line : t
TimeThis : Start Time : Thu Nov 29 19:37:11 2007
TimeThis : End Time : Thu Nov 29 19:37:14 2007
TimeThis : Elapsed Time : 00:00:03.156
So, we are talking about 2.047 seconds added by printing the hash.
Assuming 80 bytes per print statement and 50,000 print statements, that's
3906.25 K of output in about two seconds.
That's not bad and does not leave a lot of room for improvement.
Following the printing late strategy and trying to trade-off memory for
speed, let's accumulate all output before printing:
my $out;
for ( @keys ) {
$out .= "$_ $hash{$_}\n";
}
{
local $| = 0;
print $out;
}
TimeThis : Command Line : t
TimeThis : Start Time : Thu Nov 29 19:56:33 2007
TimeThis : End Time : Thu Nov 29 19:56:39 2007
TimeThis : Elapsed Time : 00:00:05.859
Well, that wasn't good (and I really did not expect it to be). But we don't
have to accumulate all output. We can just print after every 9K or so. (I
came up with that magic number on my system after some trial and error ...
Time program, go do something in Word, load cnn.com on Firefox, go back and
re-time this script ... poor man's cache clearing).
my $out;
for ( @keys ) {
$out .= "$_ $hash{$_}\n";
if ( length $out > 9_000 ) {
print $out;
$out = q{};
}
}
TimeThis : Command Line : t
TimeThis : Start Time : Thu Nov 29 20:04:57 2007
TimeThis : End Time : Thu Nov 29 20:05:00 2007
TimeThis : Elapsed Time : 00:00:03.062
So, after all that tinkering, I got an improvement of 0.094 seconds, that
is about 3%.
Now, my against my gut feeling, I did try:
print "$_ $hash{$_}\n" for sort keys %hash;
TimeThis : Command Line : t
TimeThis : Start Time : Thu Nov 29 20:11:01 2007
TimeThis : End Time : Thu Nov 29 20:11:04 2007
TimeThis : Elapsed Time : 00:00:02.953
Hmmm ... It does not look like I can beat the simplest alternative by
trying to be clever.
That took 1.844 seconds to output about 3906.25K.
of course, I probably wasted my time because I misunderstood your vaguely
phrased question.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Thu, 29 Nov 2007 23:05:33 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: SvUOK always fails on 64bit platform
Message-Id: <fingjt$1db5$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
cyl
<u8526505@gmail.com>], who wrote in article <46372675-8f8c-4703-9d68-e135639c5ea0@d27g2000prf.googlegroups.com>:
> SWIGINTERN int
> SWIG_AsVal_unsigned_SS_int SWIG_PERL_DECL_ARGS_2(SV * obj, unsigned
> int *val)
> {
> unsigned long v;
> int res = SWIG_AsVal_unsigned_SS_long SWIG_PERL_CALL_ARGS_2(obj,
> &v);
> if (SWIG_IsOK(res)) {
> if ((v > UINT_MAX)) {
> return SWIG_OverflowError;
> } else {
> if (val) *val = (unsigned int)(v);
> }
> }
> return res;
> }
IMO, you should disregard the direct criticism of the other reply to
your posting (the general musing there is correct, but applications to
your code look misplaced).
I think your problems stem from misunderstanding of C, not of
Perl/XS. Your code above:
int res = function_returning_long();
makes no sense in the context.
> SWIGINTERN int
> SWIG_AsVal_unsigned_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned
> long *val)
> {
> if (SvUOK(obj)) {
> if (val) *val = SvUV(obj);
THis is again: you put UV into an unsigned long slot. It makes sense
ONLY IF sizeof(UV) <= sizeof(long) - which will not hold on many
builds of Perl.
[Perl defines C macros with sizeof() of most useful types (and the
corresponding MAX/MIN), so you can write conditional code. Extract
SvUV to an UV variable, then compare it with UNSIGNED_LONG_MAX
(sp?) - and remember that the way to write comparison depends on
the relative sizes of types!]
Hope this helps,
Ilya
------------------------------
Date: Thu, 29 Nov 2007 23:39:19 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: SvUOK always fails on 64bit platform
Message-Id: <76v325-9e4.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> [A complimentary Cc of this posting was sent to
> cyl
> <u8526505@gmail.com>], who wrote in article
> <46372675-8f8c-4703-9d68-e135639c5ea0@d27g2000prf.googlegroups.com>:
>
> IMO, you should disregard the direct criticism of the other reply to
> your posting (the general musing there is correct, but applications to
> your code look misplaced).
If anything I've said is incorrect or inapplicable I'll gladly accept
correction. I know you know the guts of perl better than I do :).
Ben
------------------------------
Date: Thu, 29 Nov 2007 12:02:29 -0800 (PST)
From: Chiru <chiruezn@gmail.com>
Subject: URGENT Req: Perl Developer - PA - 6 months
Message-Id: <6baf282b-9df7-4c11-afbd-72e7065ee4c3@e6g2000prf.googlegroups.com>
My client is looking for Perl developers at King of Prussia,
Pennsylvania. If you are available for new projects and willing to
relocate to PA please send your resume with contact details and rate/
hr ASAP.
Description:
Perl Developer needed ASAP.
Need candidate with Good experience in Perl. Must have heavy perl
scripting experience.
Oracle Database
SQL
Unix/Linux
Urgent position in King of Prussia, PA
6 months plus
Rate around $45-$50
Regards,
Chiru
609 945 3178
chiru @ e-zencomp.com (remove spaces)
Ezen computer services, Inc.
------------------------------
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 V11 Issue 1081
***************************************