[12245] in Perl-Users-Digest
Perl-Users Digest, Issue: 5845 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 1 00:07:31 1999
Date: Mon, 31 May 99 21:00:17 -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 Mon, 31 May 1999 Volume: 8 Number: 5845
Today's topics:
hey p5p! Bug w/proto (\@)? <bhuston@eden.com>
How to use svrmgrl commands in Perl CGI <james@guangzhou.sgi.com>
Re: How to use svrmgrl commands in Perl CGI <rootbeer@redcat.com>
Re: Is there a more efficient way of coding this? <uri@sysarch.com>
Re: Perl Newbee <mlikvan@home.com>
Re: Perl Newbee <rootbeer@redcat.com>
Re: Perl Newbee (Randal L. Schwartz)
Re: Perl, Y2K, and idiots <rootbeer@redcat.com>
Re: Perl, Y2K, and idiots (I R A Aggie)
Re: Predefined variable for array number? (Martin Vorlaender)
Re: Problem with opening SOCKET to hypermart <rootbeer@redcat.com>
Problem with Sorting Hash (Ryan Ngi)
Re: Problem with Sorting Hash <dgris@moiraine.dimensional.com>
Re: Quick way to count lines in file? (Tad McClellan)
Re: Quick way to count lines in file? (Fuzzy Warm Moogles)
Re: Shorter solution ? <uri@sysarch.com>
Sorting Problem 2 (Ryan Ngi)
Re: Sorting Problem 2 <walton@frontiernet.net>
Re: Sorting Problem 2 <rootbeer@redcat.com>
Re: Sorting Problem 2 <uri@sysarch.com>
Re: the unshift function <rootbeer@redcat.com>
Re: the unshift function <dgris@moiraine.dimensional.com>
Re: Too many arguments... (Apache/mod_perl) <walton@frontiernet.net>
Re: Y2K infected Perl code <uri@sysarch.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 Jun 1999 02:17:32 GMT
From: Bill Huston <bhuston@eden.com>
Subject: hey p5p! Bug w/proto (\@)?
Message-Id: <0pH43.2137$T7.165628@typhoon-sf.snfc21.pbi.net>
Ok, not a bug, because it's documented to work the way that
it does. But it draws a distinction between a generalized
list and an array not seen in most of perl. (my perl -V is
below... I'm at 5.004_04 and building 5.005_03 as I speak...)
I have a subroutine that needs be passed in 2 arrays/lists.
(I *really* like the "named parameter" recipe from the
Cookbook: 10.7 (thanks Tom and Nat!), but I need to pass
in another list, too)
The perlfunc's that take a list argument, all accept these
interchangably:
1. array
2. literal list
3. sub() which returns a list
4. perlfunc which returns a list
Examples:
print join (":", @list); #1
print join (":", ret_list(function)); #2
print join (":", qw(literal list)); #3a
print join (":", ("literal", "list2"); #3b
print join (":", keys %h); #4
Cool! One of the many ways that Perl rules...
There is now a way with prototyping which allows for some
magical behavior... one can now pass an array to a sub, but
if you proto it with (\@), it magically becomes an array
reference! This could be marvelous, but it seems to be
inconsistant at 5.004_04, as it *only* works for arrays,
and not for any other kinds of lists. (Yes, I know it's
documented to work this way...)
While this works exactly like the perlfunc "join":
sub myjoin ($@) {
return join (shift, @_);
}
This requires an array for parameter 2, and produces a compiler
error on cases 2-4 above:
sub myjoin2 ($\@) {
my $delim=shift;
my $aref=shift;
return join ($delim, @{$aref});
}
If this could be made consistant (prototype magically gives the sub
a reference, even though the sub is called with something list-like),
it would be wonderous! I could then do something I need to do: create
a sub() which gets passed multiple lists and keep them straight:
mysub ( @a1, @opts ); # array
mysub ( (1,2,3), @opts); # literal list
mysub ( returns_list(), @opts); # sub() returns list
mysub ( keys %h, @opts); # perlfunc returns list
I can't find a way to (cleanly) do this now.
Q: Wouldn't it be more useful to have a prototype of (\@) give the
sub a generalized list reference, in order to be able to better
match builtin behavior?
Q: Is it possible to do this??
Thanks,
Bill
bhuston@eden.com
--------------- my "perl -V" -----------------------------------
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
Platform:
osname=linux, osvers=2.0.29, archname=i486-linux
uname='linux mu 2.0.29 #10 wed feb 12 01:11:40 cst 1997 i486 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=n useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=2.7.2.1
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
libc=/lib/libc.so.5.4.23, so=so
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under linux
Compiled at Aug 25 1998 21:45:46
@INC:
/usr/lib/perl5/i486-linux/5.00404
/usr/lib/perl5
/usr/lib/perl5/site_perl/i486-linux
/usr/lib/perl5/site_perl
.
--
Bill Huston bhuston@eden.com http://mu.clarityconnect.net
"Drug-Free School Zone? Big LIE! Just an excuse to bust hippies
down the street. If they were committed to the concept, they'd
ban Ritalin and Pepsi!" -- Will Freedom!, _Live in Dunellen_
------------------------------
Date: Tue, 1 Jun 1999 10:27:31 -0000
From: "James Liang" <james@guangzhou.sgi.com>
Subject: How to use svrmgrl commands in Perl CGI
Message-Id: <7ivgf2$hur9s@fido.engr.sgi.com>
Hi,
We have a problem trying to use svrmgrl commands in a Perl CGI script:
#! /usr/bin/perl5
print "Content-type: text/html\n\n";
$ENV{'ORACLE_HOME'} = '/ora7/app/oracle/product/7.3.4';
$ENV{'ORACLE_SID'} = 'mydb';
`/ora7/app/oracle/product/7.3.4/bin/svrmgrl <<EOF > /tmp/log10
connect internal;
select * from dba_users;
EOF`;
print "SUCCESS!";
This script runs correctly from command-line, but if we try to run it as
CGI, the following error is logged in /tmp/log10:
Oracle Server Manager Release 2.3.4.0.0 - Production
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release 7.3.4.0.0 - Production
PL/SQL Release 2.3.4.0.0 - Production
SVRMGR> MGR-11401: input error, unable to read input line
MGR-01508: unable to close the current file
It seems that svrmgrl cannot get the input. How can I make it work as a CGI
program ?
We are using Perl 5.005_02 for irix-n32, Oracle 7.3.4, and Netscape
SuiteSpot Enterprise server 3.5.1 on SGI Irix 6.2. The web server runs as
nobody (we've added nobody to DBA group temporarily for the testing).
Regards,
James Liang
------------------------------
Date: Mon, 31 May 1999 20:16:28 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: How to use svrmgrl commands in Perl CGI
Message-Id: <Pine.GSO.4.02A.9905312013330.19186-100000@user2.teleport.com>
On Tue, 1 Jun 1999, James Liang wrote:
> This script runs correctly from command-line, but if we try to run it
> as CGI,
> It seems that svrmgrl cannot get the input. How can I make it work as
> a CGI program ?
>
> We are using Perl 5.005_02 for irix-n32, Oracle 7.3.4, and Netscape
> SuiteSpot Enterprise server 3.5.1 on SGI Irix 6.2. The web server runs as
> nobody (we've added nobody to DBA group temporarily for the testing).
I've got a hunch that user 'nobody' still doesn't have proper authority to
get the data you need. If you're able to 'su nobody' and run the program,
you may be able to find out whether this is the case. You may need to make
a set-uid program in order to get this to work; see the perlsec manpage.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.
http://www.perl.com/CPAN/
http://www.perl.org/CPAN/
http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
http://www.perl.org/CPAN/doc/manual/html/pod/
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 31 May 1999 23:45:32 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Is there a more efficient way of coding this?
Message-Id: <x7yai4eg83.fsf@home.sysarch.com>
>>>>> "r" == rbbdsb <rbbdsb@erols.com> writes:
r> I'm extracting a series of lines between two patterns, parsing the
r> values out, and stuffing them into Oracle. Is there a more
r> efficient way of doing this?
it seems reasonably speedy to my eyes.
r> while (<InputFile>) {
r> # extents
r> if (/Owner/ .. /System/) {
r> next if(/Owner/);
r> next if(/--/);
r> next if(/System/);
r> tr/,//d;
r> ($ignore, $owner, $object, $type, $tablespace, $sizekb, $blocks,
r> $extents, $maxextent, $nextextentsize) = split(/\s*\|\s*/);
r> }
since you are in the Owner/System section, put a next there so you don't
also check for the next section. in general when using .. like this end
your if block with a next.
one trick i use with .. is to save the range line number and use it to
see if i have the first/last lines of the range. many times i have to do
special processing then.
if ( $range = /Owner/ .. /System/) {
next if $range == 1 ;
next if $range =~ /e/ ;
next if(/--/);
note that the last line number in range is in float notation with an
exponent. this is the only way to tell it is the last line using the
line number.
r> # DB backup
r> if (/Backup function/ .. /^$/) {
r> next if(/Backup/);
r> next if(/--/);
r> next if(/^$/);
r> ($ignore, $backupfunction, $startbackup, $endbackup,
r> $returncode, $detaillog) = split(/\s*\|\s*/);
r> }
r> }
that closes the while loop. why aren't you processing each of the lines
you split when in the if blocks? the code below will only process the
last line in each range.
r> $inserth = $dbh->prepare("INSERT INTO extents(owner, object, type,
r> tablespace, sizekb, blocks, extents, maxextent, nextextentsize)
r> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
r> $inserth->execute($owner, $object, $type, $tablespace, $sizekb,
r> $blocks, $extents, $maxextent, $nextextentsize);
r> $inserth = $dbh->prepare("INSERT INTO dbbackup(backupfunction, startbackup,
r> endbackup, returncode, detaillog VALUES (?, ?, ?, ?, ?)");
r> $inserth->execute($backupfunction, $startbackup, $endbackup, $returncode,
r> $detaillog);
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 01 Jun 1999 02:43:46 GMT
From: Mike Likvan <mlikvan@home.com>
Subject: Re: Perl Newbee
Message-Id: <37536490.F426F92D@home.com>
Ronald J Kimball wrote:
>
> Mike Likvan <mlikvan@home.com> wrote:
>
> > Can anyone help me sort out these questions?
>
> Not without seeing the code.
Really? You'd need to see the code even for the
question of "what needs to be set up/loaded on a
server in order to make sure Perl scripts run"?
Isn't there a standard operating environment and
settings (e.g. setting "GET" AND "POST" on the server)?
Stuff like that? I can understand the need for code
for question #1, but number 2...?
Maybe I'm just in the wrong ng. Is there one more
specific to internet web work?
Thanks,
Mike
------------------------------
Date: Mon, 31 May 1999 20:20:17 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl Newbee
Message-Id: <Pine.GSO.4.02A.9905312016550.19186-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Mike Likvan wrote:
> Maybe I'm just in the wrong ng. Is there one more
> specific to internet web work?
Oodles. Start with the ones in the comp.infosystems.www.* hierarchy.
Cheers!
http://dir.yahoo.com/Computers_and_Internet/Internet/World_Wide
_Web/Usenet/
http://sunsite.unc.edu/boutell/faq/ngroups.htm
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 31 May 1999 20:23:57 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl Newbee
Message-Id: <m13e0ca9iq.fsf@halfdome.holdit.com>
>>>>> "Mike" == Mike Likvan <mlikvan@home.com> writes:
Mike> Maybe I'm just in the wrong ng. Is there one more
Mike> specific to internet web work?
As a matter of fact, yes. comp.infosystems.www.authoring.cgi
How could you miss it with a name that contains both 'www' and 'cgi'? :)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 31 May 1999 19:49:23 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl, Y2K, and idiots
Message-Id: <Pine.GSO.4.02A.9905311936210.19186-100000@user2.teleport.com>
On Mon, 31 May 1999, Kristina wrote:
> > http://language.perl.com/style/
>
> Thanks, it's a great reference! I wonder, however, if someone would
> be kind enough to explain the following for me and the benefit of those
> who might, like me, also be newbies or "accidental programmers":
>
> * Check $@ after eval"" or s///ee.
> * Parameter asserts
>
> I understand "check $@ after eval" but what is s///ee?
See perlfaq4's answer to "How can I expand variables in text strings?".
The explanation, such as it is, is in the description of s/// in perlop.
I _think_ that the advice to check $@ after s///ee only applies to
5.005(?) and later - my experiments with 5.004 (the most recent I have
available at the moment) don't show that s///ee puts anything useful into
$@, unless I've goofed somewhere (which is quite possible). In any case,
it's better to simply avoid s///ee altogether, and then you don't have to
worry about checking $@. :-)
> Also, could you (or someone else) elaborate just a tiny bit on what is
> implied by "Parameter asserts?"
I think that this is just a highfalutin way of saying "Make sure your
subroutine parameters are reasonable." If someone asks for the square root
of a negative number, don't dump core. Conversely, if you're about to get
the square root of a number that could conceivably be negative, check it
(or wrap it in an eval block).
Happy coding!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jun 1999 03:23:24 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Perl, Y2K, and idiots
Message-Id: <slrn7l6kne.7b3.fl_aggie@thepentagon.com>
On Mon, 31 May 1999 17:20:50 -0700, Kristina <kristina@greatbasin.net>, in
<Pine.BSI.4.05L.9905311658100.25771-100000@web0.greatbasin.net> wrote:
+ As a relative Perl newbie (who will probably be a newbie all my life!), I
+ just feel like I'm not even allowed to write Perl scripts until I'm a
+ Randall Schwartz or a Tom Christiansen.
If that's how you feel...then go to you favorite bookstore that stocks
O'Reilly books, pick up the Llama book (Learning Perl, Schwartz and
Christiansen) and read the Foreward. If my memory is correct, Larry
Wall states something akin to: learn what you need to of perl. A
knowledge of a subset that accomplishes what you need accomplished
is adequate.
+ Okay, blah blah blah. Yes, I'm trying to justify my existence. Does
+ it show? :)
Just remember that when you ask for clarification on something you
should phrase your question like this: The docs say that if I use
X on Y, I should get Z, but I get A instead. Why? here's my code
snippet that demonstrates my dilema...
+ Anyone have a URL for good Perl programming style over and above where one
+ should put the whitespace and the curly brackets?
'perldoc perlstyle'??
James
------------------------------
Date: Tue, 01 Jun 1999 04:38:37 +0200
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Predefined variable for array number?
Message-Id: <375347ad.524144494f47414741@radiogaga.harz.de>
.. (none@none.ca) wrote:
: Is there an array equivalent of the $. variable for files. i.e. A variable
: which tells you what array number you are currently at.
:
: ex: Pretending that this variable was named $array_num:
:
: @array = (a b c d);
:
: foreach $x (@array) {
: print $array_num\n;
: }
No there isn't. But (as you already figured out) it's easy to have an index
variable running along. The continue block is well fitted for something
like this:
$array_num = 0;
foreach $x (@array) {
print "$array_num\n";
}
continue { ++$array_num }
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
VMS is today what | work: mv@pdv-systeme.de
Microsoft wants | http://www.pdv-systeme.de/users/martinv/
Windows NT 8.0 to be! | home: martin@radiogaga.harz.de
------------------------------
Date: Mon, 31 May 1999 19:22:03 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Problem with opening SOCKET to hypermart
Message-Id: <Pine.GSO.4.02A.9905311919010.19186-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Ryan Ngi wrote:
> i try this code to retrive data from
>
> http://topearth.hypermart.net/thai.html
>
> use IO::Socket;
Why not LWP? That's a lot simpler and easier to get correct.
> $sock = new IO::Socket::INET(PeerAddr => "topearth.hypermart.net",
> PeerPort => 80);
> print $sock "GET /thai.html / HTTP/1.0\n\n";
And as we see here, you haven't obeyed the protocol (as I understand it).
Of course, this isn't the appropriate place to discuss the details of the
protocol. But I think you should use LWP and your problems will disappear.
Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jun 1999 01:42:35 GMT
From: ryanngi@hotmail.com (Ryan Ngi)
Subject: Problem with Sorting Hash
Message-Id: <375339d6.4543876@news.inet.co.th>
if execute
%HASH=( 'dang'=>5,'dum'=>3,'kaw'=>7);
print %HASH;
it print
dang5kaw7dum3
but why not print "dang5dum3kaw7"??
how does hash arrange itself when it assign???
i'm suspect this for along time....
------------------------------
Date: 31 May 1999 20:50:55 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Problem with Sorting Hash
Message-Id: <m3pv3gskfk.fsf@moiraine.dimensional.com>
ryanngi@hotmail.com (Ryan Ngi) writes:
<snip>
> how does hash arrange itself when it assign???
Hashes are inherently unordered. If you need ordered
access to your data use an array.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Mon, 31 May 1999 17:35:48 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Quick way to count lines in file?
Message-Id: <kbvui7.883.ln@magna.metronet.com>
Benevo Lence (seeu@theasylum.com) wrote:
: > I need to put data into an array but i don't know the file size (in
: > lines) in advance.
: > Is there a quick/smart way of getting this information or do i have to
: > read every line and use a counter?
: @array = <FILEHANDLE>;
: $#array # will contain the number of lines
No it won't:
-----------------------
#!/usr/bin/perl -w
use strict;
my @array = <DATA>;
print "there are $#array lines\n";
__DATA__
one
two
three
four
five
-----------------------
output:
there are 4 lines
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 01 Jun 1999 03:08:35 GMT
From: tgy@chocobo.org (Fuzzy Warm Moogles)
Subject: Re: Quick way to count lines in file?
Message-Id: <37534a72.103801752@news.oz.net>
On Mon, 31 May 1999 18:07:56 -0700, lr@hpl.hp.com (Larry Rosler) wrote:
>In article <3753c8d1.70611184@news.oz.net> on Mon, 31 May 1999 17:57:39
>GMT, Fuzzy Warm Moogles <tgy@chocobo.org> says...
>> On Mon, 31 May 1999 15:02:23 +0200, Marian Kelc
>> <marian.kelc@ruhr-uni-bochum.de> wrote:
>> >> Is there a quick/smart way of getting this information or do i have to
>> >> read every line and use a counter?
>> >
>> >while( <FILEHANDLE> ) { push @a, $_; ++$i }
>>
>> @a = <FILEHANDLE>;
>> $i = @a;
>
>Neither of those is quick nor particularly smart. The really smart way
>is to RFFAQ. perlfaq5: "How do I count the number of lines in a file?"
The original poster was putting the data into an array, so an array in scalar
context is as quick and smart as anything. As for the FAQ, excellent work.
I enjoy reading the FAQ, the documentation, the FMTEYEWTK articles, and
sometimes even this newsgroup:
perl -lwpe "}$_=$.;{" file
--
Fuzzy | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: 31 May 1999 23:20:25 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Shorter solution ?
Message-Id: <x71zfwfvye.fsf@home.sysarch.com>
>>>>> "FWM" == Fuzzy Warm Moogles <tgy@chocobo.org> writes:
FWM> This should work the same. IOW, also UNTESTED.
FWM> my %fh = (
FWM> X4 => \*DATA ,
FWM> XY => \*DATA_XY ,
FWM> UP => \*XY_Z ,
FWM> DOWN => \*F2_DATA ,
FWM> MP => \*LS ,
FWM> C4 => \*XYZ ,
FWM> );
FWM> if ($in_file_name =~ /(X4|XY|UP|DOWN|MP|C4)/) {
FWM> my $fh = $fh{$1};
FWM> print OUTFILE while <$fh>;
FWM> close $fh;
FWM> }
why duplicate the tokens in the regex? this is more flexible as you can
add/delete hash entries without editing the regex.
(untested as per thread)
$token_re = join( '|', keys %fh ) ;
if ($in_file_name =~ /($token_re)/) {
if this doesn't change around, no /o option is needed.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 01 Jun 1999 02:07:14 GMT
From: ryanngi@hotmail.com (Ryan Ngi)
Subject: Sorting Problem 2
Message-Id: <37533f51.5946440@news.inet.co.th>
give
%HASH=( 'aim'=> 9, 'james' =>5 , 'cameron' => 7);
how to sort by values and return keys after sorted.
Here, I suppose for output "aim,cameron,james";
could anyone show me?
------------------------------
Date: Mon, 31 May 1999 23:21:47 -0400
From: Bob Walton <walton@frontiernet.net>
To: Ryan Ngi <ryanngi@hotmail.com>
Subject: Re: Sorting Problem 2
Message-Id: <375351CA.7E0C6322@frontiernet.net>
Ryan, you're not very clear about exactly what you want. I think you
want to sort by keys, not by values, and return the sorted keys along
with their values? Here is one way to do that:
%hash=( 'aim'=> 9, 'james' =>5 , 'cameron' => 7);
for(sort keys %hash){
print "key $_, value $hash{$_}\n";
}
This generates:
H:\Bob\junk>perl junk3.pl
key aim, value 9
key cameron, value 7
key james, value 5
H:\Bob\junk>
Is that what you want?
Ryan Ngi wrote:
> give
>
> %HASH=( 'aim'=> 9, 'james' =>5 , 'cameron' => 7);
>
> how to sort by values and return keys after sorted.
>
> Here, I suppose for output "aim,cameron,james";
>
> could anyone show me?
------------------------------
Date: Mon, 31 May 1999 20:21:14 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Sorting Problem 2
Message-Id: <Pine.GSO.4.02A.9905312020360.19186-100000@user2.teleport.com>
On Tue, 1 Jun 1999, Ryan Ngi wrote:
> how to sort by values and return keys after sorted.
Have you seen what the FAQ and manpages have to say about this? If you
still have questions after you've read that information, please post
again. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 31 May 1999 23:52:29 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting Problem 2
Message-Id: <x7u2ssefwi.fsf@home.sysarch.com>
>>>>> "RN" == Ryan Ngi <ryanngi@hotmail.com> writes:
RN> give
RN> %HASH=( 'aim'=> 9, 'james' =>5 , 'cameron' => 7);
RN> how to sort by values and return keys after sorted.
RN> Here, I suppose for output "aim,cameron,james";
RN> could anyone show me?
this is an FAQ and a very F one at that. please try to read all of it as
it will amswer many of you perl questions before you ever have a change
to aks them. the perl FAQ comes with your perl system or you can find it
at www.perl.com
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 31 May 1999 19:18:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: the unshift function
Message-Id: <Pine.GSO.4.02A.9905311912210.19186-100000@user2.teleport.com>
On Mon, 31 May 1999, Kevin Howe wrote:
> unshift @this;
You've told Perl that you wish to add zero items to the beginning of the
array @this. Perl has obliged. @this is now zero items longer than it was
before. Don't say that Perl isn't giving you what you asked for! :-)
If you wish to add some items, you'll need to tell Perl what those items
are.
unshift @this, qw{ These new items };
You seem to be confused because shift doesn't need (and can't take) any
additional parameters after the array name, as unshift does. If you shift
something off, though, you can unshift something on.
my $something = shift @this;
unshift @this, $something;
Those two statements don't necessarily leave @this in the same state it
was before. If it was empty before, now it has one item.
See the perlfunc manpage for more information on shift and unshift. It can
be useful to contrast them with push and pop.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 31 May 1999 20:33:34 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: the unshift function
Message-Id: <m3vhd8sl8h.fsf@moiraine.dimensional.com>
"Kevin Howe" <khowe@performance-net.com> writes:
> The perl manual says the unshift function is, obviously enough, the
> opposite of the shift function. If so, then why does the following code not
> affect the array at all, whereas the same code using shifts instead of
> unshifts would decrease the size of the array?
>
> @this = (one,two,three);
> print scalar(@this) . "," . "@this" . "\n";
> unshift @this;
> print scalar(@this) . "," . "@this" . "\n";
unshift @this, qw(what did you expect to happen?);
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Mon, 31 May 1999 23:58:19 -0400
From: Bob Walton <walton@frontiernet.net>
To: Tomas Pihl <tomas.pihl@ericsson.com>
Subject: Re: Too many arguments... (Apache/mod_perl)
Message-Id: <37535A5B.E8E64F5E@frontiernet.net>
Tomas, I wonder if passing your hash by reference rather than value would fix the problem? Like:
dofind(\%FORM);
...
sub dofind{
my($FORMref)=@_;
my $mail=$$FORMref{email};
...
}
Passing the hash the way you do causes it to actually be passed as a list, and then reassembled back into a hash (and, fortunately, you only have one argument, or it wouldn't
work!). Passing by reference might be more efficient, too.
Tomas Pihl wrote:
> I've got a mod_perl script and each time I change it and it's
> recompiled I have to restart Apache because it goes berzerk.
>
> In apache/logs/error_log I get:
>
> httpd: [Mon May 31 08:55:56 1999] [error] Too many arguments for Apache::ROOT::roomDude::room_2epl::dofind at /local/web/apache/htdocs/roomDude/room.pl line 49, near "%FORM)"
>
> 48: } elsif ($FORM{op} eq "Search") {
> 49: dofind(%FORM);
> 50: } elsif ($FORM{op} eq "finduser") {
> 51: finduser();
>
> sub dofind()
> {
> my (%FORM) = @_;
> my $mail = $FORM{email};
> .
> .
> .
> }
>
> I just can't figure out what's wrong.
>
> ---
> Tomas Pihl
> [add ihl after .p to reply]
------------------------------
Date: 31 May 1999 23:14:20 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Y2K infected Perl code
Message-Id: <x76758fw8j.fsf@home.sysarch.com>
>>>>> "K" == Kristina <kristina@greatbasin.net> writes:
K> On 31 May 1999, Uri Guttman wrote:
>> there are hundreds (thousands?) of perl scripts on these archive
>> sites. most are not fixable but need rewriting from the ground up. in
>> fact many don't even have clear specs about what they actually are
>> doing. the fact they they seem to work is enough for most lusers.
K> Big companies who can afford it hire programmers. Small businesses,
K> schools, charities, and individuals are just happy to find something that
K> works for them. If they do find something that works for them, and
K> it's not as well-written as it should be, nonetheless it fulfills a need,
K> so how can that be bad?
it is bad because it propogates bad code like a virus. when these groups
need to actually fix a bug (if they ever notice them) or make changes,
they come here and bombard us with "wwwboard is broken. why don't you
fix it for me?" we get complaints here about those scripts on a regular
basis and it gets annoying. so people are free to use them but caveat
emptor. they are distributed with no support and the authors typically
code and run. do you know that matt's scripts haven't changed one iota
in years. he makes money by selling books about them, has ads on his
website and he doesn't even bother to fix or upgrade them. forget about
actually writing some new ones using modules and good perl code.
another bad aspect is that all the newbies who want to do cgi find these
scripts and think this is the way to do cgi. so the cut and paste their
way to cgi heaven and their bosses (or more likely themselves) think it
is cool. the fact that they will break under load (no locking), do cgi
incorrectly (wait till they try to do a complex form), etc. is not even
known to them. if the sites were to have disclaimers which say this code
is old and rotten and use at your own risk, it would help a little. or
some sort of reviews by people who know perl, on which scripts are
decent would be nice. just archiving them all without judging them is a
waste. some sites i have seen just do that, collect cgi scripts and
don't care about what is in them. i would love to find cgi.pm used in
ANY of those public scripts. but i can't grep them nor do i want to
download the whole site (though that might be an interesting project for
research and writing to the authors that their code sux).
as for hiring programmers, that is a problem. you want programming, you
hire a programmer. i wonder if the cosource and other new programming
for public money project will work. that is a good way to get many of
these rewritten. if many people each want to pay a small amount for
someone to develop good cgi scripts for common needs, that would be a
big win. a new site could be created (maybe under cpan? but that has
been discussed before with no great resolution), which is for quality
perl scripts including cgi ones. i hope these new open source code
exchange ventures work. i like the idea. maybe someday i will put out some
projects and ask for bids.
'nuff said.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5845
**************************************