[22889] in Perl-Users-Digest
Perl-Users Digest, Issue: 5110 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 12 11:05:43 2003
Date: Thu, 12 Jun 2003 08:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Jun 2003 Volume: 10 Number: 5110
Today's topics:
"make test" error <zzdave13@no_spam.yahoo.com>
`du -bs $dir` question (Math55)
Re: `du -bs $dir` question <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Any Security Concerns With This Script? (BrianEWilliams)
Re: Enqueue a hash? <nobull@mail.com>
Re: Enqueue a hash? <usenet@cluestore.net>
Re: How to do a 'wrapper' on Windows? (Carlton Brown)
Re: How to do a 'wrapper' on Windows? <tzz@lifelogs.com>
Installing Perl 5.8 (Philip Juels)
Re: Perl Matrix Filter Module like in Excel? <tzz@lifelogs.com>
Re: Producing a graph <bigj@kamelfreund.de>
Re: Producing a graph <musicman@hotmail.com>
Sanitizing a regular expression <bernie@rev.net>
Sorting Algorithm: organize data into a tree <jeffrey@jhu.edu>
Re: SQL Problem - Select returns nothing (Damian James)
Re: SQL Problem - Select returns nothing <nobull@mail.com>
Re: unbelievable doco bug?? in 5.8.0 (Bhaskar Kurapati)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Jun 2003 11:52:06 +0100
From: "Dave" <zzdave13@no_spam.yahoo.com>
Subject: "make test" error
Message-Id: <3ee860b1$1@usenet01.boi.hp.com>
Hi,
having trouble installing perl, i get an error on "make test", see below.
Any help/advice much appreciated.
Dave.
____________________________
Error message from make test
____________________________
Failed 1 test script out of 661, 99.85% okay.
### Since not all tests were successful, you may want to run some of
### them individually and examine any diagnostic messages they produce.
### See the INSTALL document's section on "make test".
### You have a good chance to get more information by running
### ./perl harness
### in the 't' directory since most (>=80%) of the tests succeeded.
### You may have to set your dynamic library search path,
### LD_LIBRARY_PATH, to point to the build directory:
### setenv LD_LIBRARY_PATH `pwd`; cd t; ./perl harness
### LD_LIBRARY_PATH=`pwd`; export LD_LIBRARY_PATH; cd t; ./perl harness
### export LD_LIBRARY_PATH=`pwd`; cd t; ./perl harness
### for csh-style shells, like tcsh; or for traditional/modern
### Bourne-style shells, like bash, ksh, and zsh, respectively.
u=11.48 s=2.81 cu=721.11 cs=62.02 scripts=661 tests=68022
*** Error exit code 1
Stop.
*** Error exit code 1
Stop.
*** Error exit code 1
Stop.
_________________________________
Error message from ./perl harness
_________________________________
Failed Test Stat Wstat Total Fail Failed List of Failed
----------------------------------------------------------------------------
-----
op/pack.t 5819 8 0.14% 181 291 401 511 621 731 841 5457
48 tests and 418 subtests skipped.
Failed 1/712 test scripts, 99.86% okay. 8/68032 subtests failed, 99.99%
okay.
_________________________________
Individual test error messages
_________________________________
not ok 181
# For list (-128, -1, 0, 1, 127) (total -1) packed with c unpack '%53c' gave
0, expected 9.00719925474099e+15
not ok 291
# For list (-32768, -1, 0, 1, 32767) (total -1) packed with s unpack '%53s'
gave 0, expected 9.00719925474099e+15
not ok 401
# For list (-2147483648, -1, 0, 1, 2147483647) (total -1) packed with i
unpack '%53i' gave 0, expected 9.00719925474099e+15
not ok 511
# For list (-2147483648, -1, 0, 1, 2147483647) (total -1) packed with l
unpack '%53l' gave 0, expected 9.00719925474099e+15
not ok 621
# For list (-32768, -1, 0, 1, 32767) (total -1) packed with s! unpack
'%53s!' gave 0, expected 9.00719925474099e+15
not ok 731
# For list (-2147483648, -1, 0, 1, 2147483647) (total -1) packed with i!
unpack '%53i!' gave 0, expected 9.00719925474099e+15
not ok 841
# For list (-2147483648, -1, 0, 1, 2147483647) (total -1) packed with l!
unpack '%53l!' gave 0, expected 9.00719925474099e+15
not ok 5457
# For list (-2147483648, -1, 0, 1, 2147483647) (total -1) packed with j
unpack '%53j' gave 0, expected 9.00719925474099e+15
_______________________________
Output of myconfig shell script
_______________________________
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=hpux, osvers=10.20, archname=PA-RISC2.0
uname='hp-ux pompey b.10.20 a 9000782 2001260112 two-user license '
config_args='-Dcc=gcc -A prepend:libswanted=cl pthread '
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags
='-D_HPUX_SOURCE -DUINT32_MAX_BROKEN -DDEBUGGING -fno-strict-aliasing -D_LAR
GEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-g -O',
cppflags='-D__STDC_EXT__ -D_HPUX_SOURCE -D_HPUX_SOURCE -DUINT32_MAX_BROKEN -
DDEBUGGING -fno-strict-aliasing'
ccversion='', gccversion='2.95.2 19991024 (release)',
gccosandvers='hpux10.20'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='/usr/bin/ld', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
libs=-lcl -lnsl_s -lndbm -lmalloc -ldld -lm -lc -lndir -lcrypt -lsec
perllibs=-lcl -lnsl_s -lmalloc -ldld -lm -lc -lndir -lcrypt -lsec
libc=/lib/libc.sl, so=sl, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef,
ccdlflags='-Wl,-E -Wl,-B,deferred '
cccdlflags='-fPIC', lddlflags='-b -L/usr/local/lib'
------------------------------
Date: 12 Jun 2003 06:24:09 -0700
From: magelord@t-online.de (Math55)
Subject: `du -bs $dir` question
Message-Id: <a2b8188a.0306120524.78d7153c@posting.google.com>
hello, i wrote the following subroutine.
sub getFolderSize{
my $FolderPath = shift;
my $du_parse = `du -bs $_`;
$du_parse =~ /^(\d+)/;
$dirSizeTest = $1;
return $dirSizeTest;
}
i try to use it to geth the size of a directory with all its subdirs.
the method is called with a path like /home/test. it always gives me
12980 bytes, for EVERY directory!! whats wrong? is there any faster
way to do this? i think -s or stat are slower?
thank you :)
------------------------------
Date: Thu, 12 Jun 2003 13:27:48 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: `du -bs $dir` question
Message-Id: <Xns93989CEE07C94elhber1lidotechnet@62.89.127.66>
Math55 wrote:
> hello, i wrote the following subroutine.
>
> sub getFolderSize{
>
> my $FolderPath = shift;
>
> my $du_parse = `du -bs $_`;
^^
> $du_parse =~ /^(\d+)/;
> $dirSizeTest = $1;
> return $dirSizeTest;
>
> }
>
> i try to use it to geth the size of a directory with all its subdirs.
> the method is called with a path like /home/test. it always gives me
> 12980 bytes, for EVERY directory!! whats wrong?
Your folder path is in $FolderPath but you're du()ing what's in $_.
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 12 Jun 2003 06:10:03 -0700
From: sorry_no_email@yahoo.com (BrianEWilliams)
Subject: Re: Any Security Concerns With This Script?
Message-Id: <92383dd3.0306120510.23f3c31f@posting.google.com>
Any thoughts on this?
sorry_no_email@yahoo.com (BrianEWilliams) wrote in message news:<92383dd3.0306111222.289076fc@posting.google.com>...
> I have the following script which is used to upload files via a
> browser to a remote web host that runs Linux/Apache:
>
> #-------------Start---------------------------
> #!/usr/bin/perl -w
> use CGI::Carp qw(fatalsToBrowser);
> use CGI qw(:standard);
> use MIME::Lite qw(fatalsToBrowser);
> use CGI::Upload;
> use File::MMagic;
>
> $mailprog = '/usr/sbin/sendmail';
> $TimeStamp = time;
>
> my $upload = CGI::Upload->new;
> my $file_name = $upload->file_name('file1');
> my $file_type = $upload->file_type('file1');
> $upload->mime_magic('/path/to/mime/mimefile.txt');
> my $mime_type = $upload->mime_type('file1');
> my $file_handle = $upload->file_handle('file1');
>
> $target = "file$TimeStamp.jpg";
> open (STORAGE, ">>/path/to/uploaded_files/$target") or die "Error:
> File $file_name Upload: $!\n";
> while(read($file_handle, $data, 1024)){
> print STORAGE $data or die "Can't write to the file because of
> $!\n";
> }
> close STORAGE;
> exit;
> #-------------End---------------------------
>
> My main question is whether this script has security holes that need
> plugging. I would like to hear other comments because I have a lot to
> learn. I know I probably have more "use" lines up at the top than I
> need.
>
> One thing I am a little cloudy on is this line:
>
> $upload->mime_magic('/path/to/mime/mimefile.txt');
>
> Is this so I can add my own mime types? If so, what format should I
> use for the file?
>
> BTW, here is a reference for CGI::Upload
>
> http://search.cpan.org/author/ROBAU/CGI-Upload-1.05/lib/CGI/Upload.pm
------------------------------
Date: 12 Jun 2003 13:26:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Enqueue a hash?
Message-Id: <u9llw7wkfg.fsf@wcl-l.bham.ac.uk>
Cliff Daniel <usenet@cluestore.net> writes:
> Trivial i'm sure but I can't figure it out.
>
> my $MyQueue = Thread::Queue->new;
>
> my %Targets = (
> 'target1' => {'name' => 'blah1', 'type' => 'asdf'},
> 'target2' => {'name' => 'blah2', 'type' => 'asdf'},
> 'target3' => {'name' => 'blah3', 'type' => 'asdf'},
>
> 'targetn' => {'name' => 'blahn', 'type' => 'asdf'},
> );
>
> [pseudo]
> foreach ...
> $MyQueue->enqueue %hash_element
>
> Now what I need to be able to do is foreach over the Targets
> and enqueue that elements hash
OK
$MyQueue->enqueue($_) for values %Targets;
But why? According to the documentation of Thread::Queue you can
enqueue several at once.
$MyQueue->enqueue(values %Targets);
> (target1, then 2, etc...)
Oh, hang on. You want to enqueue in some specific order? OK in that
case you need to create a sorting function to define that order.
Are you sure you wanted to be using a hash?
$MyQueue->enqueue(@Targets{ sort { whatever } key %Targets});
> $Item = $MyQueue->dequeue();
> Item now needs to be able to 'see', 'read/write' to the 'name', 'type'
> attributes of that hash element.
Ignoring threading there should be no problem $Item->{name} and
$Item->{type}.
I've never used threads but I can't see any reason why they should
introduce a problem here.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 12 Jun 2003 14:16:53 +0000 (UTC)
From: Cliff Daniel <usenet@cluestore.net>
Subject: Re: Enqueue a hash?
Message-Id: <slrnbeh2qn.33k.cdaniel@ohno.cluestore.net>
In article <u9llw7wkfg.fsf@wcl-l.bham.ac.uk>, Brian McCauley wrote:
> Cliff Daniel <usenet@cluestore.net> writes:
>
>> Trivial i'm sure but I can't figure it out.
>>
>> my $MyQueue = Thread::Queue->new;
>>
>> my %Targets = (
>> 'target1' => {'name' => 'blah1', 'type' => 'asdf'},
>> 'target2' => {'name' => 'blah2', 'type' => 'asdf'},
>> 'target3' => {'name' => 'blah3', 'type' => 'asdf'},
>>
>> 'targetn' => {'name' => 'blahn', 'type' => 'asdf'},
>> );
>>
>> [pseudo]
>> foreach ...
>> $MyQueue->enqueue %hash_element
>>
>> Now what I need to be able to do is foreach over the Targets
>> and enqueue that elements hash
>
> OK
>
> $MyQueue->enqueue($_) for values %Targets;
This is not allowed when using threading to where more than one thread
has access or else you get the painful "Invalid value for shared scalar".
So adding this let's you push these onto the queue.
my %Targets = (
't1' => {'name' => 'blah1', 'type' => 'asdf'},
't2' => {'name' => 'blah2', 'type' => 'asdf'},
't3' => {'name' => 'blah3', 'type' => 'asdf'},
);
$MyQueue->enqueue(share($_)) for values %Targets;
>> $Item = $MyQueue->dequeue();
>> Item now needs to be able to 'see', 'read/write' to the 'name', 'type'
>> attributes of that hash element.
>
> Ignoring threading there should be no problem $Item->{name} and
> $Item->{type}.
$Item = $MyQueue->dequeue;
printf("%s [tid: %d]: Popped '%s' (ref=%s) off the queue",
$Item->{name}, ref($Item)));
Always empty references. Any ideas?
Thu Jun 12 09:13:38 2003 [tid:0]: Spawned tid #1
Thu Jun 12 09:13:39 2003 [tid:0]: Spawned tid #2
Thu Jun 12 09:13:39 2003 [tid:0]: Spawned tid #3
Thu Jun 12 09:13:39 2003 [tid:0]: 3 items queued.
Thu Jun 12 09:13:39 2003 [tid:1]: Popped '' (ref=HASH) off the queue
Thu Jun 12 09:13:40 2003 [tid:2]: Popped '' (ref=HASH) off the queue
Thu Jun 12 09:13:40 2003 [tid:3]: Popped '' (ref=HASH) off the queue
Regards,
Cliff
------------------------------
Date: 12 Jun 2003 04:53:04 -0700
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: How to do a 'wrapper' on Windows?
Message-Id: <aa611a32.0306120353.7dd67ce7@posting.google.com>
"foomf" <foomf@attbi.com> wrote in message news:<7RKFa.909447$OV.843548@rwcrnsc54>...
> I've got a problem that is trivial on UNIX of any flavor, but which is
> giving me cramps on Windows.
>
> I have a database access program that consumes licenses. It connects to a
> server via a program that runs in a DOS command window.
[snippage regarding sales people being idiots]
> I've been instructed to put a wrapper around the process that watches
> keyboard input and if it is left untouched for too long, sends the sequence
> to shut down the database connection.
First, I must say that the "real" solution here would be on the
database side because there's no client-side timeout solution that can
account for the typical sales-department shutdown technique of yanking
the power strip. For this reason, most databases or license software
have environment variables or at least commands to unregister stale
connections. I suggest checking your DB or license daemon docs before
going forward with the client side.
Having given due warning - If you are unlucky enough not to have a
server-side solution, what about using open2() to open read and write
pipes to your program, use the READ handle to capture the input, and
the WRITE handle to capture output? Use alarm() to set a client-side
timeout. Create signal handler that sends appropriate shutdown
command when certain signals are received.
UNTESTED EXAMPLE code follows, with certain assumptions on environment
and lorem ipsum text. On your own, you'll have to identify the
appropriate signals and IO buffering specific to Windows and your
Piece Of Software:
$SIG{'ALRM'} = \&exitPosDbClient;
$SIG{'INT'} = \&exitPosDbClient;
$SIG{'HUP'} = \&exitPosDbClient;
open2(*DBRETURN, *DBSEND, "C:\POSdB\dbclient.exe
/neverReleaseLicenses") or die "Can't open this POS";
while (<STDIN>) {
$line = $_;
alarm(300);
print DBSEND "$line";
print map { "$_\n" } (<DBRETURN>);
}
exitPosDbClient;
sub exitPosDbClient() {
print "Thanks for using our POS. Enjoy your lunch\n"
print OUTPUT "logout\quit\n";
close OUTPUT;
close INPUT;
exit 0;
}
# Note - if you do decide to use alarm() then whatever you do, don't
use sleep
# anywhere else in the program, use a subroutine that makes use of
select() :
sub pause($) {
# Workaround for sleep() which would interfere with alarm()
# As a bonus, this handles fractional second sleeps
$timeout = shift;
select (undef, undef, undef, $timeout) or die "Can't perform
select - $!";
return 0;
}
------------------------------
Date: Thu, 12 Jun 2003 11:04:00 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to do a 'wrapper' on Windows?
Message-Id: <4nn0gnl4m7.fsf@lockgroove.bwh.harvard.edu>
I agree with Carlton's ideas, but he relies on a CR/LF being pressed.
The user could be typing, backspacing, hitting TAB, etc.
I would catch every key press with something like Term::InKey and
forward it to the client program; set an alarm() on every key stroke.
Term::InKey works on Windows.
Ted
------------------------------
Date: 12 Jun 2003 07:23:48 -0700
From: pjuels@rics.bwh.harvard.edu (Philip Juels)
Subject: Installing Perl 5.8
Message-Id: <4cdea80b.0306120623.576abbdf@posting.google.com>
Hi all,
I'd like to install Perl 5.8.0 on our Fire 880 Solaris box, but I have
a few concerns:
1) I understand its NOT a good idea to remove/replace the Perl
version bundled with Solaris...okay that's fine, I'll just install the
Sunfreeware package which puts it in /usr/local, but...
2) How do I install CPAN modules to the newer Perl rather than the
default old one?
Thanks,
Philip Juels
pjuels@rics.bwh.harvard.edu
------------------------------
Date: Thu, 12 Jun 2003 10:53:45 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl Matrix Filter Module like in Excel?
Message-Id: <4nr85zl53a.fsf@lockgroove.bwh.harvard.edu>
On Thu, 12 Jun 2003, Dennis@NoSpam.com wrote:
> The only downside I found is the rather limited development IDE's to
> compile and test your code.
If you are looking for a full-scale IDE you may like ActiveState's
offering.
I'm blissfully happy with Emacs and cperl-mode.
Ted
------------------------------
Date: Thu, 12 Jun 2003 10:09:09 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Producing a graph
Message-Id: <pan.2003.06.12.08.08.53.230411@kamelfreund.de>
slash wrote at Wed, 11 Jun 2003 20:10:54 -0700:
> I am new to Perl and a very bad programmer and am fiddling with a
> problem of mapping a certain output to a graph data structure. I think
> I can do this in Java but in Perl, I don't even know where to begin!
If you know it how to do in Java, you should be able to translate it to
Perl. It seems to be a problem that needs a) an algorithmic solution that
is of course same to both languages and b) perhaps some modules/classes
providing the necessary data structures.
> Following is the format of my output:
>
> Use
> Post
> A
> Your
> Message
> questions
> Your
>
> Message
> Remember
> that
> that
> is
> questions
>
> Viewed
> by
> millions
> of
>
> questions
> ask
> first
>
>
> The output I am seeking is the following:
>
> Use
> Post
> A
> Your
> Message
> Remember
> that
> is
> questions
> questions
> ask
> first
> Viewed
> by
> millions
> of
>
>
> As you can see, I am not repeating any tokens in a branch. Second, I
> am discarding a child that's on a branch that also happens to be a
> parent or a grand parent to avoid inifinite trees. I am building a
> very simple text-processing system where the majority of preprocessing
> has already been finished and I am at the stage where I get the above
> formatted data. What I need is the ability to somehow map this input
> format into a graph obeying the above constraints. As speed is a big
> issue for text processing of large collections, I need this to be as
> fast as possible but the data structure has to be a graph. My end
> result is a graph. Also can I draw this graph using some sort of a
> module or a program? Is that feasible?
You might have a look to the CPAN modules
Graph
Graph::Base
Graph::Writer
Graph::Writer::XML
Graph::Writer::VCG
...
CGI::Graph
...
Tree::Base
Tree::DAG_Node
...
Greetings,
Janek
------------------------------
Date: Thu, 12 Jun 2003 13:18:35 +0200
From: Music Man <musicman@hotmail.com>
Subject: Re: Producing a graph
Message-Id: <MPG.19527ff75c6d376a989711@news.siol.net>
In article <pan.2003.06.12.08.08.53.230411@kamelfreund.de>,
bigj@kamelfreund.de says...
> slash wrote at Wed, 11 Jun 2003 20:10:54 -0700:
>
> > I am new to Perl and a very bad programmer and am fiddling with a
> > problem of mapping a certain output to a graph data structure. I think
> > I can do this in Java but in Perl, I don't even know where to begin!
>
> If you know it how to do in Java, you should be able to translate it to
> Perl. It seems to be a problem that needs a) an algorithmic solution that
> is of course same to both languages and b) perhaps some modules/classes
> providing the necessary data structures.
>
> > Following is the format of my output:
> >
> > Use
> > Post
> > A
> > Your
> > Message
> > questions
> > Your
> >
> > Message
> > Remember
> > that
> > that
> > is
> > questions
> >
> > Viewed
> > by
> > millions
> > of
> >
> > questions
> > ask
> > first
> >
> >
> > The output I am seeking is the following:
> >
> > Use
> > Post
> > A
> > Your
> > Message
> > Remember
> > that
> > is
> > questions
> > questions
I use GNUPlot with Perl
------------------------------
Date: Thu, 12 Jun 2003 10:57:00 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: Sanitizing a regular expression
Message-Id: <r04hevohpmtmi1rj27aesmlh14psq6b6g7@4ax.com>
I need to 'sanitize' a user-supplied regular expression and I'm not
sure how to manage it. The more I peruse perlre (this on 5.6.1 but we
might be upgrading one of these days) the harder it seems like it'll
be to prevent a malicious RE from doing something dangerous. I can
see that I need to scan for and remove (?{...}) [assuming I can
correctly parse the RE to _locate_ that sort of construct!] And
probably ${expr} stuff, too.... Just figuring out all the
potentially dangerous constructs seems pretty hard; actually
parsing-and-cleaning the RE to remove them seems even harder. Any
advice? Thanks!
/Bernie\
------------------------------
Date: Thu, 12 Jun 2003 10:09:24 -0400
From: "Jeffrey Silverman" <jeffrey@jhu.edu>
Subject: Sorting Algorithm: organize data into a tree
Message-Id: <pan.2003.06.12.14.09.21.340715@jhu.edu>
<frustration>Argh!</frustration>
I am cross-posting to PHP and Perl newsgroups, as the algorithm I am
seeking should be fairly language-agnostic, and I know both Perl and PHP.
I need to organize a multi-dimensional array into a tree. The data
structure is roughly as follows:
array(
"A" => array("parent"=>"B", "self"=>"A", "data"=>"aaaaa") ,
"B" => array("parent"=>"default", "self"=>"B", "data"=>"bbbbb") ,
"C" => array("parent"=>"B", "self"=>"C", "data"=>"ccccc") ,
"D" => array("parent"=>"default", "self"=>"D", "data"=>"ddddd") ,
"E" => array("parent"=>"C", "self"=>"E", "data"=>"eeeee") ,
"F" => array("parent"=>"C", "self"=>"F", "data"=>"fffff") ,
"G" => array("parent"=>"D", "self"=>"G", "data"=>"ggggg") ,
)
Note that it is not already sorted in any way.
I need an algorithm to organize it into its tree shape, like so:
array(
"default" => array(
"B" => array(
"A" => array(
),
"C" => array(
"E" => array(),
"F" => array(),
),
),
"D" => array(
"G" => array(),
)
)
)
Then I figure, once organized, I can go through the organized array and
print out the "data" using the index from the organized array as the key for the
original array, for example (pseudocode):
foreach ($original_array)
print $original_array[key($organized_array)]['data'];
This has been extremely challenging to me to figure out. I hope it poses an
interesting challenge to some of you folk, and that someone can help me.
In the meantime, I am going to do some sysadmin crap.
later...
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/
------------------------------
Date: 12 Jun 2003 11:33:41 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: SQL Problem - Select returns nothing
Message-Id: <slrnbegp8k.mq7.damian@puma.qimr.edu.au>
On 11 Jun 2003 23:22:00 -0700, Dennis Macdonald said:
>Please help. I have the following code and it inserts into the
>database correctly but the select straight after it always returns no
>records. After the insert, if I look into the database then it has the
>record in it. I've tried everything but to no avail.
>
<snip>
> $rcount = $sth->execute();
>
> if (!$rcount) { # Undefined
<snip>
> } elsif ($rcount eq '0E0') {
> $rtrn_vl = 0;
> } else {
> $rtrn_vl = $rcount;
> }
> return $rtrn_vl;
I won't comment on the rest of your code, but it looks like
DBI's execute() method doesn't do what you expect it to do.
You should consult the documentation for DBI somewhat further,
but what you are probably looking for is the fetchrow() method
or one of its siblings:
while (my @record = $sth->fetchrow){
#do something with @record
}
--damian
------------------------------
Date: 12 Jun 2003 13:11:01 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: SQL Problem - Select returns nothing
Message-Id: <u9r85zwl62.fsf@wcl-l.bham.ac.uk>
newsgroups@bandwood.com (Dennis Macdonald) writes:
> I have the following code and it inserts into the database correctly
> but the select straight after it always returns no records.
How do you know? The code you posted makes no attempt to read any
records from the database SELECT statement handle.
See also the description of the execute() method in "perldoc DBI".
Note in particular the paragraph:
For "SELECT" statements, execute simply "starts" the
query within the database engine. Use one of the fetch
methods to retrieve the data after calling "execute".
The "execute" method does not return the number of
rows that will be returned by the query (because most
databases can't tell in advance), it simply returns a
true value.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 12 Jun 2003 02:44:40 -0700
From: bhas_kurapati@yahoo.com (Bhaskar Kurapati)
Subject: Re: unbelievable doco bug?? in 5.8.0
Message-Id: <3c0c6539.0306120144.5f68fdd9@posting.google.com>
> @a = qw( a b c );
>
> while ($x = shift @a) { # this is a loop
> print "1 $x\n";
> { # this is not a loop, it is a block
> next if $x eq 'b'; # if true, we should not reach print below
> }
> print "2 $x\n\n";
> }
> #######
> according to programming perl (3rd), page 746 (near top),
> "When LABEL is omitted, the operator refers to the innermost enclosing
> loop"
> this is the while loop, since a {} block isn't a loop just by itself.
"{}" block is itself a loop which will be executed once.
below code will print what you expected.
while ($x = shift @a) { # this is a loop
print "1 $x\n";
#{ # this is not a loop, it is a block
next if $x eq 'b'; # if true, we should not reach print below
#}
print "2 $x\n\n";
}
regards,
Bhaskar
------------------------------
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 5110
***************************************