[21700] in Perl-Users-Digest
Perl-Users Digest, Issue: 3904 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 2 18:10:58 2002
Date: Wed, 2 Oct 2002 15:10:23 -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, 2 Oct 2002 Volume: 10 Number: 3904
Today's topics:
POST slow with Netscape 4 and IIS? <gerry1@dircon.co.uk>
Re: POST slow with Netscape 4 and IIS? <jurgenex@hotmail.com>
Re: POST slow with Netscape 4 and IIS? <gerry1@dircon.co.uk>
print reverse question <Use-Author-Address-Header@[127.1]>
Re: print reverse question <uri@stemsystems.com>
Re: print reverse question ctcgag@hotmail.com
Re: print reverse question <brittedg@student.gvsu.edu>
Re: print reverse question <bart.lateur@pandora.be>
Re: print reverse question <me@dwall.fastmail.fm>
Re: print reverse question <Use-Author-Address-Header@[127.1]>
Re: print reverse question <bart.lateur@pandora.be>
Re: Question regarding CGI.pm, nt_upload.lib and parsin <linkseer@yahoo.com>
Rescheduling a perl script with AT (Ralph Slate)
Re: Rescheduling a perl script with AT <Graham.T.Wood@oracle.com>
Re: Rescheduling a perl script with AT <Graham.T.Wood@oracle.com>
script.pl?parameter - can anyone help me figure this ou (gwarble)
Re: script.pl?parameter - can anyone help me figure thi <jurgenex@hotmail.com>
Re: script.pl?parameter - can anyone help me figure thi <dparrott@twmi.rr.com>
simple grep Q <penny1482@attbi.com>
Re: Sort hash of hash <bigj@kamelfreund.de>
Re: Sort hash of hash <me@dwall.fastmail.fm>
Re: Sort hash of hash <bart.lateur@pandora.be>
Re: Sticky forms without CGI.pm? <wsegrave@mindspring.com>
Re: String substitution of 3+ digit numbers only? <bigj@kamelfreund.de>
Re: Top posting (was Re: How can I count files in a dir <tom.beer@btfinancialgroup.spamfilter.com>
Re: Unable to trap error from child <tom.beer@btfinancialgroup.spamfilter.com>
Re: Why are the columns of a MySQL SELECT scrambled? ctcgag@hotmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 02 Oct 2002 19:11:01 +0100
From: Gerry Hickman <gerry1@dircon.co.uk>
Subject: POST slow with Netscape 4 and IIS?
Message-Id: <3D9B36B5.A80BC712@dircon.co.uk>
Hi,
I asked about this before, but I don't think it got solved;
When I submit a form (cgi.pm generated) it takes ages to render the conf
page in Netscape 4? I tried both encoding schemes but same problem.
IIS logs tend to imply the data got sent right away. As far as I know
this doesn't happen on Apache. I'm using Win2k and IIS5.
--
Gerry Hickman (London UK)
------------------------------
Date: Wed, 2 Oct 2002 12:16:54 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: POST slow with Netscape 4 and IIS?
Message-Id: <3d9b462a@news.microsoft.com>
Gerry Hickman wrote:
> I asked about this before, but I don't think it got solved;
Where did you ask? In a Perl NG?
> When I submit a form (cgi.pm generated) it takes ages to render the
> conf page in Netscape 4? I tried both encoding schemes but same
> problem.
>
> IIS logs tend to imply the data got sent right away. As far as I know
> this doesn't happen on Apache. I'm using Win2k and IIS5.
Then it's no surprise that you didn't get any reply.
Your question/issue/problem has nothing to do with Perl whatsoever.
You may want to ask in a NG that actually deals with
CGI/IIS/Apache/Win2k/HTML/TheWeb/Netscape/....
jue
------------------------------
Date: Wed, 02 Oct 2002 22:48:29 +0100
From: Gerry Hickman <gerry1@dircon.co.uk>
Subject: Re: POST slow with Netscape 4 and IIS?
Message-Id: <3D9B69AD.BD71B9ED@dircon.co.uk>
Hi Jurgen,
> Where did you ask? In a Perl NG?
This group.
> Then it's no surprise that you didn't get any reply.
> Your question/issue/problem has nothing to do with Perl whatsoever.
I got plenty replies, but no one knew what was causing it.
> You may want to ask in a NG that actually deals with
> CGI/IIS/Apache/Win2k/HTML/TheWeb/Netscape/....
Yup; I'll head over to cgi.iis.apache.win2k.html.theweb.netscape!! I
know what you mean though. Part of the reason for asking on here is that
lots of people use Perl with CGI, whereas most IIS people use .NET and
ASP. I'm writing cross-platform so I'm stuck with CGI:(
--
Gerry Hickman (London UK)
------------------------------
Date: Wed, 2 Oct 2002 12:00:21 -0700
From: Amanda Rechonwith <Use-Author-Address-Header@[127.1]>
Subject: print reverse question
Message-Id: <200210021900.g92J0LMu024800@www.aarg.net>
$string = "egasseM";
print reverse($string); # Results in egasseM
$g = reverse($string);
print("$g"); # Results in Message
Why doesn't the first print statement result in Message ?
------------------------------
Date: Wed, 02 Oct 2002 19:05:10 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: print reverse question
Message-Id: <x7n0pw64re.fsf@mail.sysarch.com>
>>>>> "AR" == Amanda Rechonwith <Use-Author-Address-Header@[127.1]> writes:
AR> $string = "egasseM";
AR> print reverse($string); # Results in egasseM
AR> $g = reverse($string);
AR> print("$g"); # Results in Message
AR> Why doesn't the first print statement result in Message ?
perldoc -f reverse
and look for the part than talks about context.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 02 Oct 2002 19:29:59 GMT
From: ctcgag@hotmail.com
Subject: Re: print reverse question
Message-Id: <20021002152959.702$GU@newsreader.com>
Amanda Rechonwith <Use-Author-Address-Header@[127.1]> wrote:
> $string = "egasseM";
> print reverse($string); # Results in egasseM
print expects a list, so reverse reverses a list (of one element).
>
> $g = reverse($string);
> print("$g"); # Results in Message
$g = expects a scalar, so reverse reverses a scalar.
> Why doesn't the first print statement result in Message ?
What part of the documentation did you not understand?
How would you suggest making it clearer?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Wed, 02 Oct 2002 15:34:27 -0400
From: David Britten <brittedg@student.gvsu.edu>
Subject: Re: print reverse question
Message-Id: <B9C0C283.5326%brittedg@student.gvsu.edu>
On 10/2/02 3:00 PM, in article 200210021900.g92J0LMu024800@www.aarg.net,
"Amanda Rechonwith" <Use-Author-Address-Header@[127.1]> wrote:
>
> $string = "egasseM";
> print reverse($string); # Results in egasseM
>
> $g = reverse($string);
> print("$g"); # Results in Message
>
> Why doesn't the first print statement result in Message ?
>
>
I may be WAY off on this, but here goes...
Reverse is designed to operate on lists, not on string scalars. You're
passing it a single element list which contains $string.
print reverse($string);
The reverse function is defaulting to list context since print can handle
lists or scalars, which causes the elements to be placed in reverse order.
For a single element list, this obviously has no discernable effect. Thus,
you end up printing the single unmodified element, which is "eggasseM."
$g = reverse($string);
In this case, reverse is in a scalar context, and according to O'Reilly's
Perl Pocket Reference (page 31,) it "concatenates the list elements and
returns the reverse of the resulting string." So it's concatenating all one
of the passed elements, and then reversing the string that results. In that
case, you get the proper reversed "Message," although you likely didn't
expect to get it for quite that reason.
I don't see any string functions dedicated to reversing single strings, but
I'll bet you can just do something like "print scalar reverse($string)" and
get proper results. Just be mindful of forcing scalar contexts when
necessary.
-David Britten
------------------------------
Date: Wed, 02 Oct 2002 19:43:15 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: print reverse question
Message-Id: <n0jmpusv12k9h127bbio4uolh7tdsimams@4ax.com>
Amanda Rechonwith wrote:
>$string = "egasseM";
>print reverse($string); # Results in egasseM
>
>$g = reverse($string);
>print("$g"); # Results in Message
>
>Why doesn't the first print statement result in Message ?
print() provides a list context. reverse() doe act differently in list
than in scalar context.
Try
print scalar reverse($string);
--
Bart.
------------------------------
Date: Wed, 02 Oct 2002 19:55:55 -0000
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: print reverse question
Message-Id: <Xns929BA2115224Cdkwwashere@216.168.3.30>
Amanda Rechonwith <Use-Author-Address-Header@[127.1]> wrote on 02 Oct 2002:
> $string = "egasseM";
> print reverse($string); # Results in egasseM
reverse() is in list context here. (print() expects a list.)
> $g = reverse($string);
> print("$g"); # Results in Message
reverse() is in scalar context here.
> Why doesn't the first print statement result in Message ?
perldoc -f reverse
reverse LIST
In list context, returns a list value consisting of the elements of LIST in
the opposite order. In scalar context, concatenates the elements of LIST and
returns a string value with all characters in the opposite order.
--
David K. Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Wed, 2 Oct 2002 13:09:55 -0700
From: Amanda Rechonwith <Use-Author-Address-Header@[127.1]>
Subject: Re: print reverse question
Message-Id: <200210022009.g92K9tD3031379@www.aarg.net>
In article <x7n0pw64re.fsf@mail.sysarch.com>
Uri Guttman <uri@stemsystems.com> wrote:
>
> perldoc -f reverse
>
> and look for the part than talks about context.
>
Thank you. I did read the "context" part but it
didn't sink in. I just didn't see that in one case
the context is list and in the other case it's
scalar.
After changing this
print reverse($string);
into this
print scalar reverse($string);
I got the desired result.
Of course, perldoc -f reverse has the exact
example - RTFM! Even tho I did RTFM, I still
failed to see it.
------------------------------
Date: Wed, 02 Oct 2002 20:29:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: print reverse question
Message-Id: <0jlmpucq5psj0gnuiqa7ask7oh133cjlmv@4ax.com>
David Britten wrote:
>I may be WAY off on this, but here goes...
>
>Reverse is designed to operate on lists, not on string scalars. You're
>passing it a single element list which contains $string.
>
>print reverse($string);
Yes and no. reverse() is designed to work both on lists and on strings.
It makes the distinction based on the context: scalar context for a
strings, and list context for lists.
You're right that since it's in list context here, reverse() sees a
single element list, and reversing the order of all elemnts doesn't
appear t have any effect.
--
Bart.
------------------------------
Date: Wed, 02 Oct 2002 21:11:30 GMT
From: LinkSeer <linkseer@yahoo.com>
Subject: Re: Question regarding CGI.pm, nt_upload.lib and parsing.
Message-Id: <8aompug9bajukqf698bfrjb3c306g07er9@4ax.com>
On Sun, 29 Sep 2002 23:52:59 GMT, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>Oh, okay then. First and foremost, I strongly urge you to ditch your
>parse_form function and use CGI.pm exclusively to handle form input.
>
>Here's how to modify your program to use CGI.pm:
>
> 1. Instead of calling parse_form, do the following:
>
> my $cgi = new CGI;
>
> 2. Instead of $something = $input{something}, do this:
>
> $something = $cgi->param('something');
>
>That's about it.
>
Just wanted to say Thank You! for your assistance and everyones'
input.
------------------------------
Date: 2 Oct 2002 12:06:19 -0700
From: usenet@hockeydb.com (Ralph Slate)
Subject: Rescheduling a perl script with AT
Message-Id: <4609a7be.0210021106.29731920@posting.google.com>
I have a perl script that I would like to run each day using cron.
This script fetches some data. In some cases, the data is not yet
available. When this situation is detected, I want to reschedule the
exact same script to run in 10 minutes. I should be able to do this
with the AT command/program.
I am having problems getting this to work in perl. I can do this:
if (data_not_ready) {
system("at now + 10 minutes script.pl");
exit();
}
and this works just fine. But my script.pl needs to take an input
parameter, so I need to do this:
if (data_not_ready) {
system("at now + 10 minutes script.pl INPUT_PARAMETER");
exit();
}
This fails with an "unknown word" error, which is an AT error. If I
want to run this using AT interactively, I'd have to do it like this:
at now + 10 minutes
script.pl INPUT_PARAMETER
<Ctrl-D>
The man page for AT tells me that I can send it a script file with
this command in it, but I'm trying to dynamically generate the
INPUT_PARAMETER, so it wouldn't be available in a static script file
(and I don't want to dynamically create a script file that I then pass
as an input to AT if I don't have to).
I also tried this in perl:
system("at now + 10 minutes \n script.pl INPUT_PARAMETER");
On the theory that it might recornize the \n as a LF character, and
behave like the command line, but it didn't work either (it just
hung).
So the question is, how can I call the AT command from a perl script,
to execute a perl script with an input parameter?
Thanks,
Ralph Slate
------------------------------
Date: Wed, 02 Oct 2002 20:28:45 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Rescheduling a perl script with AT
Message-Id: <3D9B48ED.2BFA9149@oracle.com>
Ralph Slate wrote:
> I have a perl script that I would like to run each day using cron.
> This script fetches some data. In some cases, the data is not yet
> available. When this situation is detected, I want to reschedule the
> exact same script to run in 10 minutes. I should be able to do this
> with the AT command/program.
>
> I am having problems getting this to work in perl. I can do this:
>
> if (data_not_ready) {
> system("at now + 10 minutes script.pl");
> exit();
> }
>
> and this works just fine. But my script.pl needs to take an input
> parameter, so I need to do this:
>
> if (data_not_ready) {
> system("at now + 10 minutes script.pl INPUT_PARAMETER");
> exit();
> }
>
> This fails with an "unknown word" error, which is an AT error. If I
> want to run this using AT interactively, I'd have to do it like this:
>
> at now + 10 minutes
> script.pl INPUT_PARAMETER
> <Ctrl-D>
>
> The man page for AT tells me that I can send it a script file with
> this command in it, but I'm trying to dynamically generate the
> INPUT_PARAMETER, so it wouldn't be available in a static script file
> (and I don't want to dynamically create a script file that I then pass
> as an input to AT if I don't have to).
>
> I also tried this in perl:
>
> system("at now + 10 minutes \n script.pl INPUT_PARAMETER");
>
> On the theory that it might recornize the \n as a LF character, and
> behave like the command line, but it didn't work either (it just
> hung).
>
> So the question is, how can I call the AT command from a perl script,
> to execute a perl script with an input parameter?
>
> Thanks,
>
> Ralph Slate
I haven't tested this but you could try opening the AT command as a file
handle and then printing the parameter you want to send.
open(AT_COMMAND,"|at now + ten minutes") || die "Can't run at now + ten
minutes $!\n";
print AT_COMMAND "INPUT_PARAMETER\n";
close AT_COMMAND;
This will launch the "at now + ten minutes" command then send "INPUT
PARAMETER" to it after it has started.
Hope this helps
Graham Wood
------------------------------
Date: Wed, 02 Oct 2002 20:32:04 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Rescheduling a perl script with AT
Message-Id: <3D9B49B4.2F6D92C1@oracle.com>
Graham Wood wrote:
> Ralph Slate wrote:
>
> > I have a perl script that I would like to run each day using cron.
> > This script fetches some data. In some cases, the data is not yet
> > available. When this situation is detected, I want to reschedule the
> > exact same script to run in 10 minutes. I should be able to do this
> > with the AT command/program.
> >
> > I am having problems getting this to work in perl. I can do this:
> >
> > if (data_not_ready) {
> > system("at now + 10 minutes script.pl");
> > exit();
> > }
> >
> > and this works just fine. But my script.pl needs to take an input
> > parameter, so I need to do this:
> >
> > if (data_not_ready) {
> > system("at now + 10 minutes script.pl INPUT_PARAMETER");
> > exit();
> > }
> >
> > This fails with an "unknown word" error, which is an AT error. If I
> > want to run this using AT interactively, I'd have to do it like this:
> >
> > at now + 10 minutes
> > script.pl INPUT_PARAMETER
> > <Ctrl-D>
> >
> > The man page for AT tells me that I can send it a script file with
> > this command in it, but I'm trying to dynamically generate the
> > INPUT_PARAMETER, so it wouldn't be available in a static script file
> > (and I don't want to dynamically create a script file that I then pass
> > as an input to AT if I don't have to).
> >
> > I also tried this in perl:
> >
> > system("at now + 10 minutes \n script.pl INPUT_PARAMETER");
> >
> > On the theory that it might recornize the \n as a LF character, and
> > behave like the command line, but it didn't work either (it just
> > hung).
> >
> > So the question is, how can I call the AT command from a perl script,
> > to execute a perl script with an input parameter?
> >
> > Thanks,
> >
> > Ralph Slate
>
> I haven't tested this but you could try opening the AT command as a file
> handle and then printing the parameter you want to send.
>
> open(AT_COMMAND,"|at now + ten minutes") || die "Can't run at now + ten
> minutes $!\n";
> print AT_COMMAND "INPUT_PARAMETER\n";
>
typo: This should read
print AT_COMMAND "script.pl INPUT_PARAMETER\n";
> close AT_COMMAND;
>
> This will launch the "at now + ten minutes" command then send "INPUT
> PARAMETER" to it after it has started.
>
> Hope this helps
>
> Graham Wood
------------------------------
Date: 2 Oct 2002 11:54:04 -0700
From: gwarble@moonman.com (gwarble)
Subject: script.pl?parameter - can anyone help me figure this out?
Message-Id: <47b16626.0210021054.49bfdd70@posting.google.com>
hey all
i'm new to perl programming, mostly doing it for fun and practice on
my website... and i want to ask something... i've searched high and
low on the internet and in books on how to pass a parameter to a perl
script like this: script.pl?parameter in the url... i've seen it done
but i cant find how to read the parameter in the code
if you see my page (www.arcadefanatic.com) it might make more sense...
i have seperate html files for each game in my collection, and want to
make a game.pl script which will set up the basic layout that is the
same for each game, and then pass ?tetris for example so it
dynamically loads the equivalent of tetris.html
if i'm an idiot, let me know, if you can help, also please let me know
thanks
joel
gwarble@hotmail.com
www.arcadefanatic.com
------------------------------
Date: Wed, 2 Oct 2002 12:19:27 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: script.pl?parameter - can anyone help me figure this out?
Message-Id: <3d9b46bf$1@news.microsoft.com>
gwarble wrote:
> i'm new to perl programming, mostly doing it for fun and practice on
> my website... and i want to ask something... i've searched high and
> low on the internet and in books on how to pass a parameter to a perl
> script like this: script.pl?parameter in the url... i've seen it done
> but i cant find how to read the parameter in the code
Actually all shells I know of are using a space instead of a question mark
to separate the command name from parameters.
So call your script as
script.pl myparameter
and you can access the value "myparameter" in the variable $ARGV[0].
jue
------------------------------
Date: Wed, 02 Oct 2002 19:39:33 GMT
From: "Dennis M. Parrott" <dparrott@twmi.rr.com>
Subject: Re: script.pl?parameter - can anyone help me figure this out?
Message-Id: <VXHm9.31908$kF.3628303@twister.columbus.rr.com>
if you are coding CGI scripts and are not using Lincoln Stein's
very nifty CGI.pm module you should. i would also recommend
his book on the subject as well ("Official Guild to Programming
with CGI.pm", pub. by Wiley)...
that is what you need to be doing to handle input to a CGI script.
dennis
gwarble <gwarble@moonman.com> wrote in message
news:47b16626.0210021054.49bfdd70@posting.google.com...
> hey all
>
> i'm new to perl programming, mostly doing it for fun and practice on
> my website... and i want to ask something... i've searched high and
> low on the internet and in books on how to pass a parameter to a perl
> script like this: script.pl?parameter in the url... i've seen it done
> but i cant find how to read the parameter in the code
>
> if you see my page (www.arcadefanatic.com) it might make more sense...
> i have seperate html files for each game in my collection, and want to
> make a game.pl script which will set up the basic layout that is the
> same for each game, and then pass ?tetris for example so it
> dynamically loads the equivalent of tetris.html
>
> if i'm an idiot, let me know, if you can help, also please let me know
>
> thanks
> joel
> gwarble@hotmail.com
> www.arcadefanatic.com
------------------------------
Date: Wed, 02 Oct 2002 21:32:47 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: simple grep Q
Message-Id: <3CJm9.12605$PP.13258@rwcrnsc53>
In the following code & output why do the two 3 digit numbers pass the grep
filter but if I remove the [ ] then only the 6 digit numbers pass out of
grep? I understand the 2nd output, but NOT the first.
_______code#1
use strict;
use warnings;
use Data::Dumper;
my @lines = (
'SPH 083000 111200 111300 111100 111280 503 959',
'SPH 084000 111250 111380 111200 111370 354 115',
'SPH 084500 111350 111390 111050 111100 353 747' );
my $text = $lines[0];
my @numbers= grep { [ s/(\d{4})(\d{2})/$1\.$2/g ] } $text =~ /\d+/g;
print Dumper @numbers;
________output #1
$VAR1 = '0830.00';
$VAR2 = '1112.00';
$VAR3 = '1113.00';
$VAR4 = '1111.00';
$VAR5 = '1112.80';
$VAR6 = '503';
$VAR7 = '959';
__________code#2 remove only [ ]
my @numbers= grep { s/(\d{4})(\d{2})/$1\.$2/g ]} $text =~ /\d+/g;
__________output #2
$VAR1 = '0830.00';
$VAR2 = '1112.00';
$VAR3 = '1113.00';
$VAR4 = '1111.00';
$VAR5 = '1112.80';
Thanks a lot.
--
Dick Penny
------------------------------
Date: Wed, 02 Oct 2002 19:23:06 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Sort hash of hash
Message-Id: <3d9b38fe$0$11471$afc38c87@auth.de.news.easynet.net>
Smileface wrote at Wed, 02 Oct 2002 17:26:10 +0200:
> How can I sort an Hash of Hash by the final values?
>
> The hash is like this:
>
> %HoH= (
> 'GGG' => { 'd' => 5 },
> 'AAA' => { 'a' => 8 },
> 'ZZZ' => { 'c' => 7 },
> 'DDD' => { 'b' => 6 },
> 'FFF' => { 'e' => 9 }
> );
>
> Thanks in advance,
As Juergen already said, it's hard in the general case.
If your data looks exactly like the above,
you could try something:
my @sorted_keys =
sort {(values %{$HoH{$a}})[0] <=> (values %{$HoH{$b}})[0]} keys %HoH;
But it looks more like a mischoosen datastructure.
Perhaps a hash of arrays is more appropriate ?
my %data = (
GGG => [d => 5],
AAA => [a => 8],
ZZZ => [c => 7],
DDD => [b => 6],
FFF => [e => 9],
);
where you would have an easier sorting of the key with
sort {$data{$a}->[1] <=> $data{$a}->[1]} keys %data;
Please read also perldoc -q sort,
especially for the Schwartzian Transformation.
Greetings,
Janek
------------------------------
Date: Wed, 02 Oct 2002 19:49:05 -0000
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: Sort hash of hash
Message-Id: <Xns929BA0E8C4CB2dkwwashere@216.168.3.30>
Smileface <smileface@libero.it> wrote on 02 Oct 2002:
> Hi,
> How can I sort an Hash of Hash by the final values?
>
> The hash is like this:
>
> %HoH= (
> 'GGG' => { 'd' => 5 },
> 'AAA' => { 'a' => 8 },
> 'ZZZ' => { 'c' => 7 },
> 'DDD' => { 'b' => 6 },
> 'FFF' => { 'e' => 9 }
> );
I don't know, but I can turn it into something that I *can* sort:
use strict;
use warnings;
my %HoH = (
'GGG' => { 'd' => 5 },
'AAA' => { 'a' => 8 },
'ZZZ' => { 'c' => 7 },
'DDD' => { 'b' => 6 },
'FFF' => { 'e' => 9 }
);
my @data;
for my $key1 ( keys %HoH ) {
for my $key2 ( keys %{ $HoH{$key1} } ) {
push @data, [ $key1, $key2, $HoH{$key1}{$key2} ];
}
}
foreach my $el ( sort { $a->[2] <=> $b->[2] } @data ) {
print join(' ', @$el), "\n";
}
I'm sure there's a better way to do this, but I don't know what to say
without knowing more about your real purpose. If your chosen data
structure makes things difficult, maybe you should choose a different data
structure?
--
David K. Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Wed, 02 Oct 2002 20:57:53 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Sort hash of hash
Message-Id: <2tmmpuc3ui7lsjgdp7a9q6gmrrnbsruplg@4ax.com>
Smileface wrote:
>How can I sort an Hash of Hash by the final values?
>
>The hash is like this:
>
> %HoH= (
> 'GGG' => { 'd' => 5 },
> 'AAA' => { 'a' => 8 },
> 'ZZZ' => { 'c' => 7 },
> 'DDD' => { 'b' => 6 },
> 'FFF' => { 'e' => 9 }
> );
What final values? The "a", "b", "c"... or the 5, 8, 9...?
I think you have a special hash here, with only one hash entry in the
subhashes. Why you don't have a two element anonymous array, I don't
know. But I digress.
I'd make a shadow of the original hash, assigning the key or value of
the subhash to the value of the shadow hash, so you get
%shadow = (
'GGG' => 'd',
'AAA' => 'a',
'ZZZ' => 'c',
'DDD' => 'b',
'FFF' => 'e'
);
or
%shadow = (
'GGG' => 5,
'AAA' => 8,
'ZZZ' => 7,
'DDD' => 6,
'FFF' => 9
);
And then you'd just have to sort according to these shadow hash's
values:
@sorted_keys = sort { $shadow{$a} <=> $shadow{$b} } keys %HoH;
or
@sorted_keys = sort { $shadow{$a} cmp $shadow{$b} } keys %HoH;
So how do you get the shadow hash filled in the first place? Perhaps
like:
foreach (keys %HoH) {
($shadow{$_}) = keys %{$HoH{$_}};
}
or
foreach (keys %HoH) {
($shadow{$_}) = values %{$HoH{$_}};
}
--
Bart.
------------------------------
Date: Wed, 2 Oct 2002 13:07:36 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Sticky forms without CGI.pm?
Message-Id: <anfckv$cgc$1@slb7.atl.mindspring.net>
"Garry" <none@none.com> wrote in message
news:andh46$nb0$1@newsg2.svr.pol.co.uk...
> I loathe writing second-hand HMTL with CGI.pm but I need the sticky form
> feature.
So why would you want to write second-hand HTML with just Perl? What is it
about CGI.pm that makes the task loathsome? Why would you love to use Perl
to write first-hand (whatever that would be) HTML tags? Why not just use
hand-coded HTML and not use Perl at all?
>Any ideas how to do it without CGI.pm?
Yes; but you won't find much encouragement in clpmisc.
OTOH, see any good reference on HTML for the minimum tags needed for an HTML
page.
>Do I need to access
> $REQUEST_URI or $QUERY_STRING? Parse this with regex's?
>
See the posting guidelines for clpmisc. You should use the resources
available to you,
e.g., FAQs, docs) to find the answers to these questions before posting
here.
After your research into your questions, if you're still insistent on
"rolling your own", rather than using CGI.pm, you might try rolling a Perl
script without CGI.pm
that does the following for generating HTML for text fields:
1. No form fields initially defined in the script.
2. Form fields initialized/modified via the query string, but uses POST for
its
(default) submit method.
3. Additional fields can be added via query string without rewriting the
script.
4. Has sticky form feature you desire.
The above requirements can be met with a five-line script. If you don't like
the HTML it generates,
you can always hand-tweak the HTML.
#!perl -w
# testform.pl - can be initialized and modified via query string,
# e.g., http://localhost/cgi-bin/testform.pl?Name=;Street+Address=;City=
use strict;
use CGI qw(-no_xhtml :standard);
print header, start_html, hr, start_form;
foreach (param()) {print p($_, textfield($_, param($_)))}
print submit, end_form, hr, end_html;
Cheers.
Bill Segraves
------------------------------
Date: Wed, 02 Oct 2002 19:22:56 +0200
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: String substitution of 3+ digit numbers only?
Message-Id: <3d9b38f4$0$11471$afc38c87@auth.de.news.easynet.net>
Stan Ng wrote at Wed, 02 Oct 2002 14:49:41 +0200:
> I need to do a string replacement for numbers with 3 or more digits:
>
> "Message 345245: Please give 27 dollars to Alice345 at 12:20"
>
> to become
>
> "Message 3 4 5 2 4 5: Please give 27 dollars to Alice 3 4 5 at 12:20"
>
> That is, numbers more than 2 digits long are blasted apart, but 2-digit
> numbers are kept intact.
>
> I need to do this in a single regexp substitution like
>
> str =~ s/{regexp1}/{regexp2}/g;
>
> or perhaps several substutions. What can I use as regexp1 and regexp2 to
> get this to happen?
Here's yet another solution that has the advantage of being
shorter than the other two ones :-)
s/(\d{3,})/$_=$1;s#(?=.)# #g;$_/ge;
It also has the disadvantage of being very cryptic and
to overwrite the global variable $_.
Greetings,
Janek
------------------------------
Date: Thu, 3 Oct 2002 07:09:36 +1000
From: "Tom Beer" <tom.beer@btfinancialgroup.spamfilter.com>
Subject: Re: Top posting (was Re: How can I count files in a directory?)
Message-Id: <anfnag$b7s$1@merki.connect.com.au>
>>>Rubber Duck <rubberducky703@hotmail.com> wrote:
>>>> Top Post????
>
>>Tad McClellan wrote in message ...
>>> http://www.tuxedo.org/~esr/jargon/html/entry/top-post.html
>>> http://www.geocities.com/nnqweb/nquote.html
>>> http://mail.augustmail.com/~tadmc/clpmisc.shtml
>
>On Wed, 2 Oct 2002 09:32:08 +1000, "Tom Beer"
><tom.beer@btfinancialgroup.spamfilter.com> wrote:
>>It's a joke, Joyce!
>
Helgi Briem wrote in message <3d9ae723.2001977291@news.cis.dfn.de>...
>If so, it's a joke that could, and probably has, landed
>you in a couple of hundred killfiles.
Me, or Rubber Duck (or both)?.
I didn't realise my post would give offence - if it has I am very sorry.
I won't do it again.
Tom.
PS. I dislike top-posting too. Please note that both my replies have been
bottom-posted.
------------------------------
Date: Thu, 3 Oct 2002 07:04:24 +1000
From: "Tom Beer" <tom.beer@btfinancialgroup.spamfilter.com>
Subject: Re: Unable to trap error from child
Message-Id: <anfn0p$b16$1@merki.connect.com.au>
news@roaima.freeserve.co.uk wrote in message
<62eena.1f8.ln@moldev.cmagroup.co.uk>...
>Tom Beer <tom.beer@btfinancialgroup.spamfilter.com> wrote:
>> My script forks a number of children, then waits for them to complete.
>
>There's a lot of well written code "out there" that alread does this. Take
>a look at perldoc perlipc for starters.
>
>> The problem I am experiencing is that the error code returned after
>> my wait call ($?) does not match the value I use in the exit statement
>> for my child process. eg. if I use
>
>> exit 256;
>
>You can't do that. Exit can only take an 8-bit value (i.e. 0..255). Larger
>values wrap round, and since 256 & 0xff == 0, your child is effectively
>exiting with status 0.
>
Chris,
Thanks very much for your helpful reply. I read that in the doco, but I
didn't understand it. Now I do.
Thanks again,
Tom.
------------------------------
Date: 02 Oct 2002 18:22:09 GMT
From: ctcgag@hotmail.com
Subject: Re: Why are the columns of a MySQL SELECT scrambled?
Message-Id: <20021002142209.708$Qq@newsreader.com>
caligari2k@yahoo.com (James) wrote:
> I want to thank everyone who responded. The unordered hash is
> obviously the problem I am having. A few of the suggestions gave me
> ideas, especially the multiple arrays. Which isn't a bad idea
> considering what I am wanting to ultimately do. Again, the key was to
> write code that isn't aware of the column names so that it can be more
> generic (ie reusable with little modification).
Uh, I think that that is backwards. The key is to write code that isn't
aware of column ordering, but just names, so that it can be more generic.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
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 3904
***************************************