[22760] in Perl-Users-Digest
Perl-Users Digest, Issue: 4981 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 14 06:05:50 2003
Date: Wed, 14 May 2003 03:05:14 -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 Wed, 14 May 2003 Volume: 10 Number: 4981
Today's topics:
Re: @Array - making it null (Villy Kruse)
Re: bootstrap <kalinabears@hdc.com.au>
Can't locate sub.pl <pierre@couderc.cc>
Re: Can't locate sub.pl (Anno Siegel)
Conversion systems <kubusieczek@poczta.onet.pl>
Re: disk usage script <krahnj@acm.org>
Getting windows 2000 remote login name (KieranK)
Re: Help: Perl Modules for Newbie non-administrator? (James E Keenan)
Re: Help: Working with a hash of hashes? (James E Keenan)
Re: High CPU usage and mem leak problem in a perl routi <no@spam.for.me.invalid>
Re: High CPU usage and mem leak problem in a perl routi <anthony@no_spam.movielink.net.au>
Re: High CPU usage and mem leak problem in a perl routi (Anno Siegel)
How to recover %CPU, Memory usage and size of a process (fafanie)
Re: how to set INC globally <spanda@cisco.com>
Re: How to Store and Print this Array? <REMOVEsdnCAPS@comcast.net>
Inserting a child node at an arbitrary point in a tree <dodger@dodger.org>
Re: Inserting a child node at an arbitrary point in a t <dodger@dodger.org>
Re: Inserting a child node at an arbitrary point in a t <dodger@dodger.org>
Re: Inserting a child node at an arbitrary point in a t <dodger@dodger.org>
Re: MYSQL images <simon.andrews@bbsrc.ac.uk>
Re: MYSQL images <musicman@hotmail.com>
Re: Negating phrases <allanon@hotmail.com>
No data entering @array from open(DATA...) <sammie@greatergreen.com>
Re: No data entering @array from open(DATA...) <sammie@greatergreen.com>
Re: No data entering @array from open(DATA...) <jurgenex@hotmail.com>
Re: No data entering @array from open(DATA...) <sammie@greatergreen.com>
Re: No data entering @array from open(DATA...) <g4rry_short@zw4llet.com>
Re: No data entering @array from open(DATA...) (Anno Siegel)
Re: Question about News::NNTPClient Method (a bit long) <jasonp@uq.net.au>
Why do I get double line feeds <dingdongy2k@hotmail.com>
Re: Why do I get double line feeds <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 May 2003 07:51:41 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: @Array - making it null
Message-Id: <slrnbc3tcc.454.vek@station02.ohout.pharmapartners.nl>
On 13 May 2003 11:29:06 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Villy Kruse <nobody> wrote in comp.lang.perl.misc:
>> On Tue, 13 May 2003 03:14:07 GMT,
>> Uri Guttman <uri@stemsystems.com> wrote:
>>
>>
>> >>>>>> "BV" == Balaji Venkataraman <dont-reply@this.address> writes:
>> >
>> > BV> So now that the experts say that undef is not a good thing to do, I
>> > BV> have a question.
>> >
>> > BV> I've see people do this to read the whole file in one fell swoop:
>> >
>> > BV> Code 1
>> > BV> ------
>> > BV> local $/ = undef;
>> >
>> >the undef is redundant. local $/ will set it to undef.
>> >
>>
>>
>> I've been searching the manual pages for this piec of information, but it
>> appears to be missing. If you don't know that my $xx and local $xx also
>> sets the initial value everytime the statement is executed at runtime
>> you may be more comfortable setting the value explicitely to undef.
>
>The run time behavior of "my" and "local" is described in perlsub, not
>in the individual descriptions in perlfunc which only point to perlsub.
>That should probably be amended.
>
Perhaps by providing examples like:
my $abc = undef;
my $abc; # sets initial value to undef; equivalent
# to previous line
my @abc = ();
my @abc; # sets initial value to empty array; equivalent
# to previous line
my %abc = ();
my %abc; # sets initial value to empty hash; equivalent
# to previous line
And similar for local.
If that is indeed the correct interpretation.
Villy
------------------------------
Date: Wed, 14 May 2003 12:56:01 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: bootstrap
Message-Id: <3ec1b153$0$12175@echo-01.iinet.net.au>
"Sisyphus" <kalinabears@hdc.com.au> wrote in message
> > One of the things this function can usefully do is check whether
> > the library version is in the expected bracket.
> >
>
> Apparently so - though I'm not sure how.
> I have version 0.191 of Win32. I opened Win32.pm and amended 'bootstrap
> Win32;' to 'bootstrap Win32 $VERSION;'. I then ran a script that
contained:
> use warnings;
> use Win32;
> print "$Win32::VERSION\n";
>
> I then altered the version number to 0.100 (and subsequently to 0.200) -
> expecting I might get some compaint when I ran the script. But there was
no
> complaint. The script faithfully produced the version number that I had
> bestowed upon the module.
>
It has now dawned on me that the above testing was flawed, because I didn't
re-compile Win32.
Had I have made the above alteration to Win32.pm and then *re-compiled* the
module, I would have encountered the version mismatch errors I was
expecting.
Cheers,
Rob
------------------------------
Date: Wed, 14 May 2003 11:16:12 +0200
From: Pierre Couderc <pierre@couderc.cc>
Subject: Can't locate sub.pl
Message-Id: <b9t1gs$umi$1@biggoron.nerim.net>
I have a sporadic error in my mod_perl script:
I have 2 files in /var/www/perl/ directory :
sub.pl
------
subroutine mysub{
...
}
main.pl
-------
require './sub.pl';
...
mysub();
Using Apache+mod_perl and the correct URL, I call main.pl, and all is fine :
mysub() is correcly executed.
But, later sporadicly, when repeating the execution, I got the message in error.log:
[Wed May 14 07:23:43 2003] [error] Undefined subroutine mysub called at
/var/www/perl/main.pl line xxx
Adding traces, I got the message "can't locate ./sub.pl"
I have tried to
- replace './sub.pl' with 'sub.pl'
- checked that no other sub.pl file exists on my server
- replaced mysub() with xwdfdfgd() to check that there are not 2 subroutines
with the same name/
- restarted Apache 30000 times to be well sure that my cache is empty
- cried : but it does not work :-)
Thank you in advance for any idea
Pierre Couderc
------------------------------
Date: 14 May 2003 09:39:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can't locate sub.pl
Message-Id: <b9t2rt$plh$3@mamenchi.zrz.TU-Berlin.DE>
Pierre Couderc <pierre@couderc.cc> wrote in comp.lang.perl.misc:
> I have a sporadic error in my mod_perl script:
>
> I have 2 files in /var/www/perl/ directory :
>
> sub.pl
> ------
>
> subroutine mysub{
> ...
> }
>
> main.pl
> -------
>
> require './sub.pl';
When you require a file with a relative path, you rely on the current
directory. That is unwise. While CGI processes usually run with
the current directory that of the executable itself, this is only
a convention and not part of the interface.
> ...
> mysub();
>
> Using Apache+mod_perl and the correct URL, I call main.pl, and all is fine :
> mysub() is correcly executed.
>
> But, later sporadicly, when repeating the execution, I got the message
> in error.log:
>
> [Wed May 14 07:23:43 2003] [error] Undefined subroutine mysub called at
> /var/www/perl/main.pl line xxx
>
> Adding traces, I got the message "can't locate ./sub.pl"
It looks like sometimes the current directory is where sub.pl is
located and sometimes it isn't.
Check out the module FindBin. It will allow you to create the full
path name for sub.pl, or make sure the current directory is what you
expect it to be.
Anno
------------------------------
Date: Wed, 14 May 2003 11:52:03 +0200
From: "Kuba" <kubusieczek@poczta.onet.pl>
Subject: Conversion systems
Message-Id: <b9t3lt$j2b$1@news.onet.pl>
Hello everybody,
At the begining of my existing at this group I say a few words about me.
Generally I'm Polish (I live in Warsaw, Poland) student (not IT), but IT is
my the most interesting hobby. For a short period of time I learn Perl.
Today I stroke upon an idea about writing script in Perl, what it would be
recount from number givin' in one system for other systems (eg: When I would
entered the number '255' in decimal system this program shows me other
values like that
> Enter the number what you can recount (prompt from programm): 255, and in
next a few lines program gives me other values in other systems (sth like
that):
255 (dec) ----- [0]377 (oct) ----- [0b]1111111 (bin) ----- [0x]FF
I would like, that this program working in this case that when I enter some
number in one of every systems this program gives other values in other
systems itself.
Do you know when I could find some help for this subject, or if I can't find
help anywhere could You give me some information about it ?
I would be very satisfited for Your answer and help.
TYIA
Best Regards
James
------------------------------
Date: Wed, 14 May 2003 05:13:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: disk usage script
Message-Id: <3EC1D04E.E36B4399@acm.org>
Shawn wrote:
>
> I currently us this script to add up the disk usage for each user and
> ranking them by usage, in a rather expansive directory.
>
> /opt/bin/find . -ls -mount | perl -ne 'chomp; $u{(split(/\s+/))[5]}
> +=(split(/\s+/))[7]; END {foreach $key (sort {$u{$b} <=> $u$a}} keys
> %u){printf "%-5s %-10d\n",$key, $u{$key};}}'
>
> Recently we have migrated to new servers and the script started acting
> differently.
> Instead of adding up the usage by the userid it now uses the group of the
> users.
>
> This is what it used to look like:
>
> greg 4297
> fred 678
> sue 605
> joe 51
>
> It is now returning this:
>
> joegrp 0
> suegrp 0
> other 0
>
> So, really it isn't adding the numbers right either. When I run the find
> command alone I return this:
>
> 6600512 4 -rwxr-xr-x 1 fred joegrp 678 Dec 10 1998
> ./NYRV/GQ19NYR1.sql
> 6600513 4 -rwxr-xr-x 1 sue suegrp 605 Dec 10 1998
> ./NYRV/GQ19NYR2.sql
> 6600514 4 -rwxr-xr-x 1 greg joegrp 1610 Dec 10 1998
> ./NYRV/GQ19NYRV.doc
> 6600515 0 -rwxr-xr-x 1 joe suegrp 51 Dec 10 1998
> ./NYRV/GQ19NYRV.pkg
> 6600516 4 -rwxr-xr-x 1 greg joegrp 2687 Aug 10 2000
> ./NYRV/GQ19NYRV.sh
>
> The guy who produced the script is no longer here and I can't get any
> assistance due to the server migration and its well above my head.
> Any assistance in correcting this problem would be greatly appreciated!
You can do it in perl like this:
perl -MFile::Find -le '($m) = stat( $d = shift );
find( sub{ @s = lstat; $m == $s[0] and $u{ getpwuid $s[4] } += $s[7]},
$d );
printf "%-5s %d\n", $_, $u{$_} for sort { $u{$b} <=> $u{$a} } keys %u' .
John
--
use Perl;
program
fulfillment
------------------------------
Date: 14 May 2003 02:27:42 -0700
From: kkontour@yahoo.com (KieranK)
Subject: Getting windows 2000 remote login name
Message-Id: <a402dfea.0305140127.7decc3e8@posting.google.com>
Hello,
I am trying to find a reliable method of getting the username of
someone who is logged in at a remote Windows 2000 PC. I am using
Win32::NBTStat to get the information but it does not always bring
back the name. Surely there must be some better method.
use Win32::NBTStat;
my $fullip="IP OF REMOTE PC";
my $nbtstat = new Win32::NBTStat( ip => $fullip );
my $user = lc($nbtstat->username);
my $machine = lc($nbtstat->computername);
Regards
KieranK
------------------------------
Date: 13 May 2003 19:02:42 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Help: Perl Modules for Newbie non-administrator?
Message-Id: <b955da04.0305131802.6fdb5987@posting.google.com>
email_entropy123@yahoo.com (entropy123) wrote in message news:<90cdce37.0305131447.6e70a94e@posting.google.com>...
> Hey all,
>
> I'm working on a thorny problem and a perl module was suggested as the
> cure. Only thing is I am not an administrator and can't get the damned
> thing to work ...Am pretty sure my admin doesn't know a lot about
> perl....
>
> It works all the way to the final step:% make install
>
> the error message is:
> Warning: You do not have permissions to install into
> /usr/lib/perl5/site_perl/5.6.1/i386-linux at
> /usr/lib/perl5/5.6.1/ExtUtils/Install.pm line 85.
> mkdir /usr/lib/perl5/site_perl/5.6.1/Graph: Permission denied at
> /usr/lib/perl5/5.6.1/ExtUtils/Install.pm line 139
> make: *** [pure_site_install] Error 255
>
>
As the error message suggests, you don't have write permission on the
directory where your system installs new Perl modules. You can either
have your sysadmin install it there with his root privileges, or you
can install it in a directory under your own home directory. If you
follow the instructions for installation via 'make' in the perldoc
reference below, you will have to modify one line of code in a manner
like this:
perl Makefile.PL LIB=/home/entropy123/Perl/lib
> Is there a good faq on this? or anyone with advice?
>
perldoq -q install
Have your sysadmin read this and s/he'll at least learn how to install
Perl modules.
------------------------------
Date: 13 May 2003 18:48:16 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Help: Working with a hash of hashes?
Message-Id: <b955da04.0305131748.68d8756@posting.google.com>
email_entropy123@yahoo.com (entropy123) wrote in message news:<90cdce37.0305131418.df9d528@posting.google.com>...
> Is there any way to separate out the values in my supha{}{} into a set
> of arrays? Or even into keys and values?
>
Multi-dimensional hashes work like single-dimensional hashes: You can
call 'keys %supha' to get a list of the keys and 'values %supha' to
get a list of the values. The only difference is that in a
multi-dimensional hash the values are references (in this case, refs
to other hashes) rather than numerals or character strings.
> The code where I create supha is as follows:
>
> $supha{$tid[$one]}{$tid[$two]} = $three;
> $supha{$tid[$two]}{$tid[$one]} = $three;
>
Why are you using array elements as hash keys rather than ordinary
scalars? I.e., why not:
$supha{$x}{$y} = $three;
$supha{$y}{$x} = $three;
[snip]
>
> My other question would be how do I get specific values out of
> supah...? I've been using for, while and other loops...but it seems
> cumbersome....
>
It would help if you showed us the code which you consider cumbersome.
How about this for a 2-dimensional hash:
foreach my $v (keys %supha) {
foreach (keys %$v) {
print "key: $_\tvalue: ${$v}{$_}\n";
}
}
HTH
------------------------------
Date: Wed, 14 May 2003 08:57:06 GMT
From: "Nils Petter Vaskinn" <no@spam.for.me.invalid>
Subject: Re: High CPU usage and mem leak problem in a perl routine
Message-Id: <pan.2003.05.14.08.57.06.909543@spam.for.me.invalid>
On Wed, 14 May 2003 10:18:22 +1000, Tony wrote:
> I have one suspicion, when you fork a process, all the variables, file
> handles etc. remain the same. I do not close the file handle in the
> child process, I do not even use it there. Would that be the problem?
>
>
open FILE $filename;
@array = <FILE>;
close FILE;
process(@array)
Should take care of it if the problem is the children inheriting
filehandles. Don't know if it is. Anyway not having to reopen the file all the
time would probably be a good idea since when you open the file all the
time it'll probably live in the filesystem cache and there won't be any
more memory available. (except mayby distributed differently between cache
an free memory). And if it isn't cached you'll give your disk a lot of
unnessesary work.
Something like (pseudocode):
while (@array) {
find-next-time
calculate-sleep-until-next-time
sleep($wait-time)
do_something
remove-element-from-array
}
might save you some CPU.
------------------------------
Date: Wed, 14 May 2003 19:11:06 +1000
From: "Tony" <anthony@no_spam.movielink.net.au>
Subject: Re: High CPU usage and mem leak problem in a perl routine
Message-Id: <pan.2003.05.14.09.11.06.18677@no_spam.movielink.net.au>
On Tue, 13 May 2003 08:51:21 +0000, Anno Siegel wrote:
> Tony <anthony@no_spam.movielink.net.au> wrote in comp.lang.perl.misc:
>> Hi Guys,
>>
>> I have a specific memory usage problem with high CPU
>> usage to.
>>
>> The following construct:
>>
>> my $file = "/some/path/file";
>>
>> START: open (FILE, $file) or die "Could not open: $file $!\n";
>> while (my $lines = <FILE>) {
>> chomp ($lines);
>> ...processing the data...
>> {...more processing...
>> fork_sub($some_data);
>> }
>> }
>> goto START;
>>
>> sub fork_sub
>> {
>> ...processing data...
>> ...forking...
>> }
>>
>> All works perfectly except for a CPU usage of 98%
> Why shouldn't it pick up as much CPU a it can? It's an infinite loop
> with nothing to slow it down. It also forks an unlimited number of
It does not, the forks are controlled, there is only one fork every
2-3 hours depending on the data in the file being read in the loop.
>> and the memory usage climbing to 100% within an hour or so.
>
> Why the memory usage of the parent process should increase is anybody's
> guess. All we know is that your program is "processing the data".
I have tried to insert a sleep (1) everytime the file has been read
once then it goes back to the start again. That does stop the
> Unless the child processes finish faster than they are created, the
> memory consumption of the whole family of processes will grow
As above, there is only 1 child process started every now and again...
>> I think the problem lies with opening the file handle in the
>> loop as shown. Every time the file has been scanned, the program
> Hardly. Just opening a filehandle over and over again doesn't
>> Is it not better to read the file in to a @list or @array and
>> then read it from there?
> How would that help? You'll have to open the file in any case.
It would be resident in memory and should only take up a finite amount
according to its size.
>> The program needs to continuesly scan the input file.
> So apparently other processes have write access to the file while
> your program is running. You'll need file locking to make that
No additions are made to the file.
I have inserted a sleep (1) before going to the START: again.
This seems to have fixed it.
Tony
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net
------------------------------
Date: 14 May 2003 09:25:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: High CPU usage and mem leak problem in a perl routine
Message-Id: <b9t22t$plh$2@mamenchi.zrz.TU-Berlin.DE>
Tony <anthony@no_spam.movielink.net.au> wrote in comp.lang.perl.misc:
[possible memory leak]
> I have inserted a sleep (1) before going to the START: again.
>
> This seems to have fixed it.
Adding "sleep()" to the loop is certainly a good move. However,
if it leaked before, it probably still does, just slower.
Anno
------------------------------
Date: 14 May 2003 00:55:58 -0700
From: fafanie99@yahoo.fr (fafanie)
Subject: How to recover %CPU, Memory usage and size of a process (Win+Unix)
Message-Id: <31b33246.0305132355.1741905a@posting.google.com>
Hi,
I want to recover %CPU, memory usage and size of a process I have run
(every 5 seconds).
Under Windows: I use package Win32.
I run a process with the following command:
Win32::Process::Create($ProcessObj, $cmdExe, $cmd, 0,
NORMAL_PRIORITY_CLASS, "$exePath");
I have the PID with the command $ProcessObj->GetProcessID();
Under SunOS/RedHat, I run my process with the command system in using
a alarm to stop the process if timeout.
But, I don't say how to recover the consumption of this process every
5 seconds in all plateforms.
Thanks
fafanie
------------------------------
Date: Wed, 14 May 2003 09:27:57 +0530
From: "spanda" <spanda@cisco.com>
Subject: Re: how to set INC globally
Message-Id: <1052884695.608210@sj-nntpcache-3>
Thanks Steve and Anno.
This helps me a lot.
Regards
Subrat
"Steve Grazzini" <grazz@pobox.com> wrote in message
news:wa8wa.9231$kH.2174945@twister.nyc.rr.com...
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > spanda <spanda@cisco.com> wrote in comp.lang.perl.misc:
> >>
> >> How can we set path in @INC, so that it will be available globally.
> >>
> >> I use
> >> BEGIN {
> >> push ($INC, $PATH);
> >> }
> >
> > Better written as
> >
> > use lib $PATH;
> >
> > That works without BEGIN because "use" already happens at compile time.
> >
> >> But this is only at perl script level.
> >
> > perldoc perlrun, look for the environment variable PERL5LIB.
>
> The various options are also listed in the FAQ
>
> $ perldoc -q 'include path'
>
> And to add directories to @INC 'permanently', OP would need to rebuild
> perl with:
>
> $ sh Configure -Dotherlibdirs=$PATH -de
>
> --
> Steve
------------------------------
Date: Wed, 14 May 2003 04:50:46 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: How to Store and Print this Array?
Message-Id: <Xns937B3B8726865sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
dave_h4@yahoo.com (Hunter) wrote in
news:27ad91d2.0305130626.4325f4be@posting.google.com:
> HOW can I store this query into a hash so I can print it to the
> browser using cgi ?
In general, you wouldn't. You'd loop over the returned rows,
printing one row at a time.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+whGIY96i4h5M0egRAhO1AKDAgGASSeAHnIgeA1xZzkkNGaiUigCffhxX
OKEpDlK9cUEkvy85BRCB1Ek=
=TR71
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 14 May 2003 02:26:42 -0500
From: Dodger <dodger@dodger.org>
Subject: Inserting a child node at an arbitrary point in a tree
Message-Id: <Xns937B4E9D70CFdodgerdodgerorg@216.166.71.239>
If I had a structure like so:
$heir = {
ITEMA => {
ITEMB => {
ITEMC => {
ITEMD => {
ITEME => {}
}
}
}
};
And I wanted to do the following:
Add 'ITEMF' => {} as a child of 'ITEMB'
Add 'ITEMG' => {} as a child of 'ITEMD'
Add 'ITEMH' => {} as a child of 'ITEMF'
I could obviously do this:
$heir->{ITEMA}->{ITEMB}->{ITEMF} = {};
$heir->{ITEMA}->{ITEMB}->{ITEMC}->{ITEMD}->{ITEMG} = {};
$heir->{ITEMH}->{ITEMB}->{ITEMF}->{ITEMH} = {};
Or more intelligently, knowing I needed to do this, I could do this:
$heir->{ITEMA}->{ITEMB}->{ITEMF}->{ITEMH} = {};
$heir->{ITEMA}->{ITEMB}->{ITEMC}->{ITEMD}->{ITEMG} = {};
Which would create ITEMF in there on the fly.
But what if I wanted to add an arbitrary item to an arbitrary place in
the tree that I didn't know ahead of time, making hardcoding it
impossible? For instance, what if I had an item named $item, which would
always be a hashref, and I also had a rule that no two branches of the
tree would have the same name (ie, there would never be two keys called
'ITEMB' on the structure).
I want to be able to insert an item into the tree based on a key name
without knowing beforehand what the parent of this item is and without
even knowing how deep the structure goes.
Of course this wuold be done through a subroutine (or, in this case, a
method). I just cannot think of how to do it. It should be able to take a
key name and a parent key name as arguments, and either a) add a hashref
of '$keyname' => {} to the tree under the existing $parentkey key, or, if
the $keyname is already a key in the tree, regardless of whether it has
children, move it to be a child of the parent key. If the parent key is
not in the tree already, it should become a new key at the root of the
tree, and if the parent key is undefined the child key should become a
new root key.
There has to be an intelligent way to do this. I'm just not thinking of
it for some reason.
Anyone willing to lend a hand?
(Note, I don't write 'TIA' on things because I'd prefer to thank the person
who helps me thoroughly and profusely afterwards. Seems more sincere to me
than writing 'TIA" on a message.)
--
Dodger
------------------------------
Date: Wed, 14 May 2003 03:30:22 -0500
From: Dodger <dodger@dodger.org>
Subject: Re: Inserting a child node at an arbitrary point in a tree
Message-Id: <Xns937BFB766792dodgerdodgerorg@216.166.71.239>
I think I might have an answer here...
I think this looks like it will work in concept. I'm going to test it in a
few minutes.
my $unstructured = {ROOT => {}};
my $structured = $unstructured->{ROOT};
sub addChild {
my $child = shift || 'ROOT';
my $parent = shift;
if (exists $unstructured->{$child} && exists $unstructured->{$parent}){
return 1 if exists $unstructured->{$parent}->{$child};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
elsif (exists $unstructured->{$parent}) {
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstructured->{$parent}->{$child};
}
elsif (exists $unstructured->{$child}) {
$unstructued->{ROOT}->{$parent} = {};
$unstructued->{$parent} = $unstructured->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
else {
$unstructured->{ROOT}->{$parent} = {};
$unstructured->{$parent} = $unstrucuted->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstrucured->{$parent}->{$child};
}
return 1;
}
------------------------------
Date: Wed, 14 May 2003 03:36:29 -0500
From: Dodger <dodger@dodger.org>
Subject: Re: Inserting a child node at an arbitrary point in a tree
Message-Id: <Xns937B10C08AF20dodgerdodgerorg@216.166.71.239>
OOps, I meant:
my $unstructured = {ROOT => {}};
my $structured = $unstructured->{ROOT};
sub addChild {
my $child = shift or return undef;
my $parent = shift || 'ROOT';
if (exists $unstructured->{$child} && exists $unstructured->{$parent})
{
return 1 if exists $unstructured->{$parent}->{$child};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
elsif (exists $unstructured->{$parent}) {
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstructured->{$parent}->{$child};
}
elsif (exists $unstructured->{$child}) {
$unstructued->{ROOT}->{$parent} = {};
$unstructued->{$parent} = $unstructured->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
else {
$unstructured->{ROOT}->{$parent} = {};
$unstructured->{$parent} = $unstrucuted->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstrucured->{$parent}->{$child};
}
}
------------------------------
Date: Wed, 14 May 2003 03:48:18 -0500
From: Dodger <dodger@dodger.org>
Subject: Re: Inserting a child node at an arbitrary point in a tree
Message-Id: <Xns937B12BF92484dodgerdodgerorg@216.166.71.239>
On 14 May 2003, Dodger <dodger@dodger.org> in
news:Xns937B10C08AF20dodgerdodgerorg@216.166.71.239 said something that
resembled:
> OOps, I meant:
And of course, I hadn't weeded out the typoes. But this works. B^) Yeehee!
Wahaaa!
(Am I the only one who reacts like this when I figure out something like
this?)
Hehehe.
Here's the actual code, HTML output done with my LIster module but you can
just look in the debugger and leave out the Lister references (it's justa
habit to dump through Lister for me, and it works well):
#!/usr/bin/perl
use strict;
my $unstructured = {ROOT => {}};
my $structured = $unstructured->{ROOT};
sub addChild {
my $child = shift or return undef;
my $parent = shift || 'ROOT';
if (exists $unstructured->{$child} && exists $unstructured->{$parent})
{
return 1 if exists $unstructured->{$parent}->{$child};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
elsif (exists $unstructured->{$parent}) {
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstructured->{$parent}->{$child};
}
elsif (exists $unstructured->{$child}) {
$unstructured->{ROOT}->{$parent} = {};
$unstructured->{$parent} = $unstructured->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = $unstructured->{$child};
for my $corenode (grep $_ ne $parent, keys %{$unstructured}) {
delete $corenode->{$child};
}
}
else {
$unstructured->{ROOT}->{$parent} = {};
$unstructured->{$parent} = $unstructured->{ROOT}->{$parent};
$unstructured->{$parent}->{$child} = {};
$unstructured->{$child} = $unstructured->{$parent}->{$child};
}
}
addChild('Trunk1');
addChild('Trunk2');
addChild('T1Branch1', 'Trunk1');
addChild('T1Branch2', 'Trunk1');
addChild('T2Branch1', 'Trunk2');
addChild('T2B1Subbranch1', 'T1Branch1');
addChild('Sapling1','GroundNearby');
use HTML::Lister;
my $lister = new HTML::Lister;
print $lister->List($structured);
------------------------------
Date: Wed, 14 May 2003 08:32:40 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: MYSQL images
Message-Id: <3EC1F118.8060401@bbsrc.ac.uk>
Music Man wrote:
> Hi !
>
> I am aware this is not the right group for my question, but there is no
> mysql related group, so since I need this from a Perl language I am
> asking here.
>
> Does anyone have an experience with Mysql & Perl regarding Web images. I
> need to make a script, which will pull pics (I know mysql has such field
> type) from a database, and put it out on a web page using CGI library.
Nothing special about image data as far as Perl is concerned. It's just
another kind of binary data. Make sure that you output an appropriate
content-type header before your image data, and that you binmode your
STDOUT when printing the image itself.
Other than that just do things the same as you would when outputting any
other data from a database into a CGI script.
One other thought. Do you really need to store the images in the
database itself. This gives you the overhead of retrieving them and
outputting them with a CGI script each time. When I've needed to do
this before I usually store the images on disk, and store their location
in the database. That way I can add the real image location into the
first dynamically generated web page and save myself the extra overhead
of a separate CGI call for each image.
Hope this helps
Simon.
------------------------------
Date: Wed, 14 May 2003 09:47:51 +0200
From: Music Man <musicman@hotmail.com>
Subject: Re: MYSQL images
Message-Id: <MPG.192c131647db2eaa989709@news.siol.net>
In article <3EC1F118.8060401@bbsrc.ac.uk>, simon.andrews@bbsrc.ac.uk
says...
>
>
> Music Man wrote:
> > Hi !
> >
> > I am aware this is not the right group for my question, but there is no
> > mysql related group, so since I need this from a Perl language I am
> > asking here.
> >
> > Does anyone have an experience with Mysql & Perl regarding Web images. I
> > need to make a script, which will pull pics (I know mysql has such field
> > type) from a database, and put it out on a web page using CGI library.
>
> Nothing special about image data as far as Perl is concerned. It's just
> another kind of binary data. Make sure that you output an appropriate
> content-type header before your image data, and that you binmode your
> STDOUT when printing the image itself.
>
> Other than that just do things the same as you would when outputting any
> other data from a database into a CGI script.
>
> One other thought. Do you really need to store the images in the
> database itself. This gives you the overhead of retrieving them and
> outputting them with a CGI script each time. When I've needed to do
> this before I usually store the images on disk, and store their location
> in the database. That way I can add the real image location into the
> first dynamically generated web page and save myself the extra overhead
> of a separate CGI call for each image.
Yes, because of the security reasons. You have control over which image
can be shown. If you have only locations of the images stored in a
database, than anyone who can guess filename, can actually see it.
>
> Hope this helps
>
> Simon.
>
>
------------------------------
Date: Wed, 14 May 2003 10:01:33 +0100
From: "Allanon" <allanon@hotmail.com>
Subject: Re: Negating phrases
Message-Id: <b9t0le$15lu@newton.cc.rl.ac.uk>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9el32lr6i.fsf@wcl-l.bham.ac.uk...
> "Allanon" <allanon@hotmail.com> writes:
>
> > Could you tell me what I'm doing wrong?
>
> Starting a new thead with question substancially the same as was
> discussed in the thread "dont match this pattern" less than a week
> ago.
Damn, you're right.. I didn't spot that one.. I guess, it's off to the firey
pits of hell for me then! ;)
Allanon
------------------------------
Date: Wed, 14 May 2003 02:37:08 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: No data entering @array from open(DATA...)
Message-Id: <oZhwa.837397$F1.105601@sccrnsc04>
This has me stumped. I must be missing something very basic, but I cannot
get @currplids to populate with the data from $playeriddb. Anyone see the
mistake?
Code:
----
my (@currplids, $playerid, $currplids, $playerupdate);
#Grab current player id database
open(CPDATA, ">>$playeriddb") or "cannot open $playeriddb: $! \n";
while (<CPDATA>) {
@currplids = (@currplids,$_);
}
#Set variable for next new player id
$playerid = @currplids;
print "first $playerid\n@currplids\n";
----
I will keep troubleshooting, and thanks for any help,
Sammie
------------------------------
Date: Wed, 14 May 2003 03:06:51 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <fpiwa.592385$Zo.130226@sccrnsc03>
> This has me stumped.
Nevermind, saw mistake...
Brad (aka Sammie)
------------------------------
Date: Wed, 14 May 2003 03:46:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <p_iwa.25921$TM6.25115@nwrddc02.gnilink.net>
Brad Walton wrote:
>> This has me stumped.
>
> Nevermind, saw mistake...
Mind to share such that others can learn, too?
jue
------------------------------
Date: Wed, 14 May 2003 03:56:36 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <U7jwa.836252$L1.243519@sccrnsc02>
> Mind to share such that others can learn, too?
Sure.
Original Code:
----
my (@currplids, $playerid, $currplids, $playerupdate);
#Grab current player id database
open(CPDATA, ">>$playeriddb") or "cannot open $playeriddb: $! \n";
while (<CPDATA>) {
@currplids = (@currplids,$_);
}
#Set variable for next new player id
$playerid = @currplids;
print "first $playerid\n@currplids\n";
----
Resolution:
I was opening the database in append mode. I removed the append '>>' and
opened it properly, in read mode. Was a simple oversight because I have been
working too hard, and my brain is beginning to smoke.
I did not post the solution because it was so obvious, but in retrospect I
should have done so anyway.
Brad
------------------------------
Date: Wed, 14 May 2003 08:58:25 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <b9st2d$eat$1$8300dec7@news.demon.co.uk>
Brad Walton wrote:
> This has me stumped. I must be missing something very basic, but I cannot
> get @currplids to populate with the data from $playeriddb. Anyone see the
> mistake?
>
> Code:
> ----
> my (@currplids, $playerid, $currplids, $playerupdate);
> #Grab current player id database
> open(CPDATA, ">>$playeriddb") or "cannot open $playeriddb: $! \n";
> while (<CPDATA>) {
> @currplids = (@currplids,$_);
> }
>
> #Set variable for next new player id
> $playerid = @currplids;
> print "first $playerid\n@currplids\n";
>
> ----
>
> I will keep troubleshooting, and thanks for any help,
> Sammie
open(CPDATA, "$playeriddb") or "cannot open $playeriddb: $! \n";
@currplids = <CPDATA>;
close CPDATA;
Get rid of append mode (>>). Must be the easiest way of stuffing a file into
an array.
HTH,
Garry
------------------------------
Date: 14 May 2003 09:01:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <b9t0lg$plh$1@mamenchi.zrz.TU-Berlin.DE>
Brad Walton <sammie@greatergreen.com> wrote in comp.lang.perl.misc:
> > Mind to share such that others can learn, too?
>
> Sure.
>
> Original Code:
> ----
> my (@currplids, $playerid, $currplids, $playerupdate);
> #Grab current player id database
> open(CPDATA, ">>$playeriddb") or "cannot open $playeriddb: $! \n";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is still nonsense. You want to print the string, or die with
the string as a message. Just mentioning it won't do any good. If
you had warnings switched on, Perl would have pointed that out.
[...]
Anno
------------------------------
Date: Tue, 13 May 2003 23:09:52 -0400
From: Jason Parker-Burlingham <jasonp@uq.net.au>
Subject: Re: Question about News::NNTPClient Method (a bit long)
Message-Id: <87fzniusu7.fsf@freezer.burling>
"Anthony Saffer" <anthony@nospam.safferconsulting.com> writes:
> while loop and search through every article. The declaration of the while
> loop is as such:
>
> while($current_article <= $last_article){}
>
> Between my brackets I search and parse each articles header. When I reach
> the end of the header I execute the ->next method as such:
>
> $current_article = $conn->next();
>
> It all works fine. The problem is when there IS no "next" article (for
> example groups with no articles).
I would suggest using a loop like
while (my $article = $conn->next()) {
# process $article
}
> Is there a 'break' command in Perl? If
> so I can't find any doc on it. Can anyone offer help?
You can use the `last' keyword. You may have to name your outer loop
if you have an inner one. See `Simple statements' in perlsyn.
--
``Oooh! A gingerbread house! Hansel and Gretel are set for life!''
------------------------------
Date: Wed, 14 May 2003 01:50:47 GMT
From: "Travis" <dingdongy2k@hotmail.com>
Subject: Why do I get double line feeds
Message-Id: <Xhhwa.69370$ey1.6283632@newsread1.prod.itd.earthlink.net>
print MEMCHK "$used_timein[$j]\n";
I am writing to file and simply want to get each line with a single line
feed.
For some reason I get the single line feed when I leave off the \n and I get
a double line feed when
I leave it in?
Any ideas?
------------------------------
Date: Wed, 14 May 2003 02:18:08 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Why do I get double line feeds
Message-Id: <3EC1A747.6@rochester.rr.com>
Travis wrote:
> print MEMCHK "$used_timein[$j]\n";
>
> I am writing to file and simply want to get each line with a single line
> feed.
>
> For some reason I get the single line feed when I leave off the \n and I get
> a double line feed when
> I leave it in?
>
> Any ideas?
Sure. Leave off the \n :-).
You undoubtedly have a newline at the end of array element
$used_timein[$j]. Perhaps you read it from a file and neglected to
chomp it?
--
Bob Walton
------------------------------
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 4981
***************************************