[7875] in Perl-Users-Digest
Perl-Users Digest, Issue: 1500 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 18 15:08:29 1997
Date: Thu, 18 Dec 97 12:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 18 Dec 1997 Volume: 8 Number: 1500
Today's topics:
Re: <SELECT MULTIPLE > Script only gives one value. Ca (Stephen P. Clouse)
Re: Adding user to NT domain <ebd@sunline.net>
Re: Advanced Perl Programming book (Thaths)
Dereference in double quotes for a print <clark@s3i.com>
Hard problem: Strip C comments while preserving newline (Bob Weissman)
Re: how to do this from STDIN (WOLtetch)
Re: Linux/Perl -> Oracle 7.3 on SCO Unix (or other) (Honza Pazdziora)
Net::Cmd - package question? <aschneid@geocities.com>
Re: Newbie can't add the -w flag to perl to get useful <rootbeer@teleport.com>
Re: No Flock! -- Now What? <rootbeer@teleport.com>
Re: Number of items in an array <rootbeer@teleport.com>
Re: one liners (Honza Pazdziora)
Re: one liners <ajohnson@gpu.srv.ualberta.ca>
Re: Perl editor needed (Neil Burnett)
prototyping <prl2@lehigh.edu>
Re: Q: limiting the input array size <rootbeer@teleport.com>
Re: Q: sorting hash by category <bowlin@sirius.com>
Re: Setting an Enviroment Variable in a Web Perl script (Honza Pazdziora)
Re: Sorting Hashes By Value <#@qz.to>
Re: Sorting Hashes By Value <tchrist@mox.perl.com>
unshift, @INC, require??? (Mark)
Re: What kind of machine wouldn't support FLOCK? <rootbeer@teleport.com>
Re: What kind of machine wouldn't support FLOCK? <clark@s3i.com>
Re: Which language pays most 17457 -- C++ vs. Java? (Lawrence Kirby)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Dec 1997 14:54:01 GMT
From: stephenc@granddesign.com (Stephen P. Clouse)
Subject: Re: <SELECT MULTIPLE > Script only gives one value. Can you help?
Message-Id: <349934ec.1092861@news.kc.net>
Hash: SHA1
On Thu, 18 Dec 1997 01:42:24 -0800, Craig <rcd@kiwi.net> wrote:
>Example:
><SELECT MULTIPLE SIZE=2 NAME="name">
><OPTION>something
><OPTION>somethingelse
></SELECT>
>
>If you have multiple values of a the SELECT tag in a form, the contents
>get sent to the Perl script like this:
>
>&name=something&name=somethingelse
>
>In which case the first "name" gets over written and the final value of
>"name" is "somethingelse".
>
>The code I use is like this:
>$name = $in->param('name');
>
>How can I capture all values of "name"?? I would appreciate it if you
>could help.
Without knowing what you're using to parse in the CGI variables it's a little
harder to help, but assuming you iterate across the CGI variable string by
splitting it on &:
foreach $pair (split(/&/,$cgiin)) {
($key,$val) = split(/=/,$pair,2);
$cgi{$key} .= \000 if $cgi{$key};
$cgi{$key} .= $val;
}
This is actually how the old cgi-lib.pl did it. What it results in is a
null-separated string of variables for each multiple-selection form element. By
doing a split(/\000/,$val) you end up with an array of the selected values that
you can iterate across and do whatever with.
Most people use CGI.pm for handling this stuff, but I don't use it so I'm not
sure how it works. I'm not a fan of loading in a 160K module when all I need is
the above five lines. I'd prefer to invent the compact wheel rather than attach
to my car the one monster truck tire left in the store :) Of course, your
wheelage may vary.
- --
Stephen P. Clouse
stephenc@granddesign.com -- steve@warpcore.org -- UIN 135012
Grand Design, Inc. (http://www.granddesign.com) -- Quality Business Web Design
The Warp Core (http://www.warpcore.org) -- The Web's Premier Descent Site
PGP-Encrypted E-Mail Preferred (Key available at www.granddesign.com/stephenc)
Fight Spam/UCE -- http://www.cauce.org
Version: PGP for Business Security 5.5
iQA/AwUBNJk4/2OLD55Fj/ZkEQLgugCfYQFi1nT32vuEee9jnbUdqt4H9j8AoNU2
lOD4WmaiaveUIIzLpmnnFewO
=SSuk
-----END PGP SIGNATURE-----
This article was posted from <A HREF="http://www.slurp.net/">Slurp Net</A>.
------------------------------
Date: Thu, 18 Dec 1997 12:33:54 -0500
From: "E. Brian Depenbrock" <ebd@sunline.net>
Subject: Re: Adding user to NT domain
Message-Id: <67bncu$bnh@snews1.zippo.com>
I did not find the answer, gut I have seen it somewhere. There is a command
line switch, look in the regular NT Help.
BTW, This scripts may not work if you are not logged on as Administrator.
Which means it won't work over the internet. You need NTACCESS which is
shareware.
Guido Smit wrote in message <67beed$4od$1@news2.xs4all.nl>...
>Hi there,
>I've made a perl script to add users to a NT domain. This work pretty good
>with the utils from the resource kit (addusers and usrtogrp). But I want to
>user the win32 extensions from the perl module win32. UserCreate does not
>create a user and I cannot find any documentation on this.
>Does anyone know how to do this and my next question, how can I define
flags
>with this command.
>
>The next problem is probably a NT problem, not a perl problem, but perhaps
>anyone can tell me how I can resolve this in perl. When I create a user
>using the perl script, the user has to change his password at the next
>logon. I don't want this. I can't find any command for this.
>
>guido@sportnet.nl
>
>
------------------------------
Date: 18 Dec 1997 19:21:50 GMT
From: thaths@nospam.com (Thaths)
Subject: Re: Advanced Perl Programming book
Message-Id: <67bt4e$igu1@continuity.mcom.com>
In article <679oni$nu1$2@csnews.cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> writes:
> In comp.lang.perl.misc, Allen Choy <achoy@us.oracle.com> writes:
>:Does anyone have any opinions, good and bad, re: the Advanced Perl
>:Programming book?
> Four out of five camels. Definitely a should-buy.
Would beginners books be graded on a scale of 1 to 5 Llamas? ;-)
Thaths
--
"He who laughs last gets dirty stares."
http://people.netscape.com/thaths/
%remove_this%thaths@netscape.com
------------------------------
Date: 18 Dec 1997 13:30:09 -0500
From: Clark Dorman <clark@s3i.com>
Subject: Dereference in double quotes for a print
Message-Id: <du3c6tsge.fsf@s3i.com>
I have been trying to understand sockets and in particular IO::Socket
but have had trouble printing out OO information. I took the code from
perlipc and played with it, printing various information about the
client on the server side. We get information about the client using:
$client = $server->accept();
$clientinfo = gethostbyaddr($client->peeraddr);
(We use Net::hostent to use the OO style of $client. Thanks Tom)
The problem I'm having is when printing the information about the
client. The following works:
printf "Client name: %s\n", $client_info->name;
and puts out something like:
Client name: blackbird
The following print statement, which I tried first:
print "Client name: $client_info->name\n";
puts out:
Client name: Net::hostent=ARRAY(0x1dde00)->name
The following does work:
print "Client name: ", $client_info->name,"\n";
Can I not use the '->' dereference within double quotes? or is there
something I don't understand going on.
I've included the server and client listings below.
--
Clark
P.S. As it turns out, sending the 'cookie' or 'who' command from the
client gives:
Insecure $ENV{PATH} while running with -T switch at s.pl line 47, <GEN1> chunk 4.
and it dies.
---begin server---------------------------------------------------------
#!/home/dorman/bin/perl -Tw
# This is a server take from the perlipc pod page, hacked by Clark Dorman
use IO::Socket;
use Net::hostent; # for OO version of gethostbyaddr
($port) = @ARGV; # Take the port from input if there
$PORT = 9000 unless $port; # otherwise, set port=9000
#--------------------------------------------------
# create a tcp server and call it server.
#--------------------------------------------------
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "Server $0 accepting clients\n";
#------------------------------------------------------
# Get a client. accept() blocks and waits for something to happen.
#------------------------------------------------------
$client = $server->accept();
$client->autoflush(1);
print $client "Welcome to $0; type help for command list.\n";
#------------------------------------------------------
# Get information about our client
#------------------------------------------------------
$clientinfo = gethostbyaddr($client->peeraddr);
&print_client_info($client);
printf "[Connect from %s]\n", $clientinfo->name || $client->peerhost;
print $client "Command? \n";
#------------------------------------------------------
# Process commands until there aren't any
#------------------------------------------------------
while ( <$client>) {
next unless /\S/; # blank line
if (/quit|exit/i) { last; }
elsif (/date|time/i) { printf $client "%s\n", scalar localtime; }
elsif (/who/i ) { print $client `who 2>&1`; }
elsif (/cookie/i ) { print $client `/usr/games/fortune 2>&1`; }
elsif (/motd/i ) { print $client `cat /etc/motd 2>&1`; }
else {
print $client "Commands: quit date who cookie motd\n";
}
} continue {
print $client "Command?\n";
}
close $client;
sub print_client_info() {
local($cl)=shift;
# peeraddr ()
# Return the address part of the sockaddr structure for
# the socket on the peer host
#
# peerport ()
# Return the port number for the socket on the peer host.
#
# peerhost ()
# Return the address part of the sockaddr structure for
# the socket on the peer host in a text form xx.xx.xx.xx
#
# sockaddr ()
# Return the address part of the sockaddr structure for
# the socket
#
# sockport ()
# Return the port number that the socket is using on the
# local host
#
# sockhost ()
# Return the address part of the sockaddr structure for
# the socket in a text form xx.xx.xx.xx
$client_peerport = $cl->peerport;
$client_peerhost = $cl->peerhost;
$client_sockport = $cl->sockport;
$client_sockhost = $cl->sockhost;
print "Client peer port: ($client_peerport)\n";
print "Client peer host: ($client_peerhost)\n";
print "Client sock port: ($client_sockport)\n";
print "Client sock host: ($client_sockhost)\n";
# gethostbyaddr returns a structure like the following:
# ($name,$aliases,$addrtype,$length,@addrs) = gethost*
$client_info = gethostbyaddr($cl->peeraddr);
printf "Client name: %s\n", $client_info->name;
print "Client name: $client_info->name\n";
print "Client name: ", $client_info->name,"\n";
printf "Client aliases: %s\n", $client_info->aliases;
printf "Client addrtype: %s\n", $client_info->addrtype;
printf "Client length: %s\n", $client_info->length;
# printf "Client addrs: %s\n", $client_info->addrs;
}
---end server ---------------------------------------------------------
---begin cleint---------------------------------------------------------
#!/home/dorman/bin/perl -w
# Client code using IO::Socket from perlipc page. Hacked by me.
use strict;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $line);
($host, $port) = @ARGV;
$port = 9000 unless $port;
$host = 'localhost' unless $host;
#--------------------------------------------------
# create a tcp connection to the specified host and port
#--------------------------------------------------
$handle = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $host,
PeerPort => $port
)
or die "can't connect to port $port on $host: $!";
print STDERR "[Connected to $host:$port]\n";
#--------------------------------------------------
# Set flushing buffer on the handle. output gets there right away
#--------------------------------------------------
$handle->autoflush(1);
#--------------------------------------------------
# split the program into two processes, identical twins
#--------------------------------------------------
die "can't fork: $!" unless defined( $kidpid = fork() );
#--------------------------------------------------
# Recieve info from handle in parent, send info to
# handle in child
#--------------------------------------------------
if ($kidpid) {
# This is the parent process
while (defined ($line = <$handle>)) {
print STDOUT $line;
}
kill("TERM", $kidpid);
}
else {
# This is the Child
while (defined ($line = <STDIN>)) {
print $handle $line;
}
}
----end client--------------------------------------------------------
------------------------------
Date: Thu, 18 Dec 1997 18:45:10 GMT
From: weissman@netcom.com (Bob Weissman)
Subject: Hard problem: Strip C comments while preserving newlines
Message-Id: <weissmanELEErA.2yJ@netcom.com>
In the Perl FAQ, there is a code fragment to remove (possibly
multi-line) C comments from a file:
$/ = undef;
$_ = <>;
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|\n+|.[^/"'\\]*)#$2#g;
print;
That seems to work.
But I find that I need to preserve the newline ('\n') characters so that
line counts do not change. The above s/// statement removes the
newlines.
I've stared at this, expanded it into a more readable /x form, but
cannot figure out how to preserve the newlines.
Anyone?
Thanks,
== Bob
------------------------------
Date: 18 Dec 1997 19:21:00 GMT
From: woltetch@aol.com (WOLtetch)
Subject: Re: how to do this from STDIN
Message-Id: <19971218192101.OAA08777@ladder01.news.aol.com>
Ironically, I do know how to do it with files as arguments.
All I want is to be able to type in the program name at the command line, then
enter some items to sort and have the script sort them. So it's STDIN I'm using
here (badly it seems).
Thanks.
>WOLtetch (woltetch@aol.com) wrote:
>: I have the following script:
>
>: #!/usr/local/bin/perl -w
>: use diagnostics;
>
>: @list2sort = <STDIN>;
>
>[snip]
>
>: This works fine if I define a test array to sort in the script itself.
>: However, in its present form, when I try to have it sort stuff
>: entered on the command line, it doesn't work (prints the input, unsorted).
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
>
>I'm confused by your confusion ;-)
>
>
>"input" is accessed as you have above (via the STDIN filehandle).
>
>"command line arguments" are accessed from the @ARGV array.
>
>Which do you really mean?
>
>
>: What am I doing wrong here?
>
>
>I think maybe you want the command line arguments to be taken as
>filenames, whose contents you want to sort, rather than as a list
>of words themselves that you want to sort?
>
>If so, then this should do it:
>
> @list2sort = <>; # use magic
>
>
>--
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
>
>
>
>
>
>
>
------------------------------
Date: Thu, 18 Dec 1997 17:53:56 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Linux/Perl -> Oracle 7.3 on SCO Unix (or other)
Message-Id: <adelton.882467636@aisa.fi.muni.cz>
"Barry Roomberg" <broomberg@ccgroupnet.com> writes:
> I'd like to be able to have a PERL program
> on a Linux box access an Oracle instance across
> the network. I'm confused. If I was connecting
> 2 SCO boxes, I'd setup a SQL/Net connection and
> go from there. No SQL/Net under Linux that
> I'm aware of. Am I wrong? What are my
> alternatives? Can anyone point
> me in a direction. Thanks.
You either use iBCS to run the SCO binary on Linux, or use DBD::pNET
DBI proxy to forward your DBI commands from Linux to wherever you
want. You can get DBD::pNET on any good CPAN store.
Hope this helps,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Thu, 18 Dec 1997 12:48:24 -0500
From: Alan Schneider <aschneid@geocities.com>
Subject: Net::Cmd - package question?
Message-Id: <349961E8.6675@geocities.com>
How can I use Net::Cmd with Net::Ftp?? I have all calls to Net::Ftp
working fine. However, I am trying to catch "specific" error messages
when ftp'ing (e.g., file or directory does not exist) and I am
"ass?"uming that I should be using Net::Cmd to catch these error
messages. Someone please give me a code snippet on how to use Net::cmd
(message() seems to return what I want). It seems I cannot use a
constructor to set up this object however??
Many Thanks...
Alan Schneider
------------------------------
Date: Thu, 18 Dec 1997 10:55:02 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Dave Reed <daveSTOP*SPAMreed@webshowplace.com>
Subject: Re: Newbie can't add the -w flag to perl to get useful warnings
Message-Id: <Pine.GSO.3.96.971218105432.18763K-100000@user2.teleport.com>
On Thu, 18 Dec 1997, Dave Reed wrote:
> Subject: Newbie can't add the -w flag to perl to get useful warnings
Check out the perlrun manpage. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 18 Dec 1997 10:17:03 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: No Flock! -- Now What?
Message-Id: <Pine.GSO.3.96.971218101610.18763C-100000@user2.teleport.com>
On Wed, 17 Dec 1997, Mark S. Reibert wrote:
> > Is it possible to develop something that is strictly PERL code, and can
> > provide flock or something like it under any setup?
>
> You can always consider a semaphore!
Are there systems on which Perl can't flock, but which do support
semaphores?
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 18 Dec 1997 10:24:14 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Christopher Lambrou <alambro@ibm.net>
Subject: Re: Number of items in an array
Message-Id: <Pine.GSO.3.96.971218102333.18763E-100000@user2.teleport.com>
On 18 Dec 1997, Christopher Lambrou wrote:
> $items = $#array; # to get number of items in array @array
Nooooo! That's one _fewer_ than the number of items in @array.
$items = @array; # to get the number of items in @array;
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 18 Dec 1997 17:51:25 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: one liners
Message-Id: <adelton.882467485@aisa.fi.muni.cz>
Kevin Maguire <kcm@tca1.dl.ac.uk> writes:
> How to this in a perl one-liner
>
> replace record 3 of line 10 in file nozz10 with hello:
> head -9 nozz10; head -10 nozz10 | tail -1 | awk '{$3="hello"; print $0}' ; tail +11 nozz10
>
> Must be pretty easy ?! And faster than the above? What about for all
> files (*10) in a one-liner?
perl -pe 'if ($.==10) {@a=split / /; $a[2]="hello"; $_=join " ",@a; }' nozz10
Maybe.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Thu, 18 Dec 1997 13:18:17 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: one liners
Message-Id: <349976F9.2767EFF5@gpu.srv.ualberta.ca>
Kevin Maguire wrote:
!
! How to this in a perl one-liner
!
! replace record 3 of line 10 in file nozz10 with hello:
! head -9 nozz10; head -10 nozz10 | tail -1 | awk '{$3="hello"; print $0}' ; tail +11 nozz10
!
! Must be pretty easy ?! And faster than the above? What about for all
! files (*10) in a one-liner?
one possibility:
perl -lapi -e '$.==10&&($F[2]="hello" and $_="@F");close ARGV if eof' *10
regards
andrew
------------------------------
Date: Thu, 18 Dec 1997 19:49:27 GMT
From: spectd@horus.sara.nl (Neil Burnett)
Subject: Re: Perl editor needed
Message-Id: <34997d17.16312494@news.eunet.be>
On 6 Dec 1997 08:00:22 GMT, syng@jalisco.engr.ucdavis.edu (Michael Ng)
wrotz:
><Previously, Larry Hanlon said he is looking for a Perl editor>
>
>I personally love using Emacs, both in Unix/NT/Win95. I use Emacs in
>almost all of my Programming tasks (except in Visual C++ and some short
>programs -- #line < 10). I am a helpless color-lover. The program
>displayed in NTEmacs is very colorful. comment is green. string is brown
>etc.
>
>Emacs is huge, if you wnat to get the whole package.
>
>Justt my opinion.
>
>--
>Michael (syng@engr.ucdavis.edu)
>+--------------------------------------------------------------+
>| http://www.engr.ucdavis.edu/~syng/ |
>| <PGP public key: http://www.engr.ucdavis.edu/~syng/mike.pgp> |
>+--------------------------------------------------------------+
I just use MS-WORD. The only addition is a word basic script to run
the perl script and save it as .doc and .pl files at the same time.
This means I can use all the editing and formatting of WORD for an
informative display and then just save and run a text only version
when I click on my 'Run Perl script' button. Here it is converted to
Word 97:
Public Sub MAIN()
Dim script$
script$ = WordBasic.[FileName$]()
script$ = WordBasic.[FileNameInfo$](script$, 4)
WordBasic.ChDir "f:\HTTPd\CGI-BIN"
WordBasic.FileSaveAs Format:=2, Name:=script$ + ".pl"
WordBasic.ChDir "f:\CGI-DOC"
WordBasic.FileSaveAs Format:=0, Name:=script$ + ".doc"
WordBasic.ChDir "f:\HTTPd\CGI-BIN"
WordBasic.Shell Environ("COMSPEC") + " /c perl " + "f:\HTTPd\CGI-BIN\"
+ script$ + ".pl >" + "f:\CGI-HTM\" + script$ + ".txt"
WordBasic.MsgBox "The results of this script have been saved as " +
"f:\CGI-HTM\" + script$ + ".txt"
WordBasic.FileOpen Name:="f:\CGI-HTM\" + script$ + ".txt",
ConfirmConversions:=0, ReadOnly:=0, AddToMru:=0, PasswordDoc:="",
PasswordDot:="", Revert:=0, WritePasswordDoc:="", WritePasswordDot:=""
End Sub
Of course, it uses my path names to cgi-bin, cgi-doc and cgi-htm (for
results).
-Regards - Neil
------------------------------
Date: 18 Dec 1997 18:36:57 GMT
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: prototyping
Message-Id: <01bd0be3$ee2dc2a0$3e03b480@mm>
What impact is there in saying:
sub blah ($$\&) { ... }
as opposed to saying:
sub blah ($$$) { ... }
Either way I seem to be able to pass either a valid hard reference or a
simple scalar without raising any complaint. Perhaps I am missing the
general point of prototyping.
Thanks,
--
Phil R Lawrence
Systems and Networking Development Services
Programmer/Analyst
prl2@lehigh.edu
------------------------------
Date: Thu, 18 Dec 1997 10:45:01 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: brian d foy <comdog@computerdog.com>
Subject: Re: Q: limiting the input array size
Message-Id: <Pine.GSO.3.96.971218103913.18763I-100000@user2.teleport.com>
On Thu, 18 Dec 1997, brian d foy wrote:
> i would expect a good CGI program to only read the number of bytes
> specified in CONTENT_LENGTH.
Yes; in fact, the CGI spec specifically states that the server needn't
give an end-of-file indication (endication? :-) after that many bytes.
http://hoohoo.ncsa.uiuc.edu/cgi/interface.html
http://hoohoo.ncsa.uiuc.edu/cgi/in.html
> however, i guess you could make the server wait by not sending as many
> bytes as you said you were going to, hence creating a denial of service
> style attack. oy - i don't think CGI.pm could recover from such a
> thing, but i hestitate to test it.
That's really the server's problem, not CGI.pm's problem. Right?
Good thing you mentioned CGI.pm there. I was starting to be afraid that
this didn't have anything to do with Perl. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Thu, 18 Dec 1997 10:48:00 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: Xah <xah@best.com>
Subject: Re: Q: sorting hash by category
Message-Id: <34996FE0.BB3BF652@sirius.com>
The best way is to create a hash of hashes. This untested
code should give you the idea.
sub cache{
my ($file, $hash) = @_;
my $ext = $file =~ m/\.([^\.]+)$/ ? $1 : '*';
$$hash{$ext}{$file}++;
}
sub print_hash {
my $hash = shift;
foreach $ext (sort keys %$hash) {
my $subhash = $$hash{$ext};
foreach (sort keys %$subhash) {
printf ("%10d", $$subhash{$_});
print "$_\n";
}
}
}
Xah wrote:
>
> Suppose I have a hash like this
>
> # about 1000 pairs.
> %hh = (
> 'wallpaperSmall15.gif' => 1,
> 'mandellaIcon.gif' => 75,
> 'astroidTrammel.fig' => 1,
> 'parabolaReflector.gif' => 6,
> 'nephroidByEnvOfCircleProof.fig' => 1,
> 'mathGraphicsGallery.html' => 17,
> 'invParallel4.gif' => 6,
> 'cardioidParallelTangents.gif' => 7,
> 'pedalCosQuetzal.gif' => 6,
> 'nebula_HeartIcon.gif' => 6,
> 'LimaconGG2_2.gif' => 4,
> 'involuteCircleRainbow.gif' => 1,
> 'deltoidTangent1.gsp' => 2,
> 'newtstalks1.html' => 1,
> 'ellipseGenPointwise.mov' => 1
> );
>
> I want to sort files into categories by extensions then sort them by count
> value. The result should print like this
>
> 75 mandellaIcon.gif
> 7 cardioidParallelTangents.gif
> 6 pedalCosQuetzal.gif
> 6 parabolaReflector.gif
> 6 nebula_HeartIcon.gif
> 6 invParallel4.gif
> 4 LimaconGG2_2.gif
> 1 wallpaperSmall15.gif
> 1 involuteCircleRainbow.gif
>
> 1 astroidTrammel.fig
> 1 nephroidByEnvOfCircleProof.fig
>
> 2 deltoidTangent1.gsp
>
> 17 mathGraphicsGallery.html
> 1 newtstalks1.html
>
> 1 ellipseGenPointwise.mov
>
> What's a *GOOD* way to do it? A guide will do me good. Thanks.
>
> (this script is intended to calc stats of my web log. Yes, I knew about
> Analog and the like.)
>
> Xah, xah@best.com
> http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
> "Perl my ass" (there are more than one way to express love)
------------------------------
Date: Thu, 18 Dec 1997 17:55:46 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Setting an Enviroment Variable in a Web Perl script
Message-Id: <adelton.882467746@aisa.fi.muni.cz>
keefner@visi.com (keefner) writes:
> I want to run a certain program during the exceution of a
> cgi/perl script but it fails. The program runs fine from
> the command line as the same user as the WebServer
> is running as so I think its one of the required enviroment
> vairables.
You do it in a Perl CGI script exactly the same way as in any other
Perl script -- set the value of %ENV hash.
Hope this helps,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: 18 Dec 1997 18:00:43 GMT
From: Eli the Bearded <#@qz.to>
Subject: Re: Sorting Hashes By Value
Message-Id: <eli$9712181234@qz.little-neck.ny.us>
Stephan Vladimir Bugaj <bugaj@bell-labs.com> wrote:
> Other than using a less moronic sorting routine than selection
> sort (like quicksort or insertion sort, which I'm writing right
> now) is there a better way to sort hashes on values than this:
>
> (a better way would be something that took advantage of PERL
> structures to avoid all the function call setups and variable
> foo.)
Um, maybe you want to look at the sorting examples in perlfunc(1)
given while describing the key function?
Here is yet another way to print your environment:
@keys = keys %ENV;
@values = values %ENV;
while ($#keys >= 0) {
print pop(@keys), '=', pop(@values), "\n";
}
or how about sorted by key:
foreach $key (sort(keys %ENV)) {
print $key, '=', $ENV{$key}, "\n";
}
To sort an array by value, you'll need to use a
sort function. Here's a descending numeric sort
of a hash by its values:
foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash)) {
printf "%4d %s\n", $hash{$key}, $key;
}
> (Which very obviously looks like the C code I derived it from,
> my perl often looks like C, sorry)
It is often possible to look at people's perl code and see what other
languagues they fell comfortable in. (I'm comfortable in regexps.)
Elijah
------
perl -e 's Y Yreverse q N ny pm srekcah lrep kroy wen emosNYex and s Pmp ynP
P and s MsMjust sMx and print and s NYPM MPYN Nis or reverse and print q qq'
------------------------------
Date: 18 Dec 1997 18:22:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sorting Hashes By Value
Message-Id: <67bplr$ho6$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Stephan Vladimir Bugaj <bugaj@bell-labs.com> writes:
:Other than using a less moronic sorting routine than selection
:sort (like quicksort or insertion sort, which I'm writing right
:now) is there a better way to sort hashes on values than this:
My God, man! See the FAQ, or my posting of a few days ago
on this matter.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I'm a programmer: I don't buy software, I write it.
--Tom Christiansen
------------------------------
Date: 18 Dec 1997 19:00:35 GMT
From: gt2863a@acmey.gatech.edu (Mark)
Subject: unshift, @INC, require???
Message-Id: <67brsj$jqe@catapult.gatech.edu>
I used to keep everything in one directory and my code
looked as follows
unshift (@INC, "L:\scripts\mec") #directory where everything is
require("Header.pl")
require("OpenFile.pl")
Okay now I moved stuff around to various sub directories.
So I changed the code like this
unshift (@INC, "L:\scripts\mec", "L:\scripts\mec\subs",
"L:\scripts\mec\calendar\");
Now it does not work, how can I let PERL know where everything
is, I thought this would take care of it.
Thanks
--
mec --gt2863a
------------------------------
Date: Thu, 18 Dec 1997 10:30:24 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Steve <syarbrou@ais.net>
Subject: Re: What kind of machine wouldn't support FLOCK?
Message-Id: <Pine.GSO.3.96.971218102917.18763G-100000@user2.teleport.com>
On Thu, 18 Dec 1997, Steve wrote:
> I have done extensive testing of flock on unix systems anyways and
> several systems have it, but only Linux truely seems to support it.
> All the other flavors of UNIX accept the command but do not work.
The vendors of nearly every modern Unix system might have a different
opinion than you on that point. :-)
Can you give an example of a Unix system which has a non-working flock
function?
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 18 Dec 1997 14:23:03 -0500
From: Clark Dorman <clark@s3i.com>
Subject: Re: What kind of machine wouldn't support FLOCK?
Message-Id: <dg1nqxxpk.fsf@s3i.com>
[courtesy cc of this posting sent to cited authors via email]
Tom Christiansen <tchrist@mox.perl.com> writes:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, syarbrou@ais.net (Steve) writes:
> :I have done extensive testing of flock on unix systems anyways and
> :several systems have it, but only Linux truely seems to support it.
> :All the other flavors of UNIX accept the command but do not work.
>
> I cannot contain my disbelief: what was your test? What you're saying
> is exceedingly scary, and to the best of my occasionally splotchy
> memory, contrary to my own empirical checks.
Here is a standalone test that I ran on Solaris 5.4 and 5.5 and Irix
5.3. The resulting file (output.dat) produces an interesting output
file as the forked children wait for the lock, resulting in a
decidedly non-sequential control of the file. However, there do not
appear to be collisions, and the file always ends up with the right
number of lines (50). On a Silicon Graphics Indigo (Irix 5.3), this
takes several minutes to run but is fast on a Sun Sparc 20.
Steve: what happens when you run this program on different machines /
operating systems?
#!/home/dorman/bin/perl -w
#!/usr/bin/perl -w
use Fcntl ':flock';
use strict;
use vars qw( $outfile $i $j $whichchild $iter $kidpid $line );
$outfile = 'output.dat';
# Fork off 10 children.
for ($i=0; $i<10; $i++) {
if ( $kidpid=fork ) {
# this is the parent
print "Forked off child $i, pid=$kidpid\n";
}
else {
# this is the child. Print to it several times.
for ($j=0; $j<5; $j++) {
&tryprint( $i, $j );
}
# Make sure to exit here! Otherwise, it gets ugly!
exit;
}
}
sub tryprint {
local( $whichchild, $iter ) = @_;
# Read it first if it is there
if (-e $outfile) {
open( OUTFILE, $outfile) or
die "Error opening for read. Child $whichchild ($!)";
flock( OUTFILE, LOCK_EX) ;
$line = <OUTFILE>;
close(OUTFILE);
}
# Now append to it
open( OUTFILE , ">>$outfile" ) or
die "Error opening for append. Child $whichchild ($!)";
flock( OUTFILE, LOCK_EX );
print OUTFILE " Child num $whichchild. Iteration $iter\n";
close( OUTFILE );
}
--
Clark Dorman "Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html -Francis Crick
------------------------------
Date: Thu, 18 Dec 97 15:48:49 GMT
From: fred@genesis.demon.co.uk (Lawrence Kirby)
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <882460129snz@genesis.demon.co.uk>
In article <e9k976.8h3.ln@localhost> tadmc@metronet.com "Tad McClellan" writes:
>Mark Framness (framness@EMIRATES.NET.AE) wrote:
>: In message <34958D16.190C@gsg.eds.com> - "Shmuel (Seymour J.) Metz"
>: <nospam@gsg.eds.com>Mon, 15 Dec 1997 12:03:34 -0800 writes:
>: #>
>
>: #>> C provides the needed primitives to do anything you need.
>: #>
>: #>You got this wrong; C does not have the needed primitives to handle
>: #>sets, do string matching, do record-oriented I/O, etc., except in the
>: #>trivial sense that anything can be simultated on anything else.
>
>: What do you mean sets? As in the mathematical sense? String matching? Huh?
>: what do strcmp, strstr etc do?
> ^^^^^^ ^^^^^^
>
>Those are not *primitives* (ie. built-in to the language).
The standard library is built into th C language.
>Those are library calls (ie. add-ons to the language).
No, they are an inherent part of the language. A compiler can't call itself
a hosted C implementation unless it provides the standard library.
>You won't find 'strcmp' in a C compiler's grammar.
True, but irrelevant. There is a lot more to any programming language than
just its grammar. It also works both ways, for example:
void main(double x)
{
char *y = x;
return "OK";
}
is perfectly valid as far as C's grammar is concerned but it isn't remotely
a valid C program.
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
------------------------------
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 1500
**************************************