[23736] in Perl-Users-Digest
Perl-Users Digest, Issue: 5942 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 16 03:05:47 2003
Date: Tue, 16 Dec 2003 00: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 Tue, 16 Dec 2003 Volume: 10 Number: 5942
Today's topics:
Re: (hash|2-dim array) question <chatasos@yahoo.com>
Asynchronous Objects (Bryan Castillo)
getting error for modules (debraj)
Re: improve code - combine for & join <nobull@mail.com>
Re: newbie creating test help <andy@petdance.com>
Re: Planning for maintenance <uri@stemsystems.com>
Re: recursive closures? <uri@stemsystems.com>
Re: Russian to Windows-1252 (htmlencode) <flavell@ph.gla.ac.uk>
Re: Starting Perl Script at Bootup <andy@petdance.com>
Re: Starting Perl Script at Bootup <abigail@abigail.nl>
Subroutine return two Hash (ThERiZla)
Re: Subroutine return two Hash <karlheinz.weindl@oooonlinehome.de>
Re: Subroutine return two Hash <noreply@gunnar.cc>
ticks and FreeBSD <jundy@jundy.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Dec 2003 18:01:08 +0200
From: Tassos <chatasos@yahoo.com>
Subject: Re: (hash|2-dim array) question
Message-Id: <1071503840.398286@athnrd02.forthnet.gr>
Tad McClellan wrote:
> Tassos <chatasos@yahoo.com> wrote:
>
>
>>I want while reading the file to create something (a hash? a 2-dim array?)
>
>
>
> A Hash Of Lists (HoL) would be convenient.
>
> perldoc perlreftut
> perldoc perlref
> perldoc perllol
> perldoc perldsc
>
>
>
>>that will
>>enable me to get the following results:
>>
>>my $temp;
>>
>>$temp = "I1";
>>print array2($temp,1) # gives "[test1]" as the output
>>print array2($temp,2) # gives "([\w\-\.:/]+)" as the output
>
>
>
> ---------------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my %array2;
> while ( <DATA> ) {
> chomp;
> my @fields = split /;/;
> $array2{$fields[0]} = \@fields;
> }
>
> my $key = 'I1';
> print $array2{$key}[1], "\n";
> print $array2{$key}[2], "\n";
>
> __DATA__
> I1;[test1];([\w\-\.:/]+)
> I2;[test2];(\w\d [\d\/]+)
> ---------------------------------------------------
>
I want to have another hash (same $key) with [1],[2] empty.
Is there a better way than the following?
foreach (@Fields) {
chomp($_);
my @fields = split /;/;
my @fields2 = split /;/;
@fields2[1..2] = "";
$array2{$fields[0]} = \@fields;
$array3{$fields[0]} = \@fields2;
}
>
------------------------------
Date: 15 Dec 2003 10:23:17 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Asynchronous Objects
Message-Id: <1bff1830.0312151023.70dce7a2@posting.google.com>
I've been looking through CPAN and the newsgroups for information on
calling on objects asynchronously from perl. Basically, I was
thinking about a Tk application I was working on that used DBI and had
some SQL statements that may take 10 to 30 seconds. I really didn't
want the screen to freeze for that long.
So I've been searching for methods of asynchronous operations on
objects. There are of course threads, however I seems that it is not
reccomended to use multiple database connections with threads, or to
even have more than 1 thread use the DBI module, even when protected
through synchronization.
What I've come up with is the start of a module that uses IPC::Open2
to start a new perl interpreter. The process is givin a package name
containing methods it should delegate out to. The process reads in
complex hashes that have been serialized with the Storable module, one
element in the hash contains the name of the method to call in the
delegate package. The method is called and the results are also
returned serialized with the storable module.
Ive then been building a client library build around select(4-arg
form) to try to send and received the data (method call and argumentS)
non-blocking.
# it kind of works like this....
my $timeout = 10;
my $server = AsyncObject::Server::IPCO2->new();
# Internally the line above is doing this to start a new process
my $command =
'use AsyncObject::Server; '.
'my $server = AsyncObject::Server->new(\\*STDIN,\\*STDOUT); '.
'$server->start();';
my $pid = open2(
$rdrfh, $wtrfh,
$Config{perlpath},
'-e',
$command
);
#-----------------------
my $request = $server->command('load', 'Async::Delegate::database');
my $reply;
while (!$reply = $request->getReply($timeout)) {
# whatever
}
if ($reply->{status} != 1) {
die $reply->{error};
}
$request = $server->call('connect', $user, $pass);
while (!$reply = $request->getReply($timeout)) {
# ....
}
if ($reply->{status} != 1) {
die $reply->{error};
}
Then i was planning on exposing the input and output handles, which
could be
used from Tk fileevent, or with select, (to handle more than one
asynchronous object call.)
# just pseudo - code.
$request = $server->call('exec_sql', 'select count(*) from blah');
my $in = $request->getInputHandle();
# use select on $in to determine when request can be sent to server
# perhaps in a fileevent
# can use more granular methods on callback from select
$request->send($timeout);
if ($request->sendComplete()) {
my $out = $request->getOutputHandle();
# use select with output handle or fileevent
on_callback:
$request->receive($timeout);
if ($request->complete()) {
my $result = $request->getResult();
}
}
Is there anything out there like this? I haven't been able to find
anything on CPAN. There is RPC::PlServer and RPC::PlClient, however I
was looking for something where the client would start the server on
demmand (theoreticaly this could still be done with
RPC::Pl(Server|Client), but I didn't want to use sockets), and I was
looking for something that would allow asynchronous calls on the
objects.
------------------------------
Date: 15 Dec 2003 08:44:09 -0800
From: debhatta@hotmail.com (debraj)
Subject: getting error for modules
Message-Id: <f9f243e.0312150844.b042ef@posting.google.com>
Hi all,
I have written a perl script and it uses a module. Now I wish to keep
a separate directory for all my modules. So I read the documents ( for
eg. perldoc perlmod; perldoc perlmodlib; perldoc perlmodinstall) and
finally decided to use the following construct in my script.
use FindBin qw($Bin);
use lib "$Bin/../libs";
Basically I dont want to hard-code the library path. The script should
work it out for itself. Now the problem with the above FindBin is that
it doesnt work if I do from a different directory other than where my
script is kept.
For eg. Say script is /etc/prog/script and lib at /etc/libs and I run
from /etc/prog it works fine. But from /home/ngraving/scripts when I
run it gives error that cant find module in @INC (
/home/ngraving/../libs). Why is this? What is the best method of
solving this and also of getting the library path without coding it? I
know that I can set the PERL5LIB variable but thats not the option I
am looking at. Or do I have to write a sub-routine to solve this ?
Any pointers will be highly helpful.
Thanx
Debhatta
------------------------------
Date: 15 Dec 2003 14:10:52 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: improve code - combine for & join
Message-Id: <u9wu8yw4r7.fsf@wcl-l.bham.ac.uk>
mike_solomon@lineone.net (Mike Solomon) writes:
> Brian McCauley <nobull@mail.com> wrote in message news:<u97k13z42g.fsf@wcl-l.bham.ac.uk>...
> > mike_solomon@lineone.net (Mike Solomon) writes:
> > >
> > > my @required = (
> > > {company => "Company is required"},
> > > {address1 => "Address1 is required"},
> > > {postcode => "Postcode is required"},
> > > {phone => "Phone is required"},
> > > );
> >
> > Obviously an array of single element hashes is a very weird data
> > structure and whatever the data you are seeking to represent
> > there's almost certainly a better structure. But without knowing
> > the problem I couldn't say what the better structure is.
>
> I am using it in various cgi programs that create some javascript
>
> The data is a field name and a message
>
> The order is important which is why I used an array
But why did you use single element hashes?
The natural representation of an ordered list of pairs would be:
my @required = (
[company => "Company is required"],
[address1 => "Address1 is required"],
[postcode => "Postcode is required"],
[phone => "Phone is required"],
);
Or if you want more hash-like behavour and don't mind using
non-builtin types:
use Tie::IxHash;
tie my %required, 'Tie::IxHash' => (
company => "Company is required",
address1 => "Address1 is required",
postcode => "Postcode is required",
phone => "Phone is required",
);
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 15 Dec 2003 11:06:27 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: newbie creating test help
Message-Id: <d7748$3fddea13$c2f0c83$31807@msgid.meganewsservers.com>
> Use "Test::More", it has a utility for that:
>
>
> ok( eq_array( $obj->splitted, $output));
Or you can even use is_deeply().
xoa
--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
------------------------------
Date: Mon, 15 Dec 2003 16:38:28 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Planning for maintenance
Message-Id: <x73cbmrq7v.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> Alan J. Flavell <flavell@ph.gla.ac.uk> wrote in comp.lang.perl.misc:
>> On Sun, 14 Dec 2003, Eric J. Roode wrote:
>>
>> > Second, imho, by fully-qualifying all of the function calls, you're
>> > making a lot of extra typing for yourself, and limiting future
>> > flexibility. If you choose to move half of the function calls to a
>> > different module someday, you'll have to edit all of the function
>> > call invocations to have the new module name, as opposed to simply
>> > changing a declaration or two at the top of each program.
>>
>> Indeed. On the other hand, if you'd had the bad-fortune to choose a
>> function name which later turned out to clash with some other needed
>> module...
> ...all is not lost. This renames a function on import:
> use Exporter::Renaming;
> use MyModule Renaming => [ clash => 'no_clash'];
i had proposed a grant project to TPF for a similar thing. this module
would actually be used by the module writer and not the user. it would
allow a user to either have an OO or procedural interface (similar to
what cgi.pm does) by having a private default object for the OO. but
because it would export names to the user namespace, i wanted to support
renaming in the use line. so the real module would use this (called
class::procedural) and list the exported names in some global (possibly
@EXPORT) and the user would pass a map (in the use line for the module
they want) of names to renames.
i will have to investigate Renaming to see how it does this. in any
case, the class::procedural stuff would still be useful if i ever get to
writing it. i can't get grants now that i am on the tpf steering
committee.
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: Mon, 15 Dec 2003 16:27:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: recursive closures?
Message-Id: <x78ylerqpw.fsf@mail.sysarch.com>
>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
> Uri Guttman <uri@stemsystems.com> writes:
>> my $sub ;
>> $sub = sub{ blah; $sub->() }
> That leaks.
it isn't real code anyhow. i don't recall if damian's leaked or he
weakened it.
> use Scalar::Util qw( weaken );
> my $weak_sub;
> my $sub = sub{ blah; $weak_sub->() }
> weaken($weak_sub = $sub);
it would only leak if you let it fall out of scope without destroying it
(but how?).
and i can't seem to find damian's stuff on google. i will email him
about it.
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: Mon, 15 Dec 2003 16:22:19 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Russian to Windows-1252 (htmlencode)
Message-Id: <Pine.LNX.4.53.0312151538410.9645@ppepc56.ph.gla.ac.uk>
On Mon, 15 Dec 2003, Bart Van der Donck wrote:
> Here is an image of the original characters:
> http://www.dotinternet.be/russi.gif
It's OK, I know what Cyrillic characters -look- like, but I still have
no idea whether you're starting from koi8-r, windows-1251, DOS-866,
utf-8 or what?
> Apparently, изменения is another encoding for that.
You posted with this header:
Content-Type: text/plain; charset=ISO-8859-1
which declares those to be accented Western characters. e-grave,
c-cedilla, etc...
I still don't know for certain what input encoding you are trying to
use, but it looks to me like Windows-1251.
> Thanks to Gunnar's subroutine, I got it working at server level.
>
> My end-goal is to make it work as a CGI:
> (1) capture the form input
Oh gosh, now we have to tangle with forms input, and already it's
clear that you're a bit shaky with character coding. I'm going to
have to say that -this- part of the task is way off topic for
c.l.p.misc. I have a web page that -might- be useful as background
http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html
but I repeat, this venue is -not- the right place for going into
detail about that.
> (2) URL decode it
> (3) pass it to HTML::Entities
> (4) query in database and see if the value exists
> (5) output the numeric entities (db values) in a Windows-1252 charset
Do you have a specific reason for this insistence on representing
Cyrillic characters using a proprietary 8-bit coding that's intended
for Western Roman content? It's not going to work in NN4 anyway.
> However, different browsers seem to understand the output differently.
URL of a test case? Circumstances of the difference? If it's only
NN4 that's causing the problem, then I can tell you for free that it
isn't going to work. You'd need to follow e.g this advice instead:
http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist.html#s6
http://ppewww.ph.gla.ac.uk/~flavell/charset/quick#cons
> Here is the perl code, as short as possible:
I'd rather see a static file as a test case first. We can worry about
the details of how you generate that file, afterwards.
But it's looking as if you have an HTML authoring problem or two to
solve, before you start writing Perl code.
------------------------------
Date: Mon, 15 Dec 2003 11:13:15 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <5a005$3fddebab$c2f0c83$31944@msgid.meganewsservers.com>
> You can't. Only C programs can be run when the server boots up.
What's the point of posting a misinforming reply like this, Abigail?
xoa
------------------------------
Date: 15 Dec 2003 19:01:25 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <slrnbts185.les.abigail@alexandra.abigail.nl>
Andy Lester (andy@petdance.com) wrote on MMMDCCLVIII September MCMXCIII
in <URL:news:5a005$3fddebab$c2f0c83$31944@msgid.meganewsservers.com>:
&&
&& > You can't. Only C programs can be run when the server boots up.
&&
&& What's the point of posting a misinforming reply like this, Abigail?
What's the point of asking non-Perl questions in a Perl group?
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: 15 Dec 2003 10:15:20 -0800
From: cool_ian10@hotmail.com (ThERiZla)
Subject: Subroutine return two Hash
Message-Id: <42f55bd6.0312151015.59e072e0@posting.google.com>
Hi,
I have a subroutine where I create two hash and I return it. But When
I check
after the subroutine if there is something and my two hash, the first
one is correct but the second one there is nothing in.
I check the two hash before I return it and my informations are in the
two hash.
This is my code:
my (%hash1, %hash2) = createHash();
# print the two hash
sub cresteHash {
# create Two Hash
return (%hash1, %hash2);
}
Anyone can explain me the method to do this ?
Thanks
------------------------------
Date: Mon, 15 Dec 2003 19:39:20 +0100
From: Karlheinz Weindl <karlheinz.weindl@oooonlinehome.de>
Subject: Re: Subroutine return two Hash
Message-Id: <brkv65$esr$1@online.de>
ThERiZla schrieb:
> Hi,
>
> I have a subroutine where I create two hash and I return it. But When
> I check
> after the subroutine if there is something and my two hash, the first
> one is correct but the second one there is nothing in.
> I check the two hash before I return it and my informations are in the
> two hash.
>
>
> This is my code:
>
> my (%hash1, %hash2) = createHash();
>
> # print the two hash
>
> sub cresteHash {
>
> # create Two Hash
>
> return (%hash1, %hash2);
> }
>
>
> Anyone can explain me the method to do this ?
Use references to hashes instead.
------------------------------
Date: Mon, 15 Dec 2003 19:42:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Subroutine return two Hash
Message-Id: <brkve1$4ha2k$1@ID-184292.news.uni-berlin.de>
ThERiZla wrote:
> I have a subroutine where I create two hash and I return it.
<snip>
> sub cresteHash {
> # create Two Hash
> return (%hash1, %hash2);
> }
That does not return two hashes. It returns one list whose elements
are the keys and values of both the hashes. Please study
http://www.perldoc.com/perl5.8.0/pod/perlsub.html
> Anyone can explain me the method to do this ?
Have the subroutine return hash references instead:
my ($hashref1, $hashref2) = createHash();
print "$_ = $hashref1->{$_}\n" for keys %$hashref1;
print "\n";
print "$_ = $hashref2->{$_}\n" for keys %$hashref2;
sub createHash {
# create Two Hash
return (\%hash1, \%hash2);
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 15 Dec 2003 17:38:49 GMT
From: Erik Tank <jundy@jundy.com>
Subject: ticks and FreeBSD
Message-Id: <6302448fd113d8e641d4b4820ac9d10b@news.teranews.com>
I just migrated a program from RedHat 9 to FreeBSD 5.1. Everything is
working well with the exception of the following:
my @jmail_return_lines = `ps -aux | grep 'jmaild' | grep -v grep`;
The baisc idea is that I want to see if a program called jmaild is
running. On RedHat 9 it @jmail_return_lines would contain the ps -aux
lines but under FreeBSD it returns nothing even though when I take the
command in the ticks and run it from the command line it does return a
line.
Any help or suggestions would be greatly appreciated.
Erik
------------------------------
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 5942
***************************************