[22759] in Perl-Users-Digest
Perl-Users Digest, Issue: 4980 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 13 21:05:48 2003
Date: Tue, 13 May 2003 18: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 Tue, 13 May 2003 Volume: 10 Number: 4980
Today's topics:
Re: -T and DBI <tmac@trransport.com>
Re: -T and DBI <usenet@dwall.fastmail.fm>
Re: -T and DBI <abigail@abigail.nl>
Re: @Array - making it null <abigail@abigail.nl>
Re: Convert array into hash element <REMOVEsdnCAPS@comcast.net>
Re: Convert array into hash element <skuo@mtwhitney.nsc.com>
disk usage script <spedwards@qwest.net>
Re: disk usage script <bwalton@rochester.rr.com>
Re: disk usage script <kevinsproule@hotmail.com>
Re: egrep exclude (James E Keenan)
Help: Perl Modules for Newbie non-administrator? (entropy123)
Re: Help: Perl Modules for Newbie non-administrator? <bwalton@rochester.rr.com>
Help: Working with a hash of hashes? (entropy123)
Re: Help: Working with a hash of hashes? <bwalton@rochester.rr.com>
Re: High CPU usage and mem leak problem in a perl routi <anthony@no_spam.movielink.net.au>
Re: How to Store and Print this Array? (James E Keenan)
Re: How to Store and Print this Array? <abigail@abigail.nl>
Mismatched or just plain incorrect Config.pm <jasonp@uq.net.au>
Re: need help "cross-building"perl 5.8.0 <petem@fl.net.au>
Perl, Xcopy on Windows, printing out results as we go (Jim B)
Re: regex and extracting permutations <ryan.311@osu.edu>
Re: removing spaces in a string <brucef@spammified.bmc-tech.com>
Re: Replying to Posts ( was: Re: check IP address ) <abuse@mweb.co.za>
Re: Replying to Posts ( was: Re: check IP address ) (Sam Holden)
Re: Search and replace - mutliples on one line? <sammie@greatergreen.com>
Re: Weighed shuffle/select. Vocabulary test <grazz@pobox.com>
Re: Weighed shuffle/select. Vocabulary test (Anno Siegel)
Re: what's the scope of global variable in cgi ? (JR)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 May 2003 13:45:41 -0700
From: "Tim McIntyre" <tmac@trransport.com>
Subject: Re: -T and DBI
Message-Id: <pan.2003.05.13.20.45.41.684327@trransport.com>
On Tue, 13 May 2003 16:54:57 +0000, David K. Wall wrote:
You can't print tainted data to a normal file though. All a table
is is a specialized type of file. And you definently are affecting
something outside your program.
Still doesn't make sense to me ???
Tim McIntyre
> Tim McIntyre <tmac@trransport.com> wrote:
>
>> It seems strange to me that I can write a program useing taint checks
>> and then insert data into a mysql table without untainting it.
>>
>> Why is that??? What am I missing???
>
> perlsec states that in taint mode "You may not use data derived from
> outside your program to affect something else outside your program".
> You're not really affecting the OS or the database software in any way,
> you're just storing the data. Even if the data said "rm -rf /", there's
> still no harm in storing that string in a database. If you tried to pass
> that string to system() or something similar, *then* the taint checks
> would be triggered.
>
> That's my take on it, anyway. Corrections and additions are welcome.
------------------------------
Date: Tue, 13 May 2003 21:23:00 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: -T and DBI
Message-Id: <Xns937AB0D4F44EEdkwwashere@216.168.3.30>
[Please don't top-post]
Tim McIntyre <tmac@trransport.com> wrote:
> You can't print tainted data to a normal file though.
Sure you can. Have you tried it? The path and the filename can't
depend on tainted data, but the data printed to a file doesn't have to
be untainted.
--
David K. Wall
------------------------------
Date: 13 May 2003 23:18:50 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: -T and DBI
Message-Id: <slrnbc2vaq.2dr.abigail@alexandra.abigail.nl>
Tim McIntyre (tmac@trransport.com) wrote on MMMDXLII September MCMXCIII
in <URL:news:pan.2003.02.13.17.28.51.168879@trransport.com>:
() It seems strange to me that I can write a program useing taint checks
() and then insert data into a mysql table without untainting it.
Yup, just as you can write tainted data to a file or a socket.
() Why is that??? What am I missing???
The "TaintIn" and "TaintOut" DBI attributes. See the manual.
Abigail
--
#!/opt/perl/bin/perl -- # Remove trailing newline!
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJ
------------------------------
Date: 13 May 2003 23:21:12 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: @Array - making it null
Message-Id: <slrnbc2vf7.2dr.abigail@alexandra.abigail.nl>
Balaji Venkataraman (dont-reply@this.address) wrote on MMMDXLII September
MCMXCIII in <URL:news:Pine.GSO.4.44.0305130946500.10521-100000@leith>:
__
__ As an aside - I wonder how the prominent posters on this group (or any
__ other for that matter), use your real email addresses? Don't you get
__ spammed?
Yes, about 60 or so a day. But do you think I let the spammers win?
No way. Email is a far too important medium not to show my email address.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: Tue, 13 May 2003 17:00:20 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Convert array into hash element
Message-Id: <Xns937AB7368F4A3sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Lechu <kopetnik@s-pam-nie.yahoo.com> wrote in
news:jcm1cvcn2k2133j1uam0f3v3n8bv3t4s9t@4ax.com:
> How to do this:
>
> Given is an array with unknown number of elements, ie:
> @a = ('a','b','c','d','e');
>
> I want to convert it into hash like:
> $h={};
> $h->{'a'}{'b'}{'c'}{'d'}{'e'} = 1
Hmmm. First thing that occurs to me is:
my $expr = "\$h->{'" . join("'}{'",@a) . "'} = 1";
eval $expr;
die if $@;
- --
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+wWsDY96i4h5M0egRAlUPAJ43pp8v8JOmud3r/lOJv6r/N5rW+QCfZFVg
9B38IpTkRoN/hksBmWLCjeE=
=ga6o
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 13 May 2003 15:47:27 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Convert array into hash element
Message-Id: <Pine.GSO.4.21.0305131546020.20509-100000@mtwhitney.nsc.com>
On Tue, 13 May 2003, Eric J. Roode wrote:
> Lechu <kopetnik@s-pam-nie.yahoo.com> wrote in
> news:jcm1cvcn2k2133j1uam0f3v3n8bv3t4s9t@4ax.com:
>
> > How to do this:
> >
> > Given is an array with unknown number of elements, ie:
> > @a = ('a','b','c','d','e');
> >
> > I want to convert it into hash like:
> > $h={};
> > $h->{'a'}{'b'}{'c'}{'d'}{'e'} = 1
>
> Hmmm. First thing that occurs to me is:
>
> my $expr = "\$h->{'" . join("'}{'",@a) . "'} = 1";
> eval $expr;
> die if $@;
>
If you wish to eschew 'eval', you can do this:
#! /usr/local/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $href;
my $ptr = \$href;
my @a = ('a','b','c','d','e');
for (@a) {
$ptr = \$$ptr->{$_}
}
$$ptr = 1;
print Dumper $href;
--
Hope this helps,
Steven
------------------------------
Date: Tue, 13 May 2003 17:15:54 -0600
From: "Shawn" <spedwards@qwest.net>
Subject: disk usage script
Message-Id: <E2fwa.562$Xf4.56056@news.uswest.net>
Hi,
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!
------------------------------
Date: Tue, 13 May 2003 23:38:27 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: disk usage script
Message-Id: <3EC181DB.9030508@rochester.rr.com>
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
{------------------------------------------------------------^
Please cut/paste code!
> %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.
I would guess the find command on your new server is generating one
column less of information than it did on the old server. It will
probably work if you change the [5] to [4] and the [7] to [6].
>
> This is what it used to look like:
>
> greg 4297
...
> It is now returning this:
>
> joegrp 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
...
--
Bob Walton
------------------------------
Date: Tue, 13 May 2003 16:40:40 -0700
From: "Kevin Sproule" <kevinsproule@hotmail.com>
Subject: Re: disk usage script
Message-Id: <gofwa.31065$eJ2.25857@fed1read07>
"Shawn" <spedwards@qwest.net> wrote in message
news:E2fwa.562$Xf4.56056@news.uswest.net...
> Hi,
>
> 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!
>
>
Shawn,
Try:
/opt/bin/find . -ls -mount | perl -ne 'chomp; $u{(split(/\s+/))[4]}
+=(split(/\s+/))[6]; END {foreach $key (sort {$u{$b} <=> $u$a}} keys
%u){printf "%-5s %-10d\n",$key, $u{$key};}}'
It looks like the ouput from find on the new server has added an extra
column which is causing the script to pick up the wrong fields.
Kevin
------------------------------
Date: 13 May 2003 14:39:12 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: egrep exclude
Message-Id: <b955da04.0305131339.3bda0591@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnbc22n9.2dr.abigail@alexandra.abigail.nl>...
> James E Keenan (jkeen@concentric.net) wrote on MMMDXLII September
> MCMXCIII in <URL:news:b955da04.0305130648.555df936@posting.google.com>:
> :)
> :) The OP indicated he was a novice, or at least a novice to Perl. It
> :) seems reasonable to suggest to a novice that he at least consider
> :) writing a script entirely in Perl rather than a mixture of shell and
> :) Perl.
>
>
> Why? If (s)he is more familiar with the shell? Perl is a *glue*
> language, and Larry has always said it's ok to talk baby-Perl.
>
Okay. May I suggest that you go back to the OP and give him some
suggestions as to solving his problem that are based on mixing shell
and Perl?
------------------------------
Date: 13 May 2003 15:47:47 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Perl Modules for Newbie non-administrator?
Message-Id: <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
Is there a good faq on this? or anyone with advice?
Thanks,
entropy
------------------------------
Date: Tue, 13 May 2003 23:29:53 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help: Perl Modules for Newbie non-administrator?
Message-Id: <3EC17FD9.70602@rochester.rr.com>
entropy123 wrote:
...
> 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
>
>
> Is there a good faq on this? or anyone with advice?
Well, you could probably install it into your own directory, where you
do have write permission. Check out the configuration options available
with the CPAN module to see how. You'll need to add that directory to
your @INC so Perl can find the module. Or you could install the
entirety of Perl in your own directory, and be done with such hassles in
the future. And be able to keep Perl up to date without hassling your
sysadmin.
...
> entropy
>
--
Bob Walton
------------------------------
Date: 13 May 2003 15:18:46 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Working with a hash of hashes?
Message-Id: <90cdce37.0305131418.df9d528@posting.google.com>
Hey all,
Following the advice of this group to solve a problem I created a
'Hash of Hashes' I prefer to call it supha.
How do I work with this thing, in particular how do I separate it out
into arrays and the like?
One of my regular hashes looks like this:
my %hash = ();
my @goog = keys %hash;
my @yahoo = values %hash;
Is there any way to separate out the values in my supha{}{} into a set
of arrays? Or even into keys and values?
The code where I create supha is as follows:
$supha{$tid[$one]}{$tid[$two]} = $three;
$supha{$tid[$two]}{$tid[$one]} = $three;
I really would like to create an array named after $tid[$one]
containing all the $tid[$two]'s attached to it...
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....
Thanks!
entropy
------------------------------
Date: Tue, 13 May 2003 23:17:21 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help: Working with a hash of hashes?
Message-Id: <3EC17CE9.90604@rochester.rr.com>
entropy123 wrote:
...
> Following the advice of this group to solve a problem I created a
> 'Hash of Hashes' I prefer to call it supha.
It is usually termed a hoh here.
>
> How do I work with this thing, in particular how do I separate it out
> into arrays and the like?
It looks like you have the general idea. Two functions are available
for this purpose, keys (returns a list containing all the keys of its
argument, which must be a hash) and values (returns a list containing
all the values if its argument, which must be a hash). The two lists
will be in the same order, but that order is pseuodrandom.
>
> One of my regular hashes looks like this:
>
> my %hash = ();
> my @goog = keys %hash;
> my @yahoo = values %hash;
>
> Is there any way to separate out the values in my supha{}{} into a set
> of arrays? Or even into keys and values?
You'll probably need to be clearer regarding what you want. Here is
code that would convert it to an array of arrays, with each element of
the outer array containing as value a reference to an anonymous array
which holds the values of the inner hashes, all without any key information:
use Data::Dumper;
%supha=('one',{won=>1,too=>2},'two',{wonwon=>11,tootoo=>22});
print Dumper(\%supha);
for(values %supha){
push @array,[values %$_];
}
print Dumper(\@array);
Is that what you want?
>
> The code where I create supha is as follows:
>
> $supha{$tid[$one]}{$tid[$two]} = $three;
> $supha{$tid[$two]}{$tid[$one]} = $three;
>
> I really would like to create an array named after $tid[$one]
> containing all the $tid[$two]'s attached to it...
That can be done, but it is a *bad idea*. Why? Because it corrupts
your namespace. Suppose, for example, that $tid[$one] has the value
'tid'. Then you will clobber your @tid array. To find out how, see
perldoc perlref
I won't show you how, since it is a bad idea. What should you do
instead? Use a hash -- it is like having your very own private
namespace -- actually, one for each hash you use. The hash it is
already in is probably a good candidate for such a hash.
>
> 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....
Well, there are hash slices, map, and maybe some more.
...
> entropy
>
--
Bob Walton
------------------------------
Date: Wed, 14 May 2003 10:18:22 +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.00.18.20.930893@no_spam.movielink.net.au>
To all who have responded, thanks for trying, more
info follows...
On Tue, 13 May 2003 05:03:19 -0500, Eric J. Roode wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Tony" <anthony@no_spam.movielink.net.au> wrote in
> news:pan.2003.05.13.08.20.15.969025@no_spam.movielink.net.au:
>
>> All works perfectly except for a CPU usage of 98%
>
> Well, your program reads the input file, then goes back and reads the
> input file, over an over again, without pausing for breath. Of
> course it'll take up all of your CPU time. So would the following
> loop:
I need to qualify things a bit better...
The reason for the "looping" is that each line of the file has
a DAY and TIME and some data after that on the same line.
The file is staic, it only needs to be read in once.
The loop is nothing more than a crude timer.
The idea is to continuesly scan the file, looking for a match of
"current time" and "current day". When a match occurs the data
in that line is processed and sent off to a child process.
The child and grand child processes are well defined and only
do a very minimum of processing, CPU and mem usage does not
even register with those. They work correctly.
I have a sleep(1); statement after the match (Before the
fork sub is called) occurs, without that the match triggers
as many matches as can be found within one second = to number
of looping the file (I match with a resolution of 1 second).
I have in place all the "wait()" statements, the children and
grand children all die properly with exits so there
are no zombies "hanging around". The child exist gracefully.
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?
I am not so concerned with the CPU usage, only with the memory
being used.
> START: for (1..100) { print "Whee!" } goto START;
>
>
>> and the memory usage climbing to 100% within an hour or so.
>
> You say your subroutine forks. Does the child exit? Or does it
> simply return to the main loop, there to fork off another child
> process? If your children are forking off children, you'll run out
> of memory in no time.
>
> If your child processes are exiting, does the parent process wait()
> for them? If not, you'll have a bunch of zombie processes hanging
> around in memory.
>
>
>> I think the problem lies with opening the file handle in the
>> loop as shown. Every time the file has been scanned, the program
>> will go to reopen the file handle. (When perl opens an open
>> handle it closes the open one first).
>
> Why would that be a problem? How would that take up extra CPU time
> or memory?
I am just guessing here...
>> 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 say one of the problems with your program
> is that it takes up too much memory. How would reading MORE data
> into memory at a time help?
It would not, but if the problem is that I open/close/open a
file handle all the time that could cause greif.
Reading in the file into an @array, effectively storing
it once, would keep the memory usage finite. The file has a
size of not more than 6-8K so it is very small. It will never
be larger than 15-16K in a worst case.
>> The program needs to continuesly scan the input file.
>
> "Continuously"? If the file changes, must the program *immediately*
> respond to the change? Or is a delay of 5-10 seconds acceptable? If
> so, put a sleep() in your loop.
The file is static as mentioned above.
> Does the program need to respond to changes that happen anywhere in
> the file? Or are new lines simply appended to the file, and you have
> to respond to those new lines?
No changes...
>> Any suggestions on this little problem?
>>
>> Will the memory and CPU usage problem persist if all
>> is read into an @array?
>
> You bet.
Memory too?
> - --
> 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+wMMGY96i4h5M0egRAtWlAKDHz0H4y7A6Wd8M6zrGTAvq8e2onACgu4I6
> hYuhRBiOxYi108X5tnNg+R0=
> =yyyl
> -----END PGP SIGNATURE-----
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
------------------------------
Date: 13 May 2003 14:46:55 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: How to Store and Print this Array?
Message-Id: <b955da04.0305131346.51d4b337@posting.google.com>
dave_h4@yahoo.com (Hunter) wrote in message news:<27ad91d2.0305130626.4325f4be@posting.google.com>...
> Hi - I need to query a database and print the rows returned. I would
> like to count the number of people from each country. Of course - I
> only want to query and print the country's that are populated - not
> the entire list of countries.
>
> My query is as such:
> "select count(country), country from customers GROUP BY country"
>
> returns:
> count | country
> -------+---------
> 1 | AE
> 1 | DE
> 2 | DZ
> 2 | FR
> 3 | ZA
> 5 | US
> 84 | CA
> (7 rows)
>
> HOW can I store this query into a hash so I can print it to the
> browser using cgi ?
>
Can you tell us a bit more about the environment you're in (i.e., what
database) and how you have attempted to solve the problem so far
(i.e., show us some code)? Are you using the Perl-DBI interface? Are
you using CGI.pm?
In general, to print values from a hash while skipping over entries
whose values are 0 looks like this:
foreach my $coun (sort keys %countries) {
print "$countries{$coun}\n" unless (! $countries{$coun});
}
But I suspect you want something more tied to your environment than
just that.
------------------------------
Date: 13 May 2003 23:23:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to Store and Print this Array?
Message-Id: <slrnbc2vje.2dr.abigail@alexandra.abigail.nl>
Hunter (dave_h4@yahoo.com) wrote on MMMDXLII September MCMXCIII in
<URL:news:27ad91d2.0305130626.4325f4be@posting.google.com>:
@@ Hi - I need to query a database and print the rows returned. I would
@@ like to count the number of people from each country. Of course - I
@@ only want to query and print the country's that are populated - not
@@ the entire list of countries.
@@
@@ My query is as such:
@@ "select count(country), country from customers GROUP BY country"
@@
@@ returns:
@@ count | country
@@ -------+---------
@@ 1 | AE
@@ 1 | DE
@@ 2 | DZ
@@ 2 | FR
@@ 3 | ZA
@@ 5 | US
@@ 84 | CA
@@ (7 rows)
@@
@@ HOW can I store this query into a hash so I can print it to the
@@ browser using cgi ?
Is there anything unclear about the DBI manual?
Abigail
--
@_=map{[$!++,$_^$/]}split$²,"\@\x7Fy~*kde~box*Zoxf*Bkiaox";$\="\r";
$|=++$*;do{($#,$=)=(rand@_,rand@_);@_[$#,$=]=@_[$=,$#]}for($*..@_);
for$:($|..@_-$|){for($|..@_-$:){@_[$_-$|,$_]=@_[$_=>$_-$*]if$_[$_][
$¼]<$_[$_-$*][$®];print+map{$_->[$|]}@_;select$·,$°,$½,0.1}}print$/
------------------------------
Date: Tue, 13 May 2003 14:56:18 -0400
From: Jason Parker-Burlingham <jasonp@uq.net.au>
Subject: Mismatched or just plain incorrect Config.pm
Message-Id: <87n0hqvfot.fsf@freezer.burling>
I have a small amount of work to do on an AIX box, for which I've
written a few classes and want to install one or two more from CPAN.
The development environment is Perl 5.6.0; perl -V reports that @INC
is set to look under /usr/local/lib. Unfortunately this isn't correct
because Perl seems to have been moved to another directory hierarchy
entirely (which is not really /Foo but the exact name is not important
and the paths are otherwise identical).
I was hoping that appropriate frobbing of PERLLIB or PERL5LIB would
get things working again, but this appears to not be the case:
$ echo $PERLLIB
/Foo/APPS/utils/perl560/lib/perl5/5.6.0:/Foo/APPS/utils/perl560/lib/perl5/5.6.0/aix:/Foo/APPS/utils/perl560/lib/perl5/5.6.0/aix/CORE
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Error: Unable to locate installed Perl libraries or Perl source code.
It is recommended that you install perl in a standard location before
building extensions. Some precompiled versions of perl do not contain
these header files, so you cannot build extensions. In such a case,
please build and install your perl from a fresh perl distribution. It
usually solves this kind of problem.
(You get this message, because MakeMaker could not find "/usr/local/lib/perl5/5.6.0/aix/CORE/perl.h")
CORE/perl.h does exist under /Foo
(/Foo/APPS/utils/perl560/lib/perl5/5.6.0/aix/CORE/perl.h to be exact)
and I was hoping that adding .../aix/CORE to PERLLIB would do the
trick, but now I am wondering if I will need to have someone edit
Config.pm, which lives under /Foo but contains references to
/usr/local instead.
Is there any other easy solution to this problem?
--
``Oooh! A gingerbread house! Hansel and Gretel are set for life!''
------------------------------
Date: Wed, 14 May 2003 10:55:22 +1000
From: "Peter J. MASON" <petem@fl.net.au>
Subject: Re: need help "cross-building"perl 5.8.0
Message-Id: <3ec191a0@fl.net.au>
This problem has been cleared. This perl port is now up and useful.
------------------------------
Date: 13 May 2003 11:44:14 -0700
From: jigidyjim@aol.com (Jim B)
Subject: Perl, Xcopy on Windows, printing out results as we go
Message-Id: <457dade9.0305131044.68159a3d@posting.google.com>
Hey there -
I've got Active Perl 5.6.1 and am running on Windows 2000. I've got a
perl script that does a big recursive xcopy and copies a lot of files
over. I am running the xcopy like
system( "xcopy /d /i /s /r /y /f @ARGV[0]\\mydir\\*.* @ARGV[1]" );
now, when i run xcopy straight from windows (in a .bat file or
something) it prints out each file as it copies it. However, the perl
script prints out the whole thing at the very end.
It would be nice if it printed out as it went along so I could see the
progress of the script.
Any ideas?
------------------------------
Date: Tue, 13 May 2003 16:02:36 -0400
From: Joseph Ryan <ryan.311@osu.edu>
To: Ryan McCarthy <remccart@uiuc.edu.spam>
Subject: Re: regex and extracting permutations
Message-Id: <3EC14F5C.5010304@osu.edu>
Ryan McCarthy wrote:
> I am tryng to use regular exprssions to extract permutations of a
> sequence into an array. Here are the parameters that I need to meet.
>
> The sequence is in the form
>
> ACK
> SG[IL]N
> SG[IUD]
> [NO]S[YR]NR
> etc...
>
> where the needed function would produce teh array with the following
> entries
>
> ACK
> SGIN
> SGLN
> SGI
> SGU
> SGD
> NSYNR
> NSRNR
> OSYNR
> OSRNR
>
> Additional things to consider:
> - there is no limit on the number of lines that can be entered
> - there is no limit on the number of letters that can be between the
> brackets [ ]
> - there is no limit on the number of bracketed characters per line
So, the brackets make no difference and can just be stripped?
- Joe
------------------------------
Date: Tue, 13 May 2003 19:32:05 GMT
From: "Bruce Fournier" <brucef@spammified.bmc-tech.com>
Subject: Re: removing spaces in a string
Message-Id: <VKbwa.832771$L1.242104@sccrnsc02>
$line =~ s/\s+/x/g;
"Kevin" <kgiles@optonline.net> wrote in message
news:337213e2.0305130932.730d10ac@posting.google.com...
> how do you remove spaces in a string varaible?
>
> thanks
>
> kg
------------------------------
Date: Tue, 13 May 2003 21:06:47 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Re: Replying to Posts ( was: Re: check IP address )
Message-Id: <pan.2003.05.13.19.06.41.109786@mweb.co.za>
I'm afraid it doesn't make sense to me. I like to read the posting with
the newest stuff at the top. This really sucks.
On Mon, 12 May 2003 23:22:20 +0000, Martien Verbruggen wrote:
> [TOFU fixed. Please, again, do not top-post]
>
> On Mon, 12 May 2003 20:49:10 +0200,
> Nico Coetzee <abuse@mweb.co.za> wrote:
>> On Mon, 12 May 2003 02:19:26 +0000, Martien Verbruggen wrote:
>>
>>> [Please, do not top-post]
>>>
>>> Martien
>
>> I was told in a previous post that I should top-post.
>
> I am fairly certain that it was not on this newsgroup, or any other
> technical newsgroup. Some groups have pandered to the bad design of
> certain excuses of news readers and the laziness of their users and
> are using top-posting as the norm, but they are the exception. When on
> those groups, top-post. Anywhere else, do the Right Thing (TM).
>
>> Which is it now? Does this ng have a FAQ?
>
> For this newsgroup, start at:
>
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
> For usenet in general, start at news.announce.newusers, and maybe
> http://www.faqs.org/usenet/
>
> Martien
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: 13 May 2003 19:38:37 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Replying to Posts ( was: Re: check IP address )
Message-Id: <slrnbc2idt.8ss.sholden@flexal.cs.usyd.edu.au>
On Tue, 13 May 2003 21:06:47 +0200, Nico Coetzee <abuse@mweb.co.za> wrote:
> I'm afraid it doesn't make sense to me. I like to read the posting with
> the newest stuff at the top. This really sucks.
Well, enjoy reading your own posts, since a whole lot of other people
won't be...
--
Sam Holden
------------------------------
Date: Tue, 13 May 2003 20:30:09 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Search and replace - mutliples on one line?
Message-Id: <lBcwa.833079$L1.241720@sccrnsc02>
> I need to search a variable, and replace all unsafe html characters with
> safe hex code points (or escape characters).
I found a solution to the problem, thanks to someone who replied to me
privately (so I will not mention his name).
The answer:
my %entities = ( '&' => '&', '<' => '<', '>' => '>' );
...
$htmlparams[1] =~ s/[&<>]/$entities{$&}/eg;
...
Thanks for the help!
Brad
------------------------------
Date: Tue, 13 May 2003 18:46:11 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Weighed shuffle/select. Vocabulary test
Message-Id: <T3bwa.25688$h42.17268@twister.nyc.rr.com>
James Kilfiger <zeimusu@yahoo.co.uk> wrote:
> I've read a ton of articles here about shuffling, I learnt a lot about
> Fisher-Yates that I didn't know know before, but they haven't quite
> helped me.
>
> I want to select an array in such a way that I favour some elements
> over others.
>
> What I really want to do is make spelling tests. I have a list of
> words that students have to learn. I want make little tests from (say)
> 10 words, but to prevent cheating I want each student to have a
> different set of words.
>
> I can do that with the shuffle algorithm from the faq list or
> something like it.
>
> But say I want to favour words starting with 'A', or words from
> chapter 5 (or whatever)
>
> I imagine that I have some kind of weight attached to each word, the
> higher the weight the more likely the word should be to appear in the
> list.
You can select a "weighted" random hash key, where the values
represent the weight, like this:
sub weighted_pick {
my $items = shift;
my ($total, $item);
while (my ($k,$v) = each %$items) {
$item = $k if rand($total += $v) < $v
}
$item
}
And so a very blunt-instrument approach to selecting a random,
weighted subset of the keys would look something like:
sub weighted_subset {
my ($size, %items) = @_;
map {
my $i = weighted_pick(\%items);
delete $items{$i};
$i
} 1..$size
}
And then to use it:
# words starting with an 'a' are 5 times
# as likely to be selected
my @words = qx{ cat /usr/dict/words };
my %items = map { $_ => /^[Aa]/ ? 5 : 1 } @words;
print for weighted_subset(10, %items);
--
Steve
------------------------------
Date: 13 May 2003 20:47:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Weighed shuffle/select. Vocabulary test
Message-Id: <b9rllr$ti$1@mamenchi.zrz.TU-Berlin.DE>
Steve Grazzini <grazz@pobox.com> wrote in comp.lang.perl.misc:
[...]
> You can select a "weighted" random hash key, where the values
> represent the weight, like this:
>
> sub weighted_pick {
> my $items = shift;
> my ($total, $item);
> while (my ($k,$v) = each %$items) {
> $item = $k if rand($total += $v) < $v
> }
> $item
> }
Oh, that's the trick of Fisher-Yates again, only with pre-settable weights
instead of having all weights = 1. It's like magic, you don't even have
to normalize the weights. And a neat implementation, if I may say so.
If I just knew where to keep it so that I find it again when I need it.
Couldn't it go into the FAQ, with the existing "How do I select a random
line from a file?"
[more good stuff snipped]
Anno
------------------------------
Date: 13 May 2003 13:16:20 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: what's the scope of global variable in cgi ?
Message-Id: <b386d54b.0305131216.5d04e317@posting.google.com>
"j" <perseus_medusa@hotmail.com> wrote in message news:<3ec0d907$1@newsgate.hknet.com>...
> Hi all ,
>
> i am changing a run alone perl script to a module which consist of many
> global variable. I am going to use that module in cgi. So I want to ask will
> the module's global variable be shared by all cgi perl script using it ?
>
> Thanks.
>
> Perseus
I think this is what you want, if I understand correctly what you're
asking. I hope this helps. For more information, see "The Perl
Cookbook," and "Programming Perl," respectively.
The below example is just the bare minimum utilization of modules.
#########SAMPLE MODULE#########
use strict;
package YourModule;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw($globalHello); # Export by default
our $globalHello = 'Hello, World';
1;
###############################
#########CALLING PERL SCRIPT (adapt to CGI, as necessary)###########
#! Perl
use strict;
use warnings;
use diagnostics;
use YourModule;
print "$globalHello\n"; # Print variable from YourModule.pm
######################################
------------------------------
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 4980
***************************************