[8765] in Perl-Users-Digest
Perl-Users Digest, Issue: 2381 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 22 13:27:24 1998
Date: Wed, 22 Apr 98 10:14:00 -0700
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, 22 Apr 1998 Volume: 8 Number: 2381
Today's topics:
Re: foreach loop & current element index (Petr Prikryl)
foreach trouble <p-fein@uchicago.edu>
Re: foreach trouble <lr@hpl.hp.com>
Re: foreach trouble <tchrist@mox.perl.com>
Re: foreach trouble <johnnie@holly.colostate.edu>
GCC and Solaris can't handle dynamic load ? <lavoie@zeus.genie.uottawa.ca>
Re: GCC and Solaris can't handle dynamic load ? <zkessin@lhr-sys.dhl.com>
Re: Get day out of 19/04/1998 13:24:41 <rdschramm@earthlink.net>
getpwnam question <kquinn@sk.sympatico.ca>
Re: getpwnam question (Michael Fuhr)
Re: getpwnam question (M.J.T. Guy)
Re: getpwnam question (Martien Verbruggen)
Re: Getting rid of the DOS console window when running <kairys@mi.sl.com>
help getting submit button action <bwsd@bwsd.com>
re: help getting submit button action <bwsd@bwsd.com>
Re: help getting submit button action <sowmaster@juicepigs.com>
Re: help getting submit button action jesten@wdynamic.com
Re: help getting submit button action (Abigail)
help on some cgi stuff (Aaron Drake)
Re: help on some cgi stuff <beske@worldnet.att.net>
Re: help on some cgi stuff (Martien Verbruggen)
Help sorting nested hashes by value <lyanddon@peapod.com>
Re: Help sorting nested hashes by value (Andre L.)
Re: Help sorting nested hashes by value <rjk@coos.dartmouth.edu>
Re: Help with regular expression (Abigail)
Re: HELP!!! fork, exec, etc. (Mark-Jason Dominus)
Re: Help! johnnie@NOPERSONALMAIL.edu
Re: Help, I'm going Perl-bald! <sowmaster@juicepigs.com>
Re: Hide or Encrypt perl source code (Stuart McDow)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Apr 1998 16:43:23 GMT
From: prikryl@dcse.fee.vutbr.cz (Petr Prikryl)
Subject: Re: foreach loop & current element index
Message-Id: <6hftvb$e95$1@boco.fee.vutbr.cz>
Jeff Pinyan (jefpin@bergen.org) wrote:
[...]
>>The question was: "When in a foreach loop, is there a special variable
>>or perl function that can be used to determine the index of the current
>>array element?"
[...]
>Currently, there are _no more_ puncuation variables left... they've all
>been used up (from $` to $?). So currently, it can't be done. However,
>certain variables are deprecated in perl5 -- $* for example -- and so, it
>may be possible in perl5.005 to do what you ask.
I would expect some smiley symbol after such remark. '$*' may be deprecated,
but it is not forbiden -- older scripts maybe use it. Perl 5.005 should
still be Perl 5. I would not be surprised if something like this was done
by Microsoft, because they do prefer money even in cases when their products
loose the backward compatibility in the next version. But Perl is a
serious product ;-)
Petr
--
Petr Prikryl (prikryl@dcse.fee.vutbr.cz) http://www.fee.vutbr.cz/~prikryl/
TU of Brno, Dept. of Computer Sci. & Engineering; tel. +420-(0)5-7275 218
------------------------------
Date: Tue, 21 Apr 1998 23:06:07 GMT
From: Peter A Fein <p-fein@uchicago.edu>
Subject: foreach trouble
Message-Id: <8767k2ojvk.fsf@bj2-64.rh.uchicago.edu>
I'm having a bit of difficulty with the following foreach loop:
print STDERR "1 val ", $self->{section_order}, " type ", ref($self->{section_order}), "\n";
foreach my $i ($self->{section_order}) {
print STDERR "2 val ", $i, " type ", ref($i), "\n";
do more stuff, using $i as a hash key;}
it outputs:
1 val ARRAY(0x80c768c) type ARRAY
2 val ARRAY(0x80c768c) type ARRAY
and then moves on.
Now, my intent, and understanding of that should be happening here, is
that $i takes each of the values in $self->{section_order} in turn.
This should mean that ref($i) should return SCALAR, and $i should have
a string. Not what's going on. Why isn't foreach seeing
$self->{section_order} as an array?
This is one of my first scripts & consultation with the Camel Book
hasn't resulted in any answers. Help is appreciated.
--
Peter Fein
1005 E. 60th St.
Chicago, IL 60637
773-834-6206
p-fein@uchicago.edu
http://pfein.home.ml.org/
------------------------------
Date: Tue, 21 Apr 1998 16:33:52 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: foreach trouble
Message-Id: <6hjad9$fk6@hplntx.hpl.hp.com>
Peter A Fein wrote in message <8767k2ojvk.fsf@bj2-64.rh.uchicago.edu>...
>
>I'm having a bit of difficulty with the following foreach loop:
>
> print STDERR "1 val ", $self->{section_order}, " type ",
ref($self->{section_order}), "\n";
> foreach my $i ($self->{section_order}) {
> print STDERR "2 val ", $i, " type ", ref($i), "\n";
foreach my $i (@{$self->{section_order}}) {
You need to loop over the array referenced, and the extra brackets are
needed to make it bind properly.
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 21 Apr 1998 23:25:03 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: foreach trouble
Message-Id: <6hj9sf$2df$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Peter A Fein <p-fein@uchicago.edu> writes:
:Now, my intent, and understanding of that should be happening here, is
:that $i takes each of the values in $self->{section_order} in turn.
No, when you write
foreach $i ( 37 ) { }
What you you expect to happen? It loops once, with $i == 37.
Now look at this:
@array = ( 1 .. 10 );
$ref = \@array;
foreach $i ( $ref ) { }
How many times do you imagine that loop will run? Just once, of course,
because the list passed to foreach has just one value! Perl nearly
never does implicit dereferencing.
You mean something more like
foreach $i ( @$ref ) { }
Or more likely in your case:
foreach $item ( @{ $self->{section_order} } ) {
# do something with $item
}
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"If it makes goo on the windshield, we'll call it a bug." --Larry Wall
------------------------------
Date: Tue, 21 Apr 1998 20:29:24 -0600
From: John Blanco <johnnie@holly.colostate.edu>
Subject: Re: foreach trouble
Message-Id: <353D5603.117D4A4C@holly.colostate.edu>
Tom Christiansen wrote:
> How many times do you imagine that loop will run? Just once, of
> course,
> because the list passed to foreach has just one value! Perl nearly
> never does implicit dereferencing.
>
> foreach $item ( @{ $self->{section_order} } ) {
> # do something with $item
Well why didn't you put it in the book in the first place, Tom?? ;)
Hey, I was proud that I actually figured that one before peeking at the
answer! I'm learning OOP! ;)
- Johnnie B
------------------------------
Date: 20 Apr 1998 19:53:35 -0400
From: Philippe Lavoie <lavoie@zeus.genie.uottawa.ca>
Subject: GCC and Solaris can't handle dynamic load ?
Message-Id: <y6wwck6oe8.fsf@zeus.genie.uottawa.ca>
Hi,
I'm wondering why gcc can't handle dynamic loading with perl 5.004_4.
It fails the make test with a missing main() symbol (pretty odd for a
dynamic load).
It works fine with cc so I was able to compile properly. Still, it be
nice to know how to make it work.
My system, SOlaris 2.5.1, gcc 2.7.2.3 on ultra 1.
Phil
PS An e-mail copy would be appreciated.
------------------------------
Date: 21 Apr 1998 08:23:48 +0100
From: Zachary Kessin <zkessin@lhr-sys.dhl.com>
Subject: Re: GCC and Solaris can't handle dynamic load ?
Message-Id: <uson7ab97.fsf@lhr-sys.dhl.com>
Philippe Lavoie <lavoie@zeus.genie.uottawa.ca> writes:
> Hi,
>
> I'm wondering why gcc can't handle dynamic loading with perl 5.004_4.
>
> It fails the make test with a missing main() symbol (pretty odd for a
> dynamic load).
I have had the exact same problem under hp-ux 10.20, using gcc 2.7 and
2.8.
--Zach Kessin
------------------------------
Date: Sun, 19 Apr 1998 11:57:48 -0400
From: <rdschramm@earthlink.net>
Subject: Re: Get day out of 19/04/1998 13:24:41
Message-Id: <6hd71g$3e5@argentina.earthlink.net>
In perl 5, use the Time::Local function to convert 19/04/1998 00:00:00 into
a "time" value, meaning the number of seconds since the epoch. Then, put
that into the localtime function. That function will return a list, of
which one element is the day of the week (0 to 6).
>but i want to know how i can get the day of a
>function who return time like 19/04/1998 13:24:41. How can I get the
>info it is sunday?????
------------------------------
Date: Sun, 19 Apr 1998 22:46:23 -0600
From: Ken Quinn <kquinn@sk.sympatico.ca>
Subject: getpwnam question
Message-Id: <353AD31F.7C84AC91@sk.sympatico.ca>
Hi, I'm trying to use getpwnam, the following works;
$username = "bill" ;
@pwdlist = getpwnam($username) ;
print @pwdlist ;
#so does;
$username = "bill" ;
$username = $a
@pwdlist = getpwnam($a) ;
print @pwdlist ;
#when I pipe a username like;
$username = <> ;
print $username ;
#no problem, but when I pipe it to getpwnam ;
$username = <> ;
$username = $a
@pwdlist = getpwnam($a);
print @pwdlist ;
It dosen't work. I know this may be rather simple but I am having
trouble so I would greatly appreciate any help.
Thanks Ken
I'm trying to pipe a username to a filter which uses getpwnam.
------------------------------
Date: Mon, 20 Apr 1998 05:15:16 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: getpwnam question
Message-Id: <6hell2$8em@flatland.dimensional.com>
Ken Quinn <kquinn@sk.sympatico.ca> writes:
> Hi, I'm trying to use getpwnam, the following works;
>
> $username = "bill" ;
> @pwdlist = getpwnam($username) ;
> print @pwdlist ;
> #so does;
> $username = "bill" ;
> $username = $a
> @pwdlist = getpwnam($a) ;
> print @pwdlist ;
Where is $a coming from? You don't say, so I'll assume it's set
to a user's name elsewhere.
> #when I pipe a username like;
> $username = <> ;
> print $username ;
> #no problem, but when I pipe it to getpwnam ;
> $username = <> ;
> $username = $a
> @pwdlist = getpwnam($a);
> print @pwdlist ;
Again, I don't see where $a is set. It would be best to give complete
examples instead of leaving things for us to guess.
> It dosen't work. I know this may be rather simple but I am having
> trouble so I would greatly appreciate any help.
Try running this example, which is what I think you're trying to do:
#!/usr/local/bin/perl -w
$username = <>;
print "-->$username<--\n";
@pwdlist = getpwnam($username);
print "@pwdlist\n";
This will probably fail, even if you give it a valid user name.
The output from the first print statement should show you why.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 20 Apr 1998 15:21:30 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: getpwnam question
Message-Id: <6hfp5q$q3r$1@lyra.csx.cam.ac.uk>
Ken Quinn <kquinn@sk.sympatico.ca> wrote:
>Hi, I'm trying to use getpwnam, the following works;
>
>$username = "bill" ;
>@pwdlist = getpwnam($username) ;
>print @pwdlist ;
>#so does;
>$username = "bill" ;
>$username = $a
>@pwdlist = getpwnam($a) ;
>print @pwdlist ;
>#when I pipe a username like;
>$username = <> ;
>print $username ;
>#no problem, but when I pipe it to getpwnam ;
>$username = <> ;
>$username = $a
>@pwdlist = getpwnam($a);
Do you mean those last two lines? I'll assume you actually tried
@pwdlist = getpwnam($username);
which makes slightly more sense.
>print @pwdlist ;
>
>It dosen't work. I know this may be rather simple but I am having
>trouble so I would greatly appreciate any help.
I suspect that your problem is a "\n" on the end of the line you have
read. Do a chomp($username); to clean it up.
Mike Guy
------------------------------
Date: 21 Apr 1998 06:40:55 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: getpwnam question
Message-Id: <6hhf1n$rcm$1@comdyn.comdyn.com.au>
In article <353AD31F.7C84AC91@sk.sympatico.ca>,
Ken Quinn <kquinn@sk.sympatico.ca> writes:
> Hi, I'm trying to use getpwnam, the following works;
>
> $username = "bill" ;
> @pwdlist = getpwnam($username) ;
> print @pwdlist ;
> #so does;
> $username = "bill" ;
> $username = $a
> @pwdlist = getpwnam($a) ;
> print @pwdlist ;
This shouldn't work, unless you have set $a somewhere else.
This is not the real code, hmm? Maybe you meant
$a = $username?
> #when I pipe a username like;
pipe? You mean something like:
# echo "joe_blogg" | my_script
or
# my_script < user_list
?? I find your terminology a bit confusing.
> $username = <> ;
This might not always do what you think. Did you mean to use <STDIN>?
> print $username ;
> #no problem, but when I pipe it to getpwnam ;
> $username = <> ;
Do you know how the <> operator works? have you thought about what
you're doing here? Have you checked the contents of $username? Have
you read the perlop documentation? You do know that using <> will
try to read input from files specified on the command line, right?
quote from perlop:
Here's how it works: the first time <> is evaluated,
the @ARGV array is checked, and if it is null, $ARGV[0] is
set to "-", which when opened gives you standard input.
The @ARGV array is then processed as a list of filenames.
> $username = $a
ditto as above. You probably have these the wrong way around, and it's a
useless statement.
> @pwdlist = getpwnam($a);
> print @pwdlist ;
>
> It dosen't work.
That doesn't surprise me.
Read the man pages for
# perldoc perlop
Look for the <> operator
# perldoc -f chomp
A starting point for you might be something like:
#!/usr/local/bin/perl -w
use strict;
# get all the lines in a list
my @users = <STDIN>;
foreach my $username (@users)
{
# get rid of the trailing newlines
chomp $username;
# treat the line as a username. BEWARE: this could use some tests
my @pwdlist = getpwnam($username);
print @pwdlist, "\n";
}
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Tue, 21 Apr 1998 09:02:42 -0400
From: "Michael Kairys" <kairys@mi.sl.com>
Subject: Re: Getting rid of the DOS console window when running a Perl program
Message-Id: <353ca528.0@news.ic.net>
>I am running Perl 5.004_04 on WinNT/Win95 and I need to run a Perl Program
>with no DOS Console window popping up - how can I do this???
Look in comp.lang-perl.tk. There are quite a few posts on this topic.
------------------------------
Date: Sun, 19 Apr 1998 12:29:47 -0500
From: Beck Web Servers & Design <bwsd@bwsd.com>
Subject: help getting submit button action
Message-Id: <353A267B.A19DDFEC@bwsd.com>
Hi:
I've got a script that I'm working on, that is doing a sub
print_order_html, let's say, where I want the submit button to be going
to a next step in the script action, based on the value of the NAME of
the <input> tag
example:
<INPUT METHOD="POST" ACTION="check.cgi" NAME="Order" VALUE"Order
Product">
I want the script now to pick up that the NAME="Order" and then display
my next part. I'm stuck here...I've searched through a lot of stuff,
and examples from other scripts, but I can't quite figure out how to do
it, since I'm no expert programmer (hack is more like it).
So I need some help figuring out the "if" part here the following
routine -- setting up the proper variables, etc.
if (the <input> tag's name is such and such) #I need help with this
{
do this or that; #I can do this
}
Please respond via personal email...appreciated.
Thanks,
Eric mailto:erbeck@web-design.net
------------------------------
Date: Sun, 19 Apr 1998 13:00:46 -0500
From: Beck Web Servers & Design <bwsd@bwsd.com>
Subject: re: help getting submit button action
Message-Id: <353A2DBD.67EA6DE9@bwsd.com>
oops....what I mean in the example is:
<INPUT TYPE="SUBMIT" NAME="Order" VALUE="Order Product">
I'm trying to capture the NAME field "Order" to process the next step
Thanks,
Eric mailto:erbeck@web-design.net
------------------------------
Date: Sun, 19 Apr 1998 13:27:38 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: bwsd@bwsd.com
Subject: Re: help getting submit button action
Message-Id: <353A340A.7053@juicepigs.com>
Beck Web Servers & Design wrote:
>
> oops....what I mean in the example is:
>
> <INPUT TYPE="SUBMIT" NAME="Order" VALUE="Order Product">
>
> I'm trying to capture the NAME field "Order" to process the next step
It's just another value pair.
#!/usr/local/bin/perl
use CGI;
CGI::ReadParse();
if ($in{'Order'}) {
process_next_step;
}
HTH
--
Bob Trieger | Titanic: big boat, bigger
sowmaster@juicepigs.com | iceberg, big deal
------------------------------
Date: Sun, 19 Apr 1998 15:56:00 -0600
From: jesten@wdynamic.com
Subject: Re: help getting submit button action
Message-Id: <6hdod0$qpr$1@nnrp1.dejanews.com>
In article <353A267B.A19DDFEC@bwsd.com>,
bwsd@bwsd.com wrote:
>
> Hi:
>
> I've got a script that I'm working on, that is doing a sub
> print_order_html, let's say, where I want the submit button to be going
> to a next step in the script action, based on the value of the NAME of
> the <input> tag
>
> example:
>
> <INPUT METHOD="POST" ACTION="check.cgi" NAME="Order" VALUE"Order
> Product">
>
> I want the script now to pick up that the NAME="Order" and then display
> my next part. I'm stuck here...I've searched through a lot of stuff,
> and examples from other scripts, but I can't quite figure out how to do
> it, since I'm no expert programmer (hack is more like it).
>
> So I need some help figuring out the "if" part here the following
> routine -- setting up the proper variables, etc.
>
> if (the <input> tag's name is such and such) #I need help with this
> {
Here's a quickie I use frequently...
&parse;
if (defined($FORM{'action'})) {
$command = $FORM{'action'};
} else {
$command = $ENV{'QUERY_STRING'};
}
&$command;
... where &parse is the standard parsing routine that drops everything into
the %FORM array, making $command have the name of the sub I want to execute.
Jim
Jim Esten, Lead Developer, WebDynamic
http://www.wdynamic.com
ICQ: 5943404
In the beginning was the word, and the word was...adjust!
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 20 Apr 1998 15:02:11 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: help getting submit button action
Message-Id: <6hfo1j$dm0$4@client2.news.psi.net>
Beck Web Servers & Design (bwsd@bwsd.com) wrote on MDCXCII September
MCMXCIII in <URL: news:353A267B.A19DDFEC@bwsd.com>:
++ Hi:
++
++ I've got a script that I'm working on, that is doing a sub
++ print_order_html, let's say, where I want the submit button to be going
++ to a next step in the script action, based on the value of the NAME of
++ the <input> tag
++
++ example:
++
++ <INPUT METHOD="POST" ACTION="check.cgi" NAME="Order" VALUE"Order
++ Product">
That is incorrect HTML.
++ I want the script now to pick up that the NAME="Order" and then display
++ my next part. I'm stuck here...I've searched through a lot of stuff,
++ and examples from other scripts, but I can't quite figure out how to do
++ it, since I'm no expert programmer (hack is more like it).
Use CGI.pm and read its manual.
++ Please respond via personal email...appreciated.
Private consulting is $150/h.
Abigail
--
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
------------------------------
Date: Mon, 20 Apr 1998 13:39:07 -0500
From: aarond@cutco.com (Aaron Drake)
Subject: help on some cgi stuff
Message-Id: <aarond-2004981339070001@207.127.137.12>
I have a cgi script that takes the info from a form (2 fields) and writes
that to a text file. Then the script has to either look at the 1st or 7th
spot of the 2nd field and redirect based on what character is there.
There are only 7 possible places they would be redirected to. I know
almost no perl at the moment, but I do have some C/C++ experience. If
someone could tell me how to make it check the specific spots in the 2nd
field it would be much appreciated.
Thanks,
Aaron
------------------------------
Date: Mon, 20 Apr 1998 14:36:53 -0400
From: Bryan Beske <beske@worldnet.att.net>
Subject: Re: help on some cgi stuff
Message-Id: <6hg4le$c1o@bgtnsc03.worldnet.att.net>
> almost no perl at the moment, but I do have some C/C++ experience. If
> someone could tell me how to make it check the specific spots in the 2nd
> field it would be much appreciated.
See page 227 of the camel book:
$first_char = substr( $in_string, 0,1 ); # Pull out the
first character of the string
$seventh_char = substr( $in_string, 6, 1 ); # Pull off the seventh
character
b^2
------------------------------
Date: 20 Apr 1998 23:40:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: help on some cgi stuff
Message-Id: <6hgmd3$p4t$4@comdyn.comdyn.com.au>
In article <aarond-2004981339070001@207.127.137.12>,
aarond@cutco.com (Aaron Drake) writes:
> I have a cgi script that takes the info from a form (2 fields) and writes
I suppose you already are using CGI.pm to get to that information. If
not, I strongly suggest you start using it.
I will however assume that you have these two fields separated and
stored somewhere, in scalars.
> that to a text file. Then the script has to either look at the 1st or 7th
> spot of the 2nd field and redirect based on what character is there.
If by 1st and 7th 'spot', you mean character, have a look at the
substr function
# perldoc -f substr
$first = substr($field2, 0, 1);
$seventh = substr($field2, 6, 1);
> There are only 7 possible places they would be redirected to. I know
> almost no perl at the moment, but I do have some C/C++ experience. If
You are aware that there is no such thing as C/C++? The people in
comp.lang.c and in comp.lang.c++ would kill you for that contraction :)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Mon, 20 Apr 1998 20:26:19 -0400
From: "Don Silvia" <lyanddon@peapod.com>
Subject: Help sorting nested hashes by value
Message-Id: <6hgp2a$i3c$1@ligarius.ultra.net>
Hi,
I have data structure that consists of nested hashes, in which I need to
sort
keys based on the value of subkeys. The data structure looks something like
this:
%Data %Route %Point
----- ---------- ------- ------
$Data{'Route_21'}{'72586'}{'Type'} = "DMP8";
$Data{'Route_21'}{'72586'}{'Sta'} = "21856.3";
$Data{'Route_21'}{'72586'}{'Elev'} = "116.213";
$Data{'Route_21'}{'72586'}{'Rail'} = "L";
$Data{'Route_21'}{'72588'}{'Type'} = "DMP8";
$Data{'Route_21'}{'72588'}{'Sta'} = "21870.3";
$Data{'Route_21'}{'72588'}{'Elev'} = "116.113";
$Data{'Route_21'}{'72588'}{'Rail'} = "L";
$Data{'Route_19'}{'70351'}{'Type'} = "DMP6";
$Data{'Route_19'}{'70351'}{'Sta'} = "19871.3";
$Data{'Route_19'}{'70351'}{'Elev'} = "110.010";
$Data{'Route_19'}{'70351'}{'Rail'} = "R";
$Data{'Route_19'}{'70352'}{'Type'} = "DMP6";
$Data{'Route_19'}{'70352'}{'Sta'} = "19901.5";
$Data{'Route_19'}{'70352'}{'Elev'} = "111.635";
$Data{'Route_19'}{'70352'}{'Rail'} = "L";
...
What I need to do is to print a list of Points, sorted by the value of their
'Sta' keys. So I tried something like this: (I know this example doesn't
work)
# For each Route in %Data
foreach $Route ( keys %Data )
# For each Point on this Route, ordered by {'Point'}{'Sta'}
foreach $Point ( sort { keys %{$Data{$Route}{Sta}{$a}} <=> keys
%{$Data{$Route}{Sta}{$b}} }
keys %{$Data{$Route}} )
print OUTPUT_FILE ("\t$Point\n");
Now, I've read the FAQs and any documentation I could find relative to
sorting hashes, but I can't find any examples that help me. Can someone
please show me how this should be done, or point me to some relevant
examples?
Thanks,
--
Don Silvia
------------------------------
Date: Mon, 20 Apr 1998 23:47:30 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Help sorting nested hashes by value
Message-Id: <alecler-2004982347300001@dialup-29.hip.cam.org>
You were almost there!
foreach $route (keys %Data) {
foreach $point (
sort { $Data{$route}{$a}{'Sta'} <=> $Data{$route}{$b}{'Sta'} }
keys %{ $Data{$route} } ) {
# modify this line to suit your purpose:
print "Point $point : Sta $Data{$route}{$point}{'Sta'}\n";
}
}
HTH,
A.L.
========================
In article <6hgp2a$i3c$1@ligarius.ultra.net>, "Don Silvia"
<djsilvia@pop.ma.ultranet.com> wrote:
> Hi,
> I have data structure that consists of nested hashes, in which I need to
> sort
> keys based on the value of subkeys. The data structure looks something like
> this:
> %Data %Route %Point
> ----- ---------- ------- ------
> $Data{'Route_21'}{'72586'}{'Type'} = "DMP8";
> $Data{'Route_21'}{'72586'}{'Sta'} = "21856.3";
> $Data{'Route_21'}{'72586'}{'Elev'} = "116.213";
> $Data{'Route_21'}{'72586'}{'Rail'} = "L";
>
> $Data{'Route_21'}{'72588'}{'Type'} = "DMP8";
> $Data{'Route_21'}{'72588'}{'Sta'} = "21870.3";
> $Data{'Route_21'}{'72588'}{'Elev'} = "116.113";
> $Data{'Route_21'}{'72588'}{'Rail'} = "L";
>
> $Data{'Route_19'}{'70351'}{'Type'} = "DMP6";
> $Data{'Route_19'}{'70351'}{'Sta'} = "19871.3";
> $Data{'Route_19'}{'70351'}{'Elev'} = "110.010";
> $Data{'Route_19'}{'70351'}{'Rail'} = "R";
>
> $Data{'Route_19'}{'70352'}{'Type'} = "DMP6";
> $Data{'Route_19'}{'70352'}{'Sta'} = "19901.5";
> $Data{'Route_19'}{'70352'}{'Elev'} = "111.635";
> $Data{'Route_19'}{'70352'}{'Rail'} = "L";
> ...
>
> What I need to do is to print a list of Points, sorted by the value of their
> 'Sta' keys. So I tried something like this: (I know this example doesn't
> work)
>
> # For each Route in %Data
> foreach $Route ( keys %Data )
> # For each Point on this Route, ordered by {'Point'}{'Sta'}
> foreach $Point ( sort { keys %{$Data{$Route}{Sta}{$a}} <=> keys
> %{$Data{$Route}{Sta}{$b}} }
> keys %{$Data{$Route}} )
> print OUTPUT_FILE ("\t$Point\n");
>
> Now, I've read the FAQs and any documentation I could find relative to
> sorting hashes, but I can't find any examples that help me. Can someone
> please show me how this should be done, or point me to some relevant
> examples?
>
> Thanks,
> --
> Don Silvia
------------------------------
Date: Tue, 21 Apr 1998 00:23:03 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: Don Silvia <djsilvia@pop.ma.ultranet.com>
Subject: Re: Help sorting nested hashes by value
Message-Id: <353C1F29.38AA43E6@coos.dartmouth.edu>
[posted and mailed]
Don Silvia wrote:
>
> $Data{'Route_21'}{'72586'}{'Type'} = "DMP8";
> $Data{'Route_21'}{'72586'}{'Sta'} = "21856.3";
> $Data{'Route_21'}{'72586'}{'Elev'} = "116.213";
> $Data{'Route_21'}{'72586'}{'Rail'} = "L";
>
> foreach $Point ( sort { keys %{$Data{$Route}{Sta}{$a}} <=> keys
> %{$Data{$Route}{Sta}{$b}} }
> keys %{$Data{$Route}} )
First, your keys are in the wrong order in the sort subroutine:
$Data{$Route}{$a}{Sta} # not ...{Sta}{$a}
Second, you want to compare those values directly, not their non-existent
derefenced hashes.
So:
sort {$Data{$Route}{$a}{Sta} <=> $Data{$Route}{$b}{Sta}} keys %{$Data{$Route}}
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 20 Apr 1998 15:05:01 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Help with regular expression
Message-Id: <6hfo6t$dm0$5@client2.news.psi.net>
Mark Fergusson (mferg@hal.ddntl.didata.co.za) wrote on MDCXCIII September
MCMXCIII in <URL: news:353B1AA8.B5A30491@hal.ddntl.didata.co.za>:
++ Please can someone help me with the following:
++
++ $DATE="03/30/98"
++ $TIME="14:49:43"
++
++ How do I get:
++ $NEWDATE="1998-03-30 14:49:43"
if ($DATE eq '03/30/98' && $TIME eq '14:49:43') {
$NEWDATE = '1998-03-30 14:49:43';
}
Perhaps you want to be more general, but you don't say. You should
be more specific in your question. Did you check out the varous
Date:: and Time:: modules on CPAN?
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: 19 Apr 1998 20:16:50 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: HELP!!! fork, exec, etc.
Message-Id: <6he45i$bn5$1@monet.op.net>
Keywords: cytology pane riverfront wapato
In article <6h8eme$6l1@news1.panix.com>,
k y n n <NOSPAMkEynOn@panix.comNOSPAM> wrote:
>I could do something like:
>
> if(fork) {
> exec("xwsh -e rasmol");
> }
>
>but I don't know how to send commands to RasMol. ... Or
>alternatively to get a filehandle associated with the child's RasMol
>process to write to?
Heh. That's called a `pipe', kid.
What you should *really* do is get a book on Unix system programming
and read it. You can't learn everything you need from newsgroups. I
learned from `Advanced UNIX Programming' by Marc A. Rochkind, but that
was an old book even then, and there are probably better and more
recent books around. I think there's one by Rich Stevens that is
supposed to be good.
The short version of the answer follows. If you read carefully, you
may understand it. About half the code is `die', so don't be put off
by the apparent size.
pipe(READER, WRITER) || die "Couldn't create pipe: $!; aborting";
my $pid = fork;
if (! defined $pid) {
die "Couldn't fork: $!; aborting";
} elsif ($pid == 0) { # child
# Attach child's STDIN to the reading end of the pipe
close WRITER or die "Couldn't close writing end of pipe; $!; aborting";
open STDIN, "<& READER" or die ...
close READER or die ...
{ exec "xwsh", @ARGS }
die "Couldn't exec: #!; aborting";
}
# Parent
close READER;
print WRITER "Some command";
The `pipe' call creates a new pipe. The pipe has two file handles
associated with it. One is for writing data into the pipe, and one is
for reading data back out of the pipe.
Then you fork. Filehandles get copied when you fork, so the parent
and child now *each* have two handles, one for writing into the pipe
and one for reading from the pipe. The four filehandles all point to
the same pipe though.
The parent closes the reading handle because it'll be sending commands
to the child, not reading anything back. Then, when it wants to send
the child a message, it prints stuff to the writing handle.
The child does the opposite; it closes the writing handle. But then
it plays a trick: It connects STDIN to come from the pipe instead of
from wherever it was coming from before. In UNIX lingo, this is
called a `dup' operation. Now if the child reads from STDIN, it'll
actually get data out of the pipe. The child now has two handles
set up to the pipe: the original one that was dup'ed, and STDIN, so it
closes the original one. Then the child execs xwsh or whatever.
When this command tries to read STDIN, it'll get data from the pipe.
This is precisely what the shell does when it wasnt to redirect a
command's stdin to come from a pipe, by the way.
>I'd prefer "low-tech-verbose-but-instructive-perl" ones.)
Well, see, you don't have a Perl problem. You have an OS problem.
I dunno if pipes count as low-tech or high-tech, but it seems to me
like the most straightforward way to do what you want.
You might want to consider asking further questions about this in
comp.unix.programmer, or read the FAQ for that group.
We don't get enough unix system programming questions in here that
it's going to drive anyone crazy, I think, but it is off-topic.
------------------------------
Date: 21 Apr 1998 15:33:41 -0600
From: johnnie@NOPERSONALMAIL.edu
Subject: Re: Help!
Message-Id: <6hj3bl$7ruq@holly.ColoState.EDU>
Keith L. Miller <miller@bigsky.net> bravely wrote:
: open (IN, filename);
: while(<IN>){
: @fields = split(/:/, $_);
: if($fields[0] =~ /\0/){ # Attemp 1
: if(length($fields) < 1){ # Attemp 2
Attempt #1 is wrong because that \0, well, I don't know what it's
going to do! \0 may be giving you NULL, but I'm not sure. What you want
is ^\s*$ instead. (That checks for nothing but spaces)
Attempt #2 will never work cause $fields is not a variable yet.
I suspect you meant length($fields[0]). But that wouldn't work
because each space is a character and you'd only be checking for lines
of the form:
:la:dee:da
Go with:
: if($fields[0] =~ /^\s*$/){ # Attemp 1
: Also, here's an interesting note. If I print the length of the blank
: field, it always comes up 38 UNLESS the filed is longer than 38, then
: it comes out with the correct length.
: Any help would be VERY appreciated!
- Johnnie B
--
- Johnnie Blanco Jr.
- "Just can't sit. Gotta get jiggy wit it, mmm, that's it!"
- Will Smith [Gettin Jiggy Wit It]
------------------------------
Date: Sun, 19 Apr 1998 12:48:45 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: msbzdragn@hotmail.com
Subject: Re: Help, I'm going Perl-bald!
Message-Id: <353A2AED.405A@juicepigs.com>
msbzdragn@hotmail.com wrote:
>
> Heeeeeelllllppp!!!!!
>
> I'm going bald prematurely, and all because I've just become a newbie... ;) I
> just started playing around with Perl and CGI for a project I am trying to do
> at work, and I'm completely baffled...
>
> I've got a web server (Sambar, http://www.sambar.com) running on Windows NT
> Server 4.0, using the included Perl executables - and CGI works fine, so long
> as I use the included scripts. However, I haven't been able to get any of the
> scripts I've downloaded off the web (such as Webbbs and a few other similar
> message-board systems, downloaded from http://www.cgi-resources.com) to work.
>
> I don't get any error message, in fact I don't get anything at all on the
> scripts that I am trying to install - the browser just sits and eventually
> times out. Where am I going wrong?
This doesn't sound like your problem is with perl. You will probably be
able to get a lot more help in the cgi or server newsgroups.
news:comp.infosystems.www.authoring.cgi
news:comp.infosystems.www.servers.ms-windows
You may also want to look into IIS. The webserver that comes with
Windows NT server.
news:microsoft.public.inetserver.iis
HTH
--
Bob Trieger | Titanic: big boat, bigger
sowmaster@juicepigs.com | iceberg, big deal
------------------------------
Date: 16 Apr 1998 13:37:54 GMT
From: smcdow@arlut.utexas.edu (Stuart McDow)
Subject: Re: Hide or Encrypt perl source code
Message-Id: <6h51ji$ptf$1@ns1.arlut.utexas.edu>
"Grinch" <grinch@whoville.com> writes:
>
> the only way to run a Perl script on a Win32 machine would be to
> install the entire Perl-Win32 distribution.
Is this really such a bad thing? The core distribution (5.004_2)
without the man directory is only 10MB or so. I install this
configuration on any win32 machine that I encounter that doesn't
already have it. It reduces the pain somewhat.
--
Stuart McDow Applied Research Laboratories
smcdow@arlut.utexas.edu The University of Texas at Austin
"It is obvious that about 750,000 people ago, Austin was a wonderful City."
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2381
**************************************