[17926] in Perl-Users-Digest
Perl-Users Digest, Issue: 86 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 18 00:05:29 2001
Date: Wed, 17 Jan 2001 21:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979794309-v10-i86@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 17 Jan 2001 Volume: 10 Number: 86
Today's topics:
Re: Can't associate .PL files in Win98 <gracenews@optusnet.com.au>
Re: FAQ 8.8: How do I get the screen size? <nospam-abuse@[127.0.0.1]>
grouping by week mkarasick@my-deja.com
Re: grouping by week (Tad McClellan)
Re: How do you detect modem rings in Perl (if possible) (David Efflandt)
LWP Syntax help.... <cam@home.com>
Re: Mac Databases and MacPerl <gracenews@optusnet.com.au>
Re: Need script help - consolidation (Damian James)
Re: Newbie question: hash tables and dbm files; what am <nospam-abuse@[127.0.0.1]>
Re: No such a file or directory (Garry Williams)
perl N' windoze <sks@sierra.net>
Re: perl N' windoze <chrisw.NOSPAM@dynamite.com.au>
Re: perl N' windoze <ronnie@catlover.com>
Re: perlcc for Win NT <carvdawg@patriot.net>
Re: POD to powerpoint translator? (Chris Fedde)
Re: Random text script, got one?:-) <ronnie@catlover.com>
Re: Running a CGI as a USER (Damian James)
Re: Running setuid Perl scripts aksethi@my-deja.com
Re: Saving .htm file to disk from CGI script (Garry Williams)
Re: Saving .htm file to disk from CGI script (Tad McClellan)
Re: Sorting complex data structure (Marc Spitzer)
Re: Sorting complex data structure <artd@artd3.com>
Re: Sorting complex data structure <artd@artd3.com>
Re: Sorting complex data structure (Damian James)
Re: Sorting complex data structure eric_edlin@my-deja.com
Re: Syntax - Still need HELP <paanwa@hotmail.com>
Re: Syntax - Still need HELP <chrisw.NOSPAM@dynamite.com.au>
Using perl to update an ASP? <scorkery@my-deja.com>
Re: Using perl to update an ASP? <ronnie@catlover.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Jan 2001 13:28:44 +1000
From: "Jeffrey Grace" <gracenews@optusnet.com.au>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <3a666301$0$15476$7f31c96c@news01.syd.optusnet.com.au>
<dtbaker_dejanews@my-deja.com> wrote in message
news:93sh0u$ggt$1@nnrp1.deja.com...
> on a related note though, I have installed the same version of
> ActivePerl on two different PCs, and one of them I have the double-click
> working and it uses the dir the script is in as the current working dir,
> and on the other it uses the dir where perl.exe is?!
>
> if you figure THAT one out, let me know!
>
> Dan
This will depend on the properties/program/working setting, which controls
the working directory, either for the MS Dos prompt or for the perl.exe
itself.
--
Jeffrey Grace
~~~~~~~~~~~~~~~~~~~~
Queensland, Australia
------------------------------
Date: Wed, 17 Jan 2001 23:11:43 -0500
From: "James Kauzlarich" <nospam-abuse@[127.0.0.1]>
Subject: Re: FAQ 8.8: How do I get the screen size?
Message-Id: <r2u96.4333$d25.26458@newsfeed.slurp.net>
AvA <a.v.a@home.nl> wrote in message news:3A65D388.E2F4B5E9@home.nl...
> > I guess that what you are after is a script on a webserver somwhere on
> > The internet that can send a request to another ip adress and ask that
> > machine what size the webrowser is on the screen.
> >
> yes it is, silly of me to think a serverside script could do such a thing.
I don't know how silly it is to think that it might. Your browser gives the
server a lot of information, such as the OS, what kind of browser you have,
etc. It could easily inform the server of the hight and width of the brower
window in pixels. It just does not. (That I know of.)
But as Martin said, I believe that it takes something like Javascript do
what you want.
jmk
--
do NOT remove the nospam from the repy to address above,
instead send email to o1tech(at)skyenet(dot)net
JAPN 8_(
------------------------------
Date: Thu, 18 Jan 2001 02:13:29 GMT
From: mkarasick@my-deja.com
Subject: grouping by week
Message-Id: <945jg4$3q2$1@nnrp1.deja.com>
I need to do some processing/grouping of data that i will be reading in
from a log file. One field in the log file is DATE. I want to produce
a report that is broken down by week. Is there a neat way to do this?
Do I have to build a hash/array of all of the last days of the month in
order to do this?
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 03:39:34 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: grouping by week
Message-Id: <slrn96cija.3m5.tadmc@tadmc26.august.net>
mkarasick@my-deja.com <mkarasick@my-deja.com> wrote:
>I need to do some processing/grouping of data that i will be reading in
>from a log file. One field in the log file is DATE. I want to produce
>a report that is broken down by week. Is there a neat way to do this?
use Date::Calc qw/Week_Number/; # or perhaps one of it's other functions
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 18 Jan 2001 03:22:39 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: How do you detect modem rings in Perl (if possible)?
Message-Id: <slrn96cobc.li.efflandt@efflandt.xnet.com>
On Wed, 17 Jan 2001 16:06:43 +0100, Craig Manley <noemail@nospam.org> wrote:
>
>I need to write a simple program that must monitor a modem for incoming
>calls and execute another program when the modem rings - that's all. I
>have no modem so I'ld like to ask first if and how this can be done
>before I buy and install one.
>The target platform may be Linux or Windows.
>
>My guess is:
>Open the modem device for reading just as if it is a file.
>Read lines from the device and whenever the text "RING" is received an
>external program is executed.
Possibly Win32::SerialPort module for Windows, which has been ported as
Device::SerialPort for Linux (Unix). The module comes with sample scripts
that I think can be set up to work with either module depending upon OS.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 18 Jan 2001 04:54:00 GMT
From: "cam" <cam@home.com>
Subject: LWP Syntax help....
Message-Id: <IFu96.26938$ED.968285@news1.rdc1.bc.home.com>
Hi:
I'm looking for a simple dictionary of perl syntax for parsing URL's using
LWP:Simple;
I know how to get a URL, but can't find a guide to the syntax used to
grab/edit it's content.
For example, what is the syntax for looking for links etc.....
Thanks.
Cam
cam@home.com
------------------------------
Date: Thu, 18 Jan 2001 13:08:49 +1000
From: "Jeffrey Grace" <gracenews@optusnet.com.au>
Subject: Re: Mac Databases and MacPerl
Message-Id: <3a665f8c$0$15489$7f31c96c@news01.syd.optusnet.com.au>
<gungeek@my-deja.com> wrote in message news:93ihvr$fqn$1@nnrp1.deja.com...
> If you're not too worried about performance, what about DBD-CSV?
>
Or you could try DBD::Sprite, which is similar to DBD::CSV but implements
more database like functions such as multiple users, transactions, etc. At
the cost of lower speed, though I doubt you'll see much difference since
MacPERL only handles one request at a time anyway. And since it keeps the
script open for a while (in case theres another request, will close after a
certain idle period) and it won't have to be read off disk for each request,
you probably won't notice any difference at all, unless your traffic is
really low, and the script closes before the next request.
NB: I've described behaviour of MacPERL when I was using it 12 months ago, I
no longer develop on a mac, and there might have been a newer version that
acts differently, best to check the MacPERL web site to check.
--
Jeffrey Grace
~~~~~~~~~~~~~~~~~~~~
Queensland, Australia
------------------------------
Date: 18 Jan 2001 03:07:49 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Need script help - consolidation
Message-Id: <slrn96cnhk.88k.damian@puma.qimr.edu.au>
bigdawg posted the following to comp.lang.perl.misc
on Wed, 17 Jan 2001 23:24:54 GMT:
>The following is a perl script that I wrote that works, but would be better
>served using arrays. Help if you can please.
[long code listing smipped]
First, you should be working with these options:
#!/path/to/perl -w
use strict;
If you don't enable warnings you miss out on a great deal of useful
information that perl itself will provide you about your program. Many of
the variable names in your subroutines are actually undeclared globals.
This would have generated a compile time error had you been using 'strict'.
You could certainly clean up the namespace in your program by moving a
lot of these (file/package) global variables into some sort of data
structure. See the perldsc and perllol manpages.
You also have a lot of redundant code -- most of your subs are identical
(except that the variable names have been changed). You know you can build
a dispatch table for that?
Eg:
my %backups = (
item1 => [ "source_path1", "dest_path1", \&generic_backup_sub ],
item2 => [ "source_path2", "dest_path2", \&generic_backup_sub ],
etc
);
sub generic_backup_sub {
my ($source, $dest) = @_;
# code to copy $source to $dest
};
Which you could then just call with:
for (keys %backups) {
$backups{$_}->[2]->($backups{$_}->[0],$backups{$_}->[1]);
};
You would then just make different subs for the exceptional cases that you
can't make generic.
HTH,
Cheers,
Damian
------------------------------
Date: Wed, 17 Jan 2001 22:06:11 -0500
From: "James Kauzlarich" <nospam-abuse@[127.0.0.1]>
Subject: Re: Newbie question: hash tables and dbm files; what am I doing wrong?
Message-Id: <K4t96.4287$d25.26093@newsfeed.slurp.net>
<gnari@my-deja.com> wrote in message news:942erp$dpm$1@nnrp1.deja.com...
> a quick search on deja.com for 'FAQ DBM' actually locates this very FAQ
> and an excellent reply by Garry Williams to a similar posting less than
> 3 weeks ago
Thanks, I think I'll look that up!
jmk
--
do NOT remove the nospam from the repy to address above,
instead send email to o1tech(at)skyenet(dot)net
JAPN 8_(
------------------------------
Date: Thu, 18 Jan 2001 02:24:08 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: No such a file or directory
Message-Id: <cts96.133$032.5914@eagle.america.net>
On Wed, 17 Jan 2001 17:38:16 GMT, Bram Hendriks <bhendriks@home.nl> wrote:
>I am a very newbie to CGI-BIN via perl.
>
>I have a problem, I have a red hat linux 6.1 pc with perl etc.
>
>When I'm writing a very simple script (write's ony hello)
>
>and I save it, do chmod 755 script.pl.
>
>But when I start the script for testing
>./script.pl
>then linux says: No such a file or directory.
Thanks for the paraphrase, but the actual error message copied and
pasted would be much better. Some actual code copied and pasted would
help, too.
Anyway, let me guess:
Is perl located at the place the script designates in its first line
(#!...)?
>but when i do: perl -cw script.pl linux says: syntax OK
Sorry, perl -- not linux -- said that one. :-)
Ahhh. We can now find out where perl really is:
which perl
This will print the actual path to perl and you can now change the
first line of your script to reflect that.
>then i started the webbrowser and go to
>192.168.1.1/cgi-bin/script.pl
>
>I get an error 500 (internal server error)
Now you need to examine your Web server's error log file to see what
error actually occurred. (That will contain the same error message
that you failed to copy and paste above.)
By the way, are you using the CGI module?
--
Garry Williams
------------------------------
Date: Thu, 18 Jan 2001 04:30:08 -0000
From: adam <sks@sierra.net>
Subject: perl N' windoze
Message-Id: <t6csagh8uhpof5@corp.supernews.com>
I'm starting into perl. I want to know if perl can be ran on windoze
machines. Of course, my primary OS is Windoze, I'd like to experiment
and test my scripts in windowze. How? user\~bin\hello world doesn't seem
right. what do I need to know. Please, don't flame me.
Adam T.
sks@sierra.net
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Thu, 18 Jan 2001 15:38:58 +1100
From: "Chris W" <chrisw.NOSPAM@dynamite.com.au>
Subject: Re: perl N' windoze
Message-Id: <ptu96.52$PN6.2698@news0.optus.net.au>
"adam" <sks@sierra.net> wrote in message
news:t6csagh8uhpof5@corp.supernews.com...
> I'm starting into perl. I want to know if perl can be ran on windoze
> machines.
Yes.
www.activestate.com
------------------------------
Date: Thu, 18 Jan 2001 04:41:10 GMT
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: perl N' windoze
Message-Id: <3A667397.C44F3092@catlover.com>
> I'm starting into perl. I want to know if perl can be ran on windoze
> machines. Of course, my primary OS is Windoze, I'd like to experiment
> and test my scripts in windowze. How? user\~bin\hello world doesn't seem
> right. what do I need to know. Please, don't flame me.
ActiveState has supported Perl ( plus Python and others ) on the Windows
platform for quite some time. www.activestate.com
http://www.google.com/search?q=perl+windows
- Ron
------------------------------
Date: Wed, 17 Jan 2001 22:00:23 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: perlcc for Win NT
Message-Id: <3A665C47.B0E95CA9@patriot.net>
www.perl2exe.com
eacooper2085@my-deja.com wrote:
> Hello,
> I would like to compile my perl program to an a standalone
> executable. I have the ActivePerl software and perlcc gives a message
> saying it is very experimental. Is there reliable software to do this?
>
> thanks in advance,
> Eric
> eric.cooper@clarent.com
>
> Sent via Deja.com
> http://www.deja.com/
--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.
------------------------------
Date: Thu, 18 Jan 2001 04:29:49 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: POD to powerpoint translator?
Message-Id: <1ju96.1065$B9.190630912@news.frii.net>
In article <3A6640FB.8497CD74@hp.com>,
John Benavides <john_benavides@hp.com> wrote:
>Has anyone built a POD to PowerPoint translator?
>
>I would like to display some of my module work
>in PowerPoint and wondered if someone has already
>cooked this up?
>
pod2html load the result into Word. From there it should be obvious.
chris
--
This space intentionally left blank
------------------------------
Date: Thu, 18 Jan 2001 03:58:02 GMT
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: Random text script, got one?:-)
Message-Id: <3A66697A.ED8FD105@catlover.com>
> Hi I looking for a random text script if someone has already have made.
Data::Random - Perl module to generate random data
Data::Random::WordList - Perl module to get random words from a word
list
Page 52 from the Cookbook shows how to create random passwords ( i.e. 8
character strings ). You could modify that to suit your needs.
- Ron
------------------------------
Date: 18 Jan 2001 02:26:47 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Running a CGI as a USER
Message-Id: <slrn96cl4m.88k.damian@puma.qimr.edu.au>
Brian E. Seppanen posted the following to comp.lang.perl.misc
on Wed, 17 Jan 2001 20:55:47 -0500:
>Hello:
>
>this. Would I have to fork a new process? Would it be as easy as
>defining $EFFECTIVE_USER_ID=(getpwnam($username)) [3]; Although I've
>tried that it doesn't seem to work. Doing it this way would allow the
>guestbook to be rw-r--r--. Not just anyone could write to it.
>
>I really don't know whether this is more of an apache issue or a perl
>issue.
Why not just chmod the file 660, create a dummy group (called 'guestbook' or
something equally imaginative), then add the webserver's UID to that group?
Or have the file owned by the webserver's UID, and chmod 600?
Cheers,
Damian
------------------------------
Date: Thu, 18 Jan 2001 04:11:44 GMT
From: aksethi@my-deja.com
Subject: Re: Running setuid Perl scripts
Message-Id: <945qdt$975$1@nnrp1.deja.com>
Tom,
I was running into the same problem today and the way I have fixed it is that
I wrote a C wrapper over the perl script , setup sticky bit on the executable
generated and that resolved this problem
vi wrap.c
#define REAL_FILE /path/to/perl/sscript"
int main(int argc, char**argv)
{
execv(REAL_FILE,argv);
return 0;
}
cc -o wrap wrap.c
chmod 6755 wrap
and then use this 'wrap' in place of the perl script that you are using, and
that should fix it ->atleast I got mine fixed like this
Hope that helps
Arun
In article <3A55FB75.5D344CEB@lucent.com>,
Thomas Edmond <tomedmond@lucent.com> wrote:
> Hello,
>
> I'm trying to run a Perl script from another program which is part of
> our configuration and change management control system (called Sablime)
> - this overall C&CMCS allows individual commands to run external scripts
> as pre-<command_name> and post-<command_name> triggers - this command
> and its trigger are run suid of the owner of the C&CMCS (not the user
> running the command)
>
> My pre-<command> trigger script is a ksh script which extracts a Framemaker
> file from theC&CMCS, turns it into text and then calls my perl script which
> then parses it to extract relevant information.
> The suid is causing me great problems - the perl script bombs out with fatal
> errors due to "Insecure $ENV{PATH}..." problems.
>
> I have tried most of the suggestions in Ch. 6 of the "bible", notably running
> a forked process with UID set back to the user running the command but with
> little success - it partially works when I run all the &Date_<??>" functions
> inside the perl script as forked processes but I seem to get double the output
> (one half correct, the other with errors although working on the same file)
>
> Before I go and rewrite the parser in ksh (or awk or 'C'), has anybody got a
> good (practical) example of this kind of thing working ??
>
> BTW - perl versions 5.004 and 5.6.0 tried - same result
>
> Cheers
>
> Tom Edmond
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 03:15:34 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Saving .htm file to disk from CGI script
Message-Id: <qdt96.152$032.7656@eagle.america.net>
On Wed, 17 Jan 2001 22:04:26 GMT, Trees for Life <nomail@spam.com>
wrote:
>I'm using Perl for CGI scripting. I want the script to generate an
>HTML file, but instead of printing it to STDOUT, to create a .htm
>file on my hard drive. Can this be done?
Yes.
>Following is my test code. Instead of creating an
>.htm file, it printed the Hello World to screen.
It's hard to believe that the code below does that. (For "printed ...
to screen" == "sent to browser".)
>open (HTMLFILE, "> cgi-bin/savehtmtolocal.htm") or die "Could not open file.";
#!/usr/local/bin/perl -wT
use strict;
Are you using the CGI module?
open (HTMLFILE, "> cgi-bin/savehtmtolocal.htm")
or die "Could not open cgi-bin/savehtmtolocal.htm: $!";
_Always_ print the file name and $! in an error message about a file
operation failing. There's nothing more infuriating than an error
message about a file that doesn't name the file or the error
encountered! Such a message is *worthless*.
Also, how do you know what the current directory is? Shouldn't you
change to a known path before opening a relative path or use an
absolute path?
>flock (HTMLFILE, 2) or die "Could not lock file.";
...
or die "Could not lock cgi-bin/savehtmtolocal.htm: $!";
Hmmm. Now that we have successfully *truncated* the file
`cgi-bin/savehtmtolocal.htm', we now attempt to lock it. A little
late, I would say. Don't you agree? :-)
Also, always use the constants imported by Fcntl instead of magic
numbers (that may be wrong or that may change in the next release):
use Fcntl qw(:flock);
...
flock(FH, LOCK_EX) or ...
You should read the "File Locking" section of the perlopentut manual
page to learn how to open a file for output and obtain an exclusive
lock on it correctly. Your code is fatally flawed.
>print HTMLFILE <<LIST_ITEM;
><HTML>\n
><HEAD>\n
><TITLE>Hello World<TITLE>\n
></HEAD>\n
><BODY>\n
><H1>Hello World!</H1>\n
></BODY>\n
></HTML>
>LIST_ITEM
>
>flock (HTMLFILE, 8);
>close HTMLFILE;
Do not unlock a file before flushing the output buffers associated
with the file. Modern versions of perl will protect you, but this is
just bad technique. Simply close a file to release a lock held on it.
I cannot believe that this code produces _any_ output on STDOUT. Have
you not included the real code?
--
Garry Williams
------------------------------
Date: Thu, 18 Jan 2001 03:54:00 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Saving .htm file to disk from CGI script
Message-Id: <slrn96cjev.3n7.tadmc@tadmc26.august.net>
Garry Williams <garry@zvolve.com> wrote:
> #!/usr/local/bin/perl -wT
^
^
While that is nearly always an extremely Good Idea for CGI programs
(perhaps such a good idea that you should get used to using it
even when you don't need it), it is not required for the program
posted. That program does not take any user input, so there
won't be any data for tainting to mark :-)
[ snip lots of good advice ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 18 Jan 2001 02:03:08 GMT
From: marc@oscar.eng.cv.net (Marc Spitzer)
Subject: Re: Sorting complex data structure
Message-Id: <slrn96cjhf.1m1d.marc@oscar.eng.cv.net>
In article <t6cglljs8jo382@corp.supernews.com>, Art wrote:
>I have a data structure listed as such:
>
>%Records = (
# > "Username" => {
"$Username" => {
> Last_Name => "$Last_Name",
> First_Name => "$First_Name",
> Email = "$Email);
> },
>...
> etc..
first by definition you cannot sort a hash table, it is a bunch of
unsorted key value pairs, with that said you can sort the keys, here
is one way to do it:
my @stuff = keys %Records ;
@stuff = sort {uc($Records{$a}{"Last_Name"}) cmp uc($Records{$b}{"Last_Name"})}\
@stuff;
foreach $key (@stuff) {
print stuff here;
}
or
map {print stuff;} \
sort {uc($Records{$a}{"Last_Name"}) cmp uc($Records{$b}{"Last_Name"})} \
keus %Records;
if it has to be on 1 line, it was over 80 chars.
the trick is you do not sort the hash, you sort an array of the first level
keys of the hash. Then you access the hash using the sorted keys. Also
your first lines should look like this:
#!/where/perl/is/perl -w
use strict;
it will tell you what you need to fix.
good luck
marc
>
>
>I want to run through and sort the hash by the last name, I've tried a
>number of sort tactics, but I am only able to sort by the first level keys.
>
>Thanks in advance for any pointers / advice.
>This was my last iteration, it is GODLY wrong, but I am so confused with t
>foreach my $key (sort { sort { lc($Records{$key}{'sn'}{$a}) cmp
>lc($Records{$key}{'sn'}{$b}) } keys %{ $Records{$keys}{'sn'} } } keys
>%Records) {
>
>
------------------------------
Date: Wed, 17 Jan 2001 21:18:45 -0500
From: "Art" <artd@artd3.com>
Subject: Re: Sorting complex data structure
Message-Id: <t6ckk8ohfjdce7@corp.supernews.com>
See below...
"Damian James" <damian@puma.qimr.edu.au> wrote in message
news:slrn96cjfe.4tn.damian@puma.qimr.edu.au...
> Art posted the following to comp.lang.perl.misc
> on Wed, 17 Jan 2001 16:40:41 -0500:
> >I have a data structure listed as such:
> >
> >%Records = (
> > "Username" => {
> > Last_Name => "$Last_Name",
> > First_Name => "$First_Name",
> > Email = "$Email);
> > },
> >...
> > etc..
>
> Is this right? Are you sure it shouldn't be something like:
>
> my @records = (
> {
> Username => {
> Last_Name => "$Last_Name",
> First_Name => "$First_Name",
> Email = "$Email"
> },
> Other_attributes => {
> shoesize => "etc"
> }
> },
> { Username => 'etc' },
> );
>
> Or is there really only one record?
>
> >
> >I want to run through and sort the hash by the last name, I've tried a
> >number of sort tactics, but I am only able to sort by the first level
keys.
>
> Probably this is not what you want to do - it doesn't make sense to sort a
> hash (see perldata).
>
> If you agree that the data structure should be as I suggested above, then
the
> sort should be fairly straightforward. See perldoc -f sort for details.
For
> the above, it would look something like:
Don't want to sort the hash in the way it is stored, rather how it is
outputted. For example I have a script that gets static and dynmic list
members, and puts them into a hash as described in my original post
# Scriplet
# Normally this data is taken from Net::LDAP
push @Array_Of_DNs =
('uid=xyz,ou=someou,o=arius.com','uid=fds,ou=someotherou,o=arius.com');
foreach my $dn (@Array_Of_DNs) {
$Hash_Of_Members{"$dn"}{'Full_Name'} = $cn;
$Hash_Of_Members{"$dn"}{'Last_Name'} = $sn;
# etc....
};
# End Scriptlet
When I output the data, I;d like to be able to print the users in order of
their last name, i've been able to sort upon the easy (sort keys
%Hash_Of_Members) but thats about it... So I guess what I am really trying
to do is get a list of keys for the top level hash that are sorted based on
the Last_Name.
Thanks for the comments.
-art
>
> @records = sort { lc($a->{Username}->{Last_name})
> cmp
> lc($b->{Username}->{Last_name}) }, @records;
>
>
> Cheers,
> Damian
------------------------------
Date: Wed, 17 Jan 2001 21:28:53 -0500
From: "Art" <artd@artd3.com>
Subject: Re: Sorting complex data structure
Message-Id: <t6cl7b45bg4pf4@corp.supernews.com>
Yup, that did it, thanks...
"Marc Spitzer" <marc@oscar.eng.cv.net> wrote in message
news:slrn96cjhf.1m1d.marc@oscar.eng.cv.net...
> In article <t6cglljs8jo382@corp.supernews.com>, Art wrote:
> >I have a data structure listed as such:
> >
> >%Records = (
> # > "Username" => {
> "$Username" => {
> > Last_Name => "$Last_Name",
> > First_Name => "$First_Name",
> > Email = "$Email);
> > },
> >...
> > etc..
>
> first by definition you cannot sort a hash table, it is a bunch of
> unsorted key value pairs, with that said you can sort the keys, here
> is one way to do it:
>
> my @stuff = keys %Records ;
>
> @stuff = sort {uc($Records{$a}{"Last_Name"}) cmp
uc($Records{$b}{"Last_Name"})}\
> @stuff;
>
> foreach $key (@stuff) {
> print stuff here;
> }
>
> or
>
> map {print stuff;} \
> sort {uc($Records{$a}{"Last_Name"}) cmp uc($Records{$b}{"Last_Name"})} \
> keus %Records;
>
> if it has to be on 1 line, it was over 80 chars.
>
> the trick is you do not sort the hash, you sort an array of the first
level
> keys of the hash. Then you access the hash using the sorted keys. Also
> your first lines should look like this:
> #!/where/perl/is/perl -w
> use strict;
>
> it will tell you what you need to fix.
>
> good luck
>
> marc
>
> >
> >
> >I want to run through and sort the hash by the last name, I've tried a
> >number of sort tactics, but I am only able to sort by the first level
keys.
> >
> >Thanks in advance for any pointers / advice.
> >This was my last iteration, it is GODLY wrong, but I am so confused with
t
> >foreach my $key (sort { sort { lc($Records{$key}{'sn'}{$a}) cmp
> >lc($Records{$key}{'sn'}{$b}) } keys %{ $Records{$keys}{'sn'} } } keys
> >%Records) {
> >
> >
------------------------------
Date: 18 Jan 2001 02:44:42 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Sorting complex data structure
Message-Id: <slrn96cm69.88k.damian@puma.qimr.edu.au>
Art posted the following to comp.lang.perl.misc
on Wed, 17 Jan 2001 21:18:45 -0500:
>"Damian James" <damian@puma.qimr.edu.au> wrote in message
>news:slrn96cjfe.4tn.damian@puma.qimr.edu.au...
>
>foreach my $dn (@Array_Of_DNs) {
> $Hash_Of_Members{"$dn"}{'Full_Name'} = $cn;
> $Hash_Of_Members{"$dn"}{'Last_Name'} = $sn;
> # etc....
>};
>
># End Scriptlet
>
>... So I guess what I am really trying
>to do is get a list of keys for the top level hash that are sorted based on
>the Last_Name.
>
In that case, it would be:
@sorted_list = sort { lc($Hash_Of_Members{$a}->{Last_Name})
cmp
lc($Hash_Of_Members{$b}->{Last_Name})
} keys %Hash_Of_Members;
BUT see perldoc -f sort for details.
>> @records = sort { lc($a->{Username}->{Last_name})
>> cmp
>> lc($b->{Username}->{Last_name}) }, @records;
^
^
Whoops -- my bad, that comma shouldn't be there
Cheers,
Damian
------------------------------
Date: Thu, 18 Jan 2001 04:27:54 GMT
From: eric_edlin@my-deja.com
Subject: Re: Sorting complex data structure
Message-Id: <945rc7$9t2$1@nnrp1.deja.com>
In article <t6cglljs8jo382@corp.supernews.com>,
"Art" <artd@artd3.com> wrote:
> I have a data structure listed as such:
>
> %Records = (
> "Username" => {
> Last_Name => "$Last_Name",
> First_Name => "$First_Name",
> Email = "$Email);
> },
> ...
> etc..
This is not the most condensed, but it does the trick.
foreach $user (keys %Records) {
push (@lname, lc $Records{$user}{Last_Name});
}
sort @lname;
Eric
>
> I want to run through and sort the hash by the last name, I've tried a
> number of sort tactics, but I am only able to sort by the first level
keys.
>
> Thanks in advance for any pointers / advice.
> This was my last iteration, it is GODLY wrong, but I am so confused
with t
> foreach my $key (sort { sort { lc($Records{$key}{'sn'}{$a}) cmp
> lc($Records{$key}{'sn'}{$b}) } keys %{ $Records{$keys}{'sn'} } } keys
> %Records) {
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 03:05:07 GMT
From: "paanwa" <paanwa@hotmail.com>
Subject: Re: Syntax - Still need HELP
Message-Id: <D3t96.19413$_B2.1678311@typhoon.kc.rr.com>
Good thought Ren.....I will do that.
PAW
> I'm afraid it looks like we're going to have to see more of the code
> to figure out what the problem is. If you comment out the problem
> lines, the error will likely move to a different line. Sometimes this
> strategy can help you find the real problem.
>
> --
> Ren Maddox
> ren@tivoli.com
------------------------------
Date: Thu, 18 Jan 2001 14:29:19 +1100
From: "Chris W" <chrisw.NOSPAM@dynamite.com.au>
Subject: Re: Syntax - Still need HELP
Message-Id: <Rrt96.48$PN6.3102@news0.optus.net.au>
"PaAnWa" <paul_wasilkoff@ucg.org> wrote in message
news:t6c7t2ikrdope3@corp.supernews.com...
> for example, line 118 had the "next token 'print '" error; here is the
> previous and next line of code:
> print "<HR><H3>You did not fill in the required Survey Information
fields."; #Line 117
> print " Please click the Back button at the top of your browser and
answer" ; #Line 118
> print "the two survey questions listed at the bottom of the page.</P>";
#Line 119
What happens when you use the 'here' document to simpify the bul text
output?
print <<_EOPRINT;
<HR><H3>You did not fill in the required Survey Information fields
Please click the Back button at the top of your browser and answer
the two survey questions listed at the bottom of the page.</P>
_EOPRINT
------------------------------
Date: Thu, 18 Jan 2001 04:21:58 GMT
From: duckdba <scorkery@my-deja.com>
Subject: Using perl to update an ASP?
Message-Id: <945r13$9ja$1@nnrp1.deja.com>
My employer recently starting requiring it's employees "clock-in" by
logining in to a web-page. This page is tied to our vacation days and
if we forget to "clock-in", one day is docked from our total number of
vaction days. I am looking for a way to automate this "clocking-in"
process, so that I can put it in a cron job, so I don't have to worry
about losing vacation days.
The webpage is an ASP. Is it possible to write a perl script that will
send my login information to the ASP? And if so, are there any
examples out there? (I've looked, but I didn't see any) Or could some
one advise me how to go about writing a script that would accomplish
this?
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 04:43:45 GMT
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: Using perl to update an ASP?
Message-Id: <3A66742F.7C8E497@catlover.com>
> The webpage is an ASP. Is it possible to write a perl script that will
> send my login information to the ASP? And if so, are there any
> examples out there? (I've looked, but I didn't see any) Or could some
> one advise me how to go about writing a script that would accomplish
> this?
ASP is just another server-side scripting platform. The normal
LWP::UserAgent, HTTP::Cookies, HTTP::Request::Common, etc. will all work
as documented.
- Ron
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 86
*************************************