[22928] in Perl-Users-Digest
Perl-Users Digest, Issue: 5148 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 27 21:05:31 2003
Date: Fri, 27 Jun 2003 18: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 Fri, 27 Jun 2003 Volume: 10 Number: 5148
Today's topics:
Re: Better Way <johannes.fuernkranz@t-online.de>
Re: BTree examples ?? <minceme@start.no>
Re: BTree examples ?? <joerg@objectpark.org>
Re: Fun with Threads - "Attempt to free unreferenced sc (Bryan Castillo)
Re: Hash::Utils lock_keys (Jay Tilton)
Re: Hash::Utils lock_keys <johannes.fuernkranz@t-online.de>
Mail::Sendmail cannot connect to localhost but the mail (Andres Monroy-Hernandez)
Re: Mail::Sendmail cannot connect to localhost but the <tony_curtis32@yahoo.com>
Re: need assistance understanding multilevel hashes. (Jay Tilton)
No error for calling undefined sub's? (kalasend)
Re: No error for calling undefined sub's? <noreply@gunnar.cc>
Re: Problem with fork <ndronen@io.frii.com>
Reading JPEG file <zvone.zagar@siol.net>
Re: running UNIX with perl <mgjv@tradingpost.com.au>
Re: scalars and namespace <noreply@gunnar.cc>
Re: UNIX Domain sockets on HPUX <russ.jones2@boeing.com>
Re: Using local $/ (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Jun 2003 01:26:37 +0200
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Better Way
Message-Id: <bdijrs$okv$05$1@news.t-online.com>
Abigail wrote:
|
> `' $line = join ' ', (split ' ',$line)[8];
>
> That join doesn't make much sense. (...)[8] indexes on a list,
> returning exactly one element. The join then becomes very trivial.
You're right. I meant [0..8], of course.
> $line = (split ' ', $line) [8];
>
> `' Or maybe you want something like
> `'
> `' $line = ($line =~ m/^(([^ ]+ ){8})/);
>
> That's not the same. Your regex would even fail if there are 2 spaces
> in a row. If the first argument of split equals ' ', special things
> happen. See the manual page of split for details.
The keyphrase here was "something like"...
[ I also blew the lvalue on the left, which should have been ($line) ]
Juffi
------------------------------
Date: Fri, 27 Jun 2003 22:30:45 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: BTree examples ??
Message-Id: <bdigil$a5a$1@troll.powertech.no>
Paul Marquess <paul.marquess@btinternet.com> wrote:
> The DB_File module, that comes with Perl, has a btree opion. You can
> easily store hundres of thousands of key/data pairs in it.
>
>
> The example below is derived from the docuemntation that comes with
> DB_File
>
> use warnings ;
> use strict ;
> use DB_File ;
>
> my %h ;
> tie %h, "DB_File", "tree", O_RDWR|O_CREAT, 0666, $DB_BTREE
> or die "Cannot open file 'tree': $!\n" ;
>
> # Add a key/value pair to the file
> $h{'Wall'} = 'Larry' ;
> $h{'Smith'} = 'John' ;
> $h{'mouse'} = 'mickey' ;
> $h{'duck'} = 'donald' ;
>
> # Delete
> delete $h{"duck"} ;
>
> # Cycle through the keys printing them in order.
> # Note it is not necessary to sort the keys as
> # the btree will have kept them in order automatically.
> foreach (keys %h)
> { print "$_\n" }
>
> untie %h ;
>
> Paul
( I'm not sure about this, but I think I'm right: )
A small note: If you have a very big hash, you'd might like to save
memory by doing
while ( (my $k, undef) = each %h ) {
print "$k\n";
}
instead of using the foreach loop in the above example.
--
Vlad
------------------------------
Date: Fri, 27 Jun 2003 15:04:18 +0000
From: =?ISO-8859-1?Q?J=F6rg?= Westheide <joerg@objectpark.org>
Subject: Re: BTree examples ??
Message-Id: <0306QYvULoUrv0yfMhx3ae8Ayw@objectpark.org>
Hi!
> I am wondering if anyone has an example of using BTree for
> storing data on a disk file.?? I found some BTree modules on the
> web, but none give example of how you would then store it and retrieve
> it from disk drive.
Have a look at the DB_File module
> I have a need to store hundred of thousands of
> key, data values
That's no problem (I used it with some millions)
The only backdraw I discovered, is the really bad performance on=20
Win(2K), it's fine on Linux though
J=F6rg
------------------------------
Date: 27 Jun 2003 17:24:30 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Fun with Threads - "Attempt to free unreferenced scalar during global destruction."
Message-Id: <1bff1830.0306271624.2065b23c@posting.google.com>
Stuart Moore <stjm2@hermes.cam.ac.uk> wrote in message news:<Pine.SOL.4.44.0306271347280.25299-100000@orange.csi.cam.ac.uk>...
> My aim is to have a module, "ToolsThread", which I can pass commands to so
> that it'll execute them in its own thread. However when I call join on the
> thread, it seems to all go wrong. It all behaves as normal up to the point
> I call join on the thread in the quit function, then it gives me the
> message
>
> Attempt to free unreferenced scalar during global destruction.
>
> I'm not sure what that means, but I don't like it.
>
> Here is the relevant code (ToolsThread.pm is the module, testToolsThread
> is a basic test script. I would have more code in the loop eventually,
> assuming I can get it to work)
>
> ##ToolsThread.pm
> package ToolsThread;
>
> use strict;
> use warnings;
> use threads;
> use threads::shared;
> use Thread::Queue;
>
> our $queue = new Thread::Queue;
> our $thread = threads->create(\&Run,$queue);
# change to this (I don't know why it is like this though)
our $thread = threads->create("Run",$queue);
>
> sub Run{
> my $queue = shift;
> while(1){
> my $incoming = $queue->dequeue;
> if ($incoming eq "quit"){
> last;
> }
> }
> }
>
> sub Quit{
> $queue->enqueue('quit');
> $thread->join();
> }
>
> ##testToolsThread.pl
> use strict;
> use warnings;
> use threads;
> use threads::shared;
> use Thread::Queue;
> use ToolsThread;
>
> ToolsThread::Quit;
------------------------------
Date: Fri, 27 Jun 2003 22:07:23 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Hash::Utils lock_keys
Message-Id: <3efcb0c8.507065990@news.erols.com>
=?ISO-8859-15?Q?Johannes_F=FCrnkranz?=
<johannes.fuernkranz@t-online.de> wrote:
: I looked through Hash::Util, of course. Sorry if this was not obvious
: from my posting. But I find the assumption that sbdy posts a question on
: a module w/o looking at perldoc a bit presumptious.
The assumption is accurate with sickening frequency.
: I think this was clearly not a newbie question.
Really? Neophytes adore asking "What does X do?" and expecting
readers to break out the PSI::ESP module to see the real question they
wanted to ask.
: Yes, but Hash::Util also tells me that the hash-lock "is intended to
: largely replace the deprecated pseudo-hashes."
One feature of a pseudohash is that it does not allow keys to be added
or removed accidentally. Hash::Util gives exactly that capability to
any ordinary hash with far fewer hoops to jump through.
The dual hash/array nature of a pseudohash isn't there, but who ever
used that anyway?
: Now, if I remember correctly, these pseudo-hashes were meant to combine
: the better of arrays (smaller and faster) and hashes (can take any
: keys).
I never was able to reconcile the "smaller and faster" claim with
expectation. Seems they would be neither smaller, since there's a
hash taking up space alongside the array elements, nor faster, since
using their hash nature requires Perl to look up the array index in a
hash then look up the array element.
No matter. Even if pseudohashes do provide speed/storage benefits,
Hash::Util doesn't.
: And Hash::Util doesn't really answer these questions (at least not for me).
Nope. It sure doesn't. I get the feeling that the porters want
pseudohashes to go away ASAP, and the less mentioned about them, the
better.
------------------------------
Date: Sat, 28 Jun 2003 01:36:40 +0200
From: =?ISO-8859-15?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Hash::Utils lock_keys
Message-Id: <bdikem$p1i$05$1@news.t-online.com>
Jay Tilton wrote:
>
> : Now, if I remember correctly, these pseudo-hashes were meant to combine
> : the better of arrays (smaller and faster) and hashes (can take any
> : keys).
>
> I never was able to reconcile the "smaller and faster" claim with
> expectation. Seems they would be neither smaller, since there's a
> hash taking up space alongside the array elements, nor faster, since
> using their hash nature requires Perl to look up the array index in a
> hash then look up the array element.
I never quite got that either. I think it only worked with 'use fields'
to get some compile-time optimization, but it was awkward in any case.
> No matter. Even if pseudohashes do provide speed/storage benefits,
> Hash::Util doesn't.
I see. Too bad.
Thank you!
Juffi
------------------------------
Date: 27 Jun 2003 16:52:32 -0700
From: andres@monroy.com (Andres Monroy-Hernandez)
Subject: Mail::Sendmail cannot connect to localhost but the mail command can
Message-Id: <3591b31a.0306271552.36a45fc9@posting.google.com>
Hello,
I have a script that uses Mail::Sendmail, this script works just fine
in 4 different boxes (RedHat and Solaris).
Nevertheless, there is this Solaris machine where it doesn't work, and
this is the error I get in the $Mail::Sendmail::error variable:
connect to localhost failed (Connection refused)
The thing that puzzles me, is that in the same machine, the mail
command works just fine.
<snipet>
39 sfx@et2:ver_2> mail andres@monroy.com
testing
.
</snipet>
As far as I know, mail tries to send emails via the localhost SMTP
just as Mail::Sendmail does.
I also tried changing the host name in Mail::Sendmail from localhost
to the server's IP and host name, but it didn't work either.
Any comments are appreciated.
-Andrés
------------------------------
Date: Fri, 27 Jun 2003 18:58:32 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Mail::Sendmail cannot connect to localhost but the mail command can
Message-Id: <87y8zn139z.fsf@limey.hpcc.uh.edu>
>> On 27 Jun 2003 16:52:32 -0700,
>> andres@monroy.com (Andres Monroy-Hernandez) said:
> Hello, I have a script that uses Mail::Sendmail, this
> script works just fine in 4 different boxes (RedHat and
> Solaris).
> Nevertheless, there is this Solaris machine where it
> doesn't work, and this is the error I get in the
> $Mail::Sendmail::error variable:
> connect to localhost failed (Connection refused)
> The thing that puzzles me, is that in the same machine,
> the mail command works just fine.
> <snipet> 39 sfx@et2:ver_2> mail andres@monroy.com
> testing . </snipet>
This just requires a locally installed sendmail (or some
other MTA like postfix) into which mail/mailx can inject
the message. It doesn't require an SMTP service.
I'd wager there's an SMTP server running on all the other
machines (probably sendmail -bd) but not on this one, or
the other boxes are configured as clients to a local mail
hub, and this one isn't.
(If so, we've wandered out of perl territory. You
probably want to take a step back and re-think your local
mail setup first.)
hth
t
------------------------------
Date: Fri, 27 Jun 2003 22:16:39 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <3efcc085.511095730@news.erols.com>
Allen Wooden <allen.wooden@educate.invalid> wrote:
: On Thu, 26 Jun 2003 22:18:31 GMT, tiltonj@erols.com (Jay Tilton)
: wrote:
: >
: >Some clarification is needed there. Some example code would help.
:
: The program is a report front-end to RRDTOOL which takes the customer
: name as one of the command line args, the second being the date range
: (MM-YYYY) and pulls the 95th % for that customer's port and prints out
: a nice little summary of the utilization.
:
: The config file looks like this: (i'll only show one customer for sake
: of brevity, the others are similar.
: Sorry if the wrapped lines make things difficult to follow.
:
: configfile:
: %customer1 = ( "ports" => "2", "rrd0" =>
: '/usr/local/mrtg/rrdfiles/10.15.0.19.1.rrd', "rrd1" =>
: '/usr/local/mrtg/rrdfiles/10.15.0.19.3
: .rrd', "rrd2" => '/usr/local/mrtg/rrdfiles/10.15.0.7.1.rrd', "rrd3" =>
: '/usr/local/mrtg/rrdfiles/10.15.0.7.3.rrd', "rate" => "450000
: 00", "page_num" => "2", "tag" => 'Customer1' );
:
: At runtime, the user would enter.. ./prog ( -h (usage display)) or
: ./prog customer1 MM-YYYY
:
: I'll include all the code,
Yipe.
Example code is one thing. A complete program is another.
Posting entire programs is seldom necessary, and even less often
desirable. Reducing code to the barest minimum necessary to
demonstrate the problem eases comprehension of the problem and its
solution.
[Relevant portions of code retained in comments.]
: >Are you saying the configuration file is executable Perl that defines
: >hashes, and the desired hash can only be accessed by its name? E.g.
: >
: > %Fred = ( spouse => 'Wilma', child => 'Pebbles' );
: > %Barney = ( spouse => 'Betty', child => 'Bam Bam');
: >
: I run the config file using 'do' to pull the hashes in.
Gotcha. The config file is indeed Perl code.
: I found that I
: had to use 'our (%customer_names) etc ahead of time in order for those
: hashes I pull in to be seen.
Makes sense. Declaring them with my() would create a new set of
variables whose scope is restricted to the program.
: Seems that those hases go out of scope
: and disappear right after I run the config file otherwise.
Sort of right. A set of hashes declared with my() would exist
independently of the ones defined in the config file, while package
variables, declared with our(), never go out of scope.
: Accessing
: it by name is the only way I can see to do this, if there is a better
: way by all means let a newbie know.. :)
Count on it. :)
: >Like, say,
: >
: > $customer_name = 'Fred';
: > %customer_data = %$customer_name;
: >
: Your making a symbolic reference there am I right? I read that that is
: not a 'good thing to do'.
Exactly right on both points. It deserved a "don't do this" note.
: >If I've gauged the problem accurately, you're SOL due to a bad design
: >decision from the past.
:
: A bad design decision on my part?
Instead of pointing fingers, I was taking the coward's path of
assigning blame to an anonymous "damned previous programmer." But
since the program is still in its youth, setting things on track now
is a Good Thing and an Easy Thing.
: >You should really want a private namespace--your own hash-of-hashes to
: >thrash around in.
: >
: > %customers = (
: > Fred => { spouse => 'Wilma', child => 'Pebbles' },
: > Barney => { spouse => 'Betty', child => 'Bam Bam' },
: > );
: > $customer_name = 'Fred';
: > %customer_data = %{ $customers{$customer_name} };
: >
: This is where I'm having some trouble.
What is that trouble?
The least intrusive modification would be to leave the separate hash
definitions alone, then create another hash of references to those
hashes, e.g.
my %customer1 = ( "ports" => 2, ... );
my %customer1 = ( "ports" => 3, ... );
# etc.
our %customers = (
customer1 => \%customer1,
customer2 => \%customer2,
# etc.
);
So %customers becomes the private namespace I mentioned before.
Declaring %customer1 and %customer2 with my() restricts their scope to
the config file. Outside of that scope, they are inaccessible except
by going through the package variable %customers, which is accessible
from anywhere.
Slightly more intrusive but also more scalable is to create a hash of
anonymous hashes directly.
our %customers = (
customer1 => { "ports" => 2, ... },
customer2 => { "ports" => 3, ... },
# etc.
);
For either case, instead of saying
if ( $custid =~ /^customer1$/ ) { %custid = %customer1; }
if ( $custid =~ /^customer2$/ ) { %custid = %customer2; }
you would say
my %custid = %{ $customers{$custid} };
and validate the value in $custid by checking whether
$customers{$custid} is defined, instead of matching its value against
a static regex.
As a bonus, counting the customers becomes much simpler and less
fragile. Instead of opening the file again and scanning for
'%' characters, say
$count = keys %customers;
: I guess what I'm trying to do is get the config file to drive the
: program and allow me not to have to modify the prog whenever I add a
: new customer.
A worthwhile design point, and one that is perfectly achievable.
------------------------------
Date: 27 Jun 2003 17:05:01 -0700
From: kalasend@yahoo.com (kalasend)
Subject: No error for calling undefined sub's?
Message-Id: <bb2cde26.0306271605.7a2addd6@posting.google.com>
Hi,
I am having this problem:
Since some point in time the script is not complaining about calls of
any undefined subroutines(e.g. by a typo). It simply exits, like it
finished running. It didn't use to do that but I can't possibly
remember what change I made caused this.
What is likely to be wrong here?
thanks
ben
------------------------------
Date: Sat, 28 Jun 2003 02:12:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: No error for calling undefined sub's?
Message-Id: <bdimk2$rmiqf$1@ID-184292.news.dfncis.de>
kalasend wrote:
> Since some point in time the script is not complaining about calls
> of any undefined subroutines(e.g. by a typo). It simply exits, like
> it finished running. It didn't use to do that but I can't possibly
> remember what change I made caused this.
> What is likely to be wrong here?
How about posting a simple script that illustrates the phenomenon?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 27 Jun 2003 23:29:22 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: Problem with fork
Message-Id: <3efcd352$0$197$75868355@news.frii.net>
Krishna <kgundlapalli@hotmail.com> wrote:
K> Hi -
K> I am using 'fork' to execute a child process (a perl program) in my
K> CGI.
K> When the user submits the page, I am displaying a status page (created
K> by a CGI)
K> and forking the my external process. However spawning of this external
K> process is redisplaying the the status page below the original page
K> (means I am getting a TILED page of my status page).
K> $pid = fork;
K> if ($pid)
K> { return 1; }
K> else {
K> close STDOUT;
close STDERR; # perhaps you need this as well?
K> exec "/usr/local/bin/perl /../../push.pl ";
Trailing whitespace aside, "/../../push.pl " is equivalent
to "/push.pl". Is this how it appears in your code?
Regards,
Nicholas
--
"Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
"Meanings are another story." http://www.ifas.org/wa/glossolalia.html
------------------------------
Date: Sat, 28 Jun 2003 02:05:26 +0200
From: Zvone Zagar <zvone.zagar@siol.net>
Subject: Reading JPEG file
Message-Id: <l_4La.1859$78.94796@news.siol.net>
Hello!
I am new to this list. I have a problem, which bothers me for days.
I would like to read a jpg image, get data (decode) out of it and make a
postscript file from scratch. I can get width, height, color depth but I
don't know how to make a hex string needed for postscript.
Postscript line should look like: width height depth matrix {<hex data>}
false 3 colorimage.
I know I could use Perl/Tk and its widgets. But I need to do it without Tk.
There is also an excellent module PDF::API2 for creating pdf files.
I have searched for days, but found almost nothing (except some excerpts
from C code).
I hope I made myself clear enough. Any help would be appreciated.
Thanks Zvone Zagar
------------------------------
Date: Sat, 28 Jun 2003 09:33:58 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: running UNIX with perl
Message-Id: <slrnbfpl36.rlm.mgjv@martien.heliotrope.home>
On Fri, 27 Jun 2003 21:06:52 GMT,
joe <tunmaster@hotmail.com> wrote:
> Great, using the exact address, captured by 'which mysqldump', was the
> solution indeed!
Great.
Now, to avoid all the mistakes that everyone has already made once
before while working in a CGI environment, please read the first
question in the Perl FAQ, section 9, and follow some of the links
suggested there.
Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
| about its friends.
|
------------------------------
Date: Sat, 28 Jun 2003 00:06:20 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: scalars and namespace
Message-Id: <bdif87$tq1us$1@ID-184292.news.dfncis.de>
Jeff Thies wrote:
> I have all these "config" files with lists of global scalars:
>
> config_1.cfg
> ###########
>
> $scalar1='something';
> $scalar2='something_else';
>
>
> #########
>
> That worked for me in that I could import those scalars like this:
>
> require 'path_to/config_1.cfg';
>
> Now I want to import those into a sub and make that list of scalars
> local to that sub. (I want to do something with the list of scalars in
> all these "config" files one file at a time) How do I do that?
One way:
sub mysub {
my ($scalar1, $scalar2);
open FH, 'config_1.cfg' or die "Can't open... $!";
eval while <FH>;
close FH;
[do something]
}
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 27 Jun 2003 18:21:38 GMT
From: Russ Jones <russ.jones2@boeing.com>
Subject: Re: UNIX Domain sockets on HPUX
Message-Id: <Xns93A787EB5B24Drussjones2boeingcom@192.54.3.19>
Russ Jones <russ.jones2@boeing.com> wrote in
news:Xns93A7513BAAF9Brussjones2boeingcom@192.54.3.19:
> I'm trying to use UNIX Domain sockets on HPUX 11.11, using Perl 5.6.1
> for PA-RISC2.0, the IO::Socket module, without much luck.
>
I figured it out. There's a typo in the Perl Cookbook, which would have
made the call fail anyway, but the real issue is that SOCK_DGRAM is not
supported for UNIX Domain sockets (at least on HPUX it's not).
So I tried SOCK_STREAM and now all the workers are happy.
------------------------------
Date: Fri, 27 Jun 2003 16:19:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using local $/
Message-Id: <slrnbfpd6s.3sc.tadmc@magna.augustmail.com>
derek / nul <abuse@sgrail.org> wrote:
> How do I now get my file to a series of characters so I can search the string
> and replace the 2 lines after the successful search?
You do not need to get the "file" to a series of characters so that
you can search and replace.
The s/// operator operates on _strings_, and you already have
a string, you are good to go!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 5148
***************************************