[10657] in Perl-Users-Digest
Perl-Users Digest, Issue: 4249 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 18 16:07:23 1998
Date: Wed, 18 Nov 98 13:00:22 -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 Wed, 18 Nov 1998 Volume: 8 Number: 4249
Today's topics:
Re: /g modifier: why not 'last' out of while loop? (John Klassa)
Re: 500 server error (Matthew Bafford)
Accessing Cookies bsethi@p21.com
Re: Accessing Cookies (K. Krueger)
Re: Base64 encoding problem... <rootbeer@teleport.com>
Re: CPU time with NT (Larry Rosler)
Re: How to access a file within a perl program (Larry Rosler)
Re: Log Munging (Larry Rosler)
make test failure, Net::SSLeay.pm on Solaris 2.4 fwh01@health.state.ny.us
Need equivalent to a sh's export command. (Thomas Jordan)
Re: Need equivalent to a sh's export command. (I R A Aggie)
Re: Perl Usage Survey - interpretations, anyone? <jdporter@min.net>
Re: Perl Usage Survey - interpretations, anyone? <eashton@bbnplanet.com>
Re: Perl Usage Survey - interpretations, anyone? <uri@fastengines.com>
Re: Perl Usage Survey - interpretations, anyone? (Adam Turoff)
Re: Perl Usage Survey - interpretations, anyone? (Adam Turoff)
Re: Perl Usage Survey - interpretations, anyone? (Adam Turoff)
Re: Q: bulk-assign associative array? <r28629@email.sps.mot.com>
Re: Q: bulk-assign associative array? (Andre L.)
Re: Q: bulk-assign associative array? <uri@fastengines.com>
Re: Q: bulk-assign associative array? droby@copyright.com
Re: required fields <cici@erols.com>
Re: required fields dturley@pobox.com
Re: reverse comma operator in the camel <rootbeer@teleport.com>
Re: reverse comma operator in the camel <tchrist@mox.perl.com>
Re: Scope question for Perl <jdporter@min.net>
selective list assignment? <marty@catnmoose.com>
Re: Sounds easy when I type it fast <rootbeer@teleport.com>
Re: test for.t failure due to bad rounding <rootbeer@teleport.com>
Re: Two-Part RE question <uri@fastengines.com>
Re: writing to file on winnt perl cgi <ac212@cam.ac.uk>
Re: writing to file on winnt perl cgi (Matthew Bafford)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Nov 1998 19:01:29 GMT
From: klassa@aur.alcatel.com (John Klassa)
Subject: Re: /g modifier: why not 'last' out of while loop?
Message-Id: <72v5i9$b3b$1@aurwww.aur.alcatel.com>
On Wed, 18 Nov 1998 14:23:23 GMT, J.D. Laub <jdl@iasi.com> wrote:
> I don't understand something in the Cookbook. From pg. 170:
> [To find the Nth match in a string,]
> Why can't a 'last' be used to bail out of the loop?
I think the point is that you shouldn't try to "last" out of the loop and
*then* print "The third fish is a $1 one.\n" because $1 isn't meaningful
outside the scope of the "while". Now, if you want to print the value
inside the "while" and *then* "last" out, you're okay...
--
John Klassa / Alcatel / Raleigh, NC, USA / $perl_monger{Raleigh}[0] / <><
------------------------------
Date: Wed, 18 Nov 1998 15:49:04 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: 500 server error
Message-Id: <MPG.10bcf850505d1b19989719@news.scescape.net>
In article <3652EB4E.1438@erase.courrier.usherb.ca>, JTJ
<jtjohnston@erase.courrier.usherb.ca> pounded in the following:
=> Matthew Bafford wrote:
=> >
=> > In article <36523476.4AA6@erase.courrier.usherb.ca>, JTJ
=> > <jtjohnston@erase.courrier.usherb.ca> pounded in the following:
=> > => perl -w file.pl
=> > => perl -w file.cgi
=> > =>
=> > => These will run your perl debugger.
^^^^^^^^
[snip my questioning that]
=>
=> No I mean:
=> perl -c file.pl
=> perl -c file.cgi
=> perl -w file.pl
=> perl -w file.cgi
<following from perlrun>
-c
causes Perl to check the syntax of the script and then exit without
executing it. Actually, it will execute BEGIN, END and use blocks,
because these are considered as occurring outside the execution of
your program.
-w
prints warnings about variable names that are mentioned only once,
and scalar variables that are used before being set. Also warns
about redefined subroutines, and references to undefined filehandles
or filehandles opened read-only that you are attempting to write on.
Also warns you if you use values as a number that doesn't look like
numbers, using an array as though it were a scalar, if your
subroutines recurse more than 100 deep, and innumerable other
things.
You can disable specific warnings using __WARN__ hooks, as described
in perlvar and perlfunc. See also perldiag and perltrap.
-d
runs the script under the Perl debugger. See perldebug.
</>
=> Unix AIX RS-6000 Server.
Musta messed with the source code...
HTH,
--Matthew
------------------------------
Date: Wed, 18 Nov 1998 20:04:37 GMT
From: bsethi@p21.com
Subject: Accessing Cookies
Message-Id: <72v987$kua$1@nnrp1.dejanews.com>
I'm trying to parse two cookies from within the same perl script. i am using
HTTP_COOKIE to get the first one but am not sure what to do to get the second
cookie.
thank you in advance for your help.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 18 Nov 1998 12:21:59 -0800
From: kirbyk@best.com (K. Krueger)
Subject: Re: Accessing Cookies
Message-Id: <72va97$hh7$1@shell2.ba.best.com>
In article <72v987$kua$1@nnrp1.dejanews.com>, <bsethi@p21.com> wrote:
>I'm trying to parse two cookies from within the same perl script. i am using
>HTTP_COOKIE to get the first one but am not sure what to do to get the second
>cookie.
>thank you in advance for your help.
>
You really ought to consider using the CGI module - it makes this really
quite easy. And, as a bonus, descriptions (with code samples!) are spelled
out nicely in the docs (perldoc cgi). It's a pretty good discussion, and
quite probably is already on your machine.
--
Kirby Krueger O- kirbyk@best.com
<*> "Most .sigs this small can't open their own jump gate."
------------------------------
Date: Wed, 18 Nov 1998 20:46:56 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Base64 encoding problem...
Message-Id: <Pine.GSO.4.02A.9811181246030.27321-100000@user2.teleport.com>
On Wed, 18 Nov 1998, The Corruptor wrote:
> My problem is that this code will only generate a few bytes of encoded
> data
> I'm running a freshly installed NT4.0
binmode? Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 18 Nov 1998 11:12:32 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: CPU time with NT
Message-Id: <MPG.10bcbbfee3c6afcf98987c@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <72uqr7$lpc$1@news.pt.lu> on Wed, 18 Nov 1998 16:57:53 +0100,
POIREL Thomas <thomas_poirel@crediteurop.lu> says...
>
> How can get CPU time in my Perl process with NT machine ?
>
> Times does not work with NT !!!
#!perl -w
use strict;
my @t0 = times;
print "@t0\n";
for (my $i = 0; $i < 1_000_000; ++$i) { }
my @t1 = times;
print "@t1\n";
__END__
d:/mksnt/mksnt/sh.exe -c "perl e:/test/try.txt"
0.031 0.031 0 0
2.125 0.031 0 0
Press any key to close this window...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 18 Nov 1998 11:05:28 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to access a file within a perl program
Message-Id: <MPG.10bcba5712e68f8d98987b@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <72udrk$oc9$6@inf2.informatik.uni-stuttgart.de> on 18 Nov
1998 12:16:52 GMT, Christian Harms <harms@rupert.informatik.uni-
stuttgart.de> says...
> Murali Kanaga <mkanaga@hotmail.com> wrote:
> > ... I have to write a perl program which will search through
> > the /etc/group file. When I type a user name (jdoe), the script will go
> > through /etc/group file & find out which group jode is in.
> >
> > In order to do this, how can I read the file /etc/group from my perl script.
...
> foreach $i (grep(/$user/,`cat /etc/group`))
> {
> ($i,$u)=split(/::/,$i);
> print "$i\n";
> }
Why would one want to spawn an external process to read a file, which is
a capability fundamental to Perl? Also, that code will find undesired
users such as 'xjdoey'.
open GROUPS, '/etc/group/' or die "Couldn't open /etc/group. $!\n";
while (<GROUPS>) {
next unless /^${user}::(.*\n)/;
print $1;
last;
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 18 Nov 1998 12:46:32 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Log Munging
Message-Id: <MPG.10bcd2058f56fdd798987d@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <72v467$rh3$1@autumn.news.rcn.net> on Wed, 18 Nov 1998
13:40:03 -0500, Ci-Ci Mills <cici@erols.com> says...
> I am TRYING to write some custom web server log statistic scripts. The
> first one is supposed the report the top 20 searches per day. I built a
> hash that contains the date, keyword and the count for that keyword. To get
> the top 20 keywords, I need to sort by the count....this is where I am
> running into problems.
>
> This is how I am populating the hash:
>
> if ($url =~ m|.*?query\=?(.*?)\&|) {
If you are looking for a count to sort by, it is better to guarantee
that what you find is a sequence of digits (I have cleaned up several
irrelevancies):
if ($url =~ /query=?(\d*)&/) {
> $keyhash{$dt} = $1 unless (($keyhash{$dt}) || ($1 eq ""));
> $keyhash{$dt}{$1} = $keyhash{$dt}{$1} + 1;
You don't want to set the value to a number and then use it as a hash
reference. My guess is that you want to set it to a reference to an
anonymous hash:
$keyhash{$dt} = {} unless (($keyhash{$dt}) || ($1 eq ""));
But you don't need to do that in any case, because the anonymous hash
will be created if it doesn't exist ('autovivified'):
++$keyhash{$dt}{$1};
> }
>
> This is how I am printing out the hash:
>
> foreach $datetime (sort keys %keyhash) {
> print "$datetime\n";
> foreach $wd (sort keys %{$keyhash{$datetime}}) {
You have specified an alphanumeric sort on the keys, which is not what
you want for numbers.
foreach $wd (sort { $a <=> $b } keys %{$keyhash{$datetime}}) {
> print "$title\t$keyhash{$datetime}{$wd}\n";
> }
> }
Not tested, because I don't have your data.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 18 Nov 1998 19:00:57 GMT
From: fwh01@health.state.ny.us
Subject: make test failure, Net::SSLeay.pm on Solaris 2.4
Message-Id: <72v5gt$hej$1@nnrp1.dejanews.com>
Trying to install Net::SSLeay.pm 1.02
SSLeay-0.9.0 was installed before installation attempt for Net::SSLeay.pm
This is what happens with 'make test'
PERL_DL_NONLAZY=1 /usr/bin/perl -I./blib/arch -I./blib/lib
-I/usr/local/lib/perl 5/sun4-solaris/5.00404 -I/usr/local/lib/perl5 test.pl
1..12 Can't load './blib/arch/auto/Net/SSLeay/SSLeay.so' for module
Net::SSLeay: ld.so .1: /usr/bin/perl: fatal: relocation error: symbol not
found: BIO_int_ctrl: refe renced in ./blib/arch/auto/Net/SSLeay/SSLeay.so at
/usr/local/lib/perl5/sun4-sol aris/5.00404/DynaLoader.pm line 166.
at test.pl line 14
BEGIN failed--compilation aborted at test.pl line 14.
not ok 1
*** Error code 2
make: Fatal error: Command failed for target `test_dynamic'
What does this mean and what can I do to fix it?
Perl info:
This is perl, version 5.004_04 built for sun4-solaris
Thanks for any pointers, clues or helpful hints.
Franklin
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 18 Nov 1998 20:15:18 GMT
From: *ace*@programmer.net (Thomas Jordan)
Subject: Need equivalent to a sh's export command.
Message-Id: <36532a40.623599749@news.alpha.net>
How do you modify the parent shell's environment?
$ENV{CVSROOT}="/cvsroot";
only changes the variable in the perl process.
The following:
system('export CVSROOT=/cvsroot');
doesn't seem to work either.
TIA
-- Tom.
===================================================
Thomas Jordan
mailto:ace -at- programmer.net
no-spam:replace -at- with @
------------------------------
Date: Wed, 18 Nov 1998 15:22:14 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Need equivalent to a sh's export command.
Message-Id: <fl_aggie-1811981522140001@aggie.coaps.fsu.edu>
In article <36532a40.623599749@news.alpha.net>, *ace*@programmer.net
(Thomas Jordan) wrote:
+ How do you modify the parent shell's environment?
You can't. Its a feature, not a flaw.
James
------------------------------
Date: Wed, 18 Nov 1998 14:15:18 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <36531CC6.8BB5F347@min.net>
Adam Turoff wrote:
>
> I may not be well read in anthropology, but I've never read of a case
> where neanderthals devolved into 'homo microsofticus'. That would lead
> me to believe that our fur-clad relatives were more intelligent than
> your average ntadmin, teenage boy or otherwise.
Actually, there seems to be some speculation among anthropologists
lately that the neanderthals may have indeed been more intelligent
than the sapiens who displaced them. Wish I had a link or two for you...
John Porter
------------------------------
Date: Wed, 18 Nov 1998 19:39:22 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <36531FC5.E4BE7D3F@bbnplanet.com>
Adam Turoff wrote:
> Uri Guttman <uri@sysarch.com> wrote:
> >i am not as anti-linux or pro-solaris as you think i am.
>
> Describing linux users as unprofessional or less professional than
> SCO/Solaris/etc. users comes off as a little harsh, I think.
Who? Uri? Harsh? I'm shocked! ;)
> >the bottom line is that i think the average sun user will more likely
> >use perl than the average linux user. i think there are many more linux
> >boxes out there than suns, but there were almost equal numbers of perl
> >users in the survey. that means a higher percentage of sun users use
> >perl than linux users. this correlation is the gist of my argument.
>
> Seems like a valid correlation, and more clearly stated. Either that,
> or I'm getting less dense or more caffeinated as the week progresses...
I think this is wild speculation. We draw this assumption based only on
our own experience, not fact. This is where the actual survey data would
be useful.
> Uh, yeah. Run http://www.ora.de/german/perl/einperl2/autor.html through
> babelfish if you want to talk about sun users knowing a good tool when
> they see one. :-) :-)
*mwwaahaahaa*
e.
After all, the cultivated person's first duty is to
always be prepared to rewrite the encyclopedia. - U. Eco -
------------------------------
Date: 18 Nov 1998 15:03:24 -0500
From: Uri Guttman <uri@fastengines.com>
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <sarbtm4epkj.fsf@camel.fastserv.com>
>>>>> "AT" == Adam Turoff <ziggy@panix.com> writes:
AT> Uri Guttman <uri@sysarch.com> wrote:
>> that is what i have been trying (unsuccessfully) to say. the sun numbers
>> were very high and i feel rightly so. sun users know a good tool when we
>> see one!
AT> Uh, yeah. Run http://www.ora.de/german/perl/einperl2/autor.html through
AT> babelfish if you want to talk about sun users knowing a good tool when
AT> they see one. :-) :-)
seeing randal's and tom's bios babelfished from german is amusing. but i
am missing your point regarding sun. babelfish and altavista are on
alphas, IIR since they are both (nee) dec.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 18 Nov 1998 15:07:46 -0500
From: ziggy@panix.com (Adam Turoff)
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <72v9ei$cn9@panix.com>
Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> wrote:
>Adam Turoff wrote:
>> Uri Guttman <uri@sysarch.com> wrote:
>> >the bottom line is that i think the average sun user will more likely
>> >use perl than the average linux user. i think there are many more linux
>> >boxes out there than suns, but there were almost equal numbers of perl
>> >users in the survey. that means a higher percentage of sun users use
>> >perl than linux users. this correlation is the gist of my argument.
>>
>> Seems like a valid correlation, and more clearly stated. Either that,
>> or I'm getting less dense or more caffeinated as the week progresses...
>
>I think this is wild speculation. We draw this assumption based only on
>our own experience, not fact. This is where the actual survey data would
>be useful.
This is where the actual survey would turn pontifications into
damned lies and statistics. :-)
Z.
------------------------------
Date: 18 Nov 1998 15:42:08 -0500
From: ziggy@panix.com (Adam Turoff)
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <72vbf0$g8i@panix.com>
John Porter <jdporter@min.net> wrote:
>Adam Turoff wrote:
>> I may not be well read in anthropology, but I've never read of a case
>> where neanderthals devolved into 'homo microsofticus'. That would lead
>> me to believe that our fur-clad relatives were more intelligent than
>> your average ntadmin, teenage boy or otherwise.
>
>Actually, there seems to be some speculation among anthropologists
>lately that the neanderthals may have indeed been more intelligent
>than the sapiens who displaced them. Wish I had a link or two for you...
http://www.microsoft.com
http://home.microsoft.com
http://www.msn.com
Need more proof that homo sapiens aren't as wise as we think we are? :-)
ObPerl: did neanderthals use language? could they have learned perl?
I think they knew about good tools...
Z.
------------------------------
Date: 18 Nov 1998 15:50:38 -0500
From: ziggy@panix.com (Adam Turoff)
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <72vbuu$h6a@panix.com>
In article <sarbtm4epkj.fsf@camel.fastserv.com>,
Uri Guttman <uri@fastengines.com> wrote:
>
> AT> Uri Guttman <uri@sysarch.com> wrote:
> >> that is what i have been trying (unsuccessfully) to say. the sun numbers
> >> were very high and i feel rightly so. sun users know a good tool when we
> >> see one!
>
> AT> Uh, yeah. Run http://www.ora.de/german/perl/einperl2/autor.html through
> AT> babelfish if you want to talk about sun users knowing a good tool when
> AT> they see one. :-) :-)
>
>seeing randal's and tom's bios babelfished from german is amusing. but i
>am missing your point regarding sun. babelfish and altavista are on
>alphas, IIR since they are both (nee) dec.
elaine, could you please tell uri he's being too literal again? Thanks.
Go read the translation bit until you get the 'good tool' joke. And if
altavista, et al are running AIX, BeOS, Coherent or DecUnix, it doesn't
really matter. As you put it, 'sun users know a good tool when
they see one', and IMNSHO babelfish qualifies as a good tool when you need
a good laugh.
methinks you need a nice big cup of coffee before you get back to work
on perl2cobol...
ObPerl: Does Digital^WCompaq use perl inside of Altavista anymore? I think
they may have at one point....
Z.
------------------------------
Date: Wed, 18 Nov 1998 12:58:56 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Apple-O <appleo@cybercomm.net>
Subject: Re: Q: bulk-assign associative array?
Message-Id: <365318F0.C6CAC016@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
Apple-O wrote:
>
> Here is the answer (I was using the wrong array prefix (should be % for assoc array) and you need to use parentesis not brackets or curly braces when assigning values:
>
> %arr2 = ("a","1st","b","2nd","c","3rd");
> print "arr2{\"a\"}:".$arr2{"a"}."\n";
> print "arr2{\"b\"}:".$arr2{"b"}."\n";
> print "arr2{\"c\"}:".$arr2{"c"}."\n";
Yet another way to create 'serialized' hash:
@letters{'a'..'z'} = (1..26);
Ain't that nice? :)
-TK
------------------------------
Date: Wed, 18 Nov 1998 15:42:51 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Q: bulk-assign associative array?
Message-Id: <alecler-1811981542510001@dialup-599.hip.cam.org>
In article <72v177$12t$1@raven.cybercomm.net>, appleo@cybercomm.net
(Apple-O) wrote:
> Here is the answer (I was using the wrong array prefix (should be % for
assoc array) and you need to use parentesis not brackets or curly braces
when assigning values:
>
> %arr2 = ("a","1st","b","2nd","c","3rd");
> print "arr2{\"a\"}:".$arr2{"a"}."\n";
> print "arr2{\"b\"}:".$arr2{"b"}."\n";
> print "arr2{\"c\"}:".$arr2{"c"}."\n";
Perl also allows you to write the assignment like so:
%hash = (
a => '1st',
b => '2nd',
c => '3rd',
);
Isn't that neat?
BTW, there are simpler ways to print the contents of a hash:
while (my($key,$val) = each %hash) {
print "$key : $val\n";
}
HTH,
Andre
------------------------------
Date: 18 Nov 1998 15:25:01 -0500
From: Uri Guttman <uri@fastengines.com>
Subject: Re: Q: bulk-assign associative array?
Message-Id: <sar3e7geoki.fsf@camel.fastserv.com>
>>>>> "A" == Apple-O <appleo@cybercomm.net> writes:
A> Could someone explain how to bulk-assign values to
A> an associative array? The following would work
A> but the script would get really big & ugly when
A> you have something like 300 values to assign:
A> #!/usr/bin/perl
A> @arr2{"a"}="1"; # assign values to assoc array
A> @arr2{"b"}="2";
A> @arr2{"c"}="4";
@arr{ 'a', 'b', 'c' } = ( 1, 2, 4 );
or
%arr = ( 'a' => 1, 'b', => 2, 'c' => 4 ) ;
A> print "arr2{\"a\"}:".$arr2{"a"}."\n"; # print value
my eyes are burning from the quotes! have you read about all the variety
of quotes in perl? you almost never have to backwhack a quote char. just
pick a different outside quote. you don't even seem to know about single
quote (') which is more what you want as a key inside a hash.
A> print "arr2{'a'}: $arr2{'a'}\n" ;
no need for . and multiple strings and \" etc. just do it directly as
one nice and easy to read string.
you need to read more about strings and hashes in some good perl book
and the online docs
hth,
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Wed, 18 Nov 1998 20:19:32 GMT
From: droby@copyright.com
Subject: Re: Q: bulk-assign associative array?
Message-Id: <72va40$lkb$1@nnrp1.dejanews.com>
In article <72uviv$uq4$1@raven.cybercomm.net>,
appleo@cybercomm.net (Apple-O) wrote:
> Could someone explain how to bulk-assign values to
> an associative array? The following would work
> but the script would get really big & ugly when
> you have something like 300 values to assign:
>
> #!/usr/bin/perl
> @arr2{"a"}="1"; # assign values to assoc array
> @arr2{"b"}="2";
> @arr2{"c"}="4";
> print "arr2{\"a\"}:".$arr2{"a"}."\n"; # print value
> print "arr2{\"b\"}:".$arr2{"b"}."\n";
> print "arr2{\"c\"}:".$arr2{"c"}."\n";
>
> Is there a way to assign values to an assoc array
> all in one line like you can for a regular 1-D array?:
>
> @arrFile = ("a","1","b","2","c","3");
> print "arrFile[0]:".$arrFile[0]."\n";
> print "arrFile[1]:".$arrFile[1]."\n";
> print "arrFile[2]:".$arrFile[2]."\n";
> print "arrFile[3]:".$arrFile[3]."\n";
> print "arrFile[4]:".$arrFile[4]."\n";
> print "arrFile[5]:".$arrFile[5]."\n";
>
> I thought this might somehow be referencable
> as an assoc array, like so, but it didn't work:
>
> @arr2 = {"a","1","b","2","c","3"};
> print "arr2{\"a\"}:".$arr2{"a"}."\n";
> print "arr2{\"b\"}:".$arr2{"b"}."\n";
> print "arr2{\"c\"}:".$arr2{"c"}."\n";
>
> Any help would be most appreciated.
>
>
All this is explained pretty well in the perldata section of the fine
documentation, which you should be able to find on your system somewhere, or
on-line at http://www.perl.com.
Replace the assignment in your last attempt up there with
%arr2 = ('a',1,'b',2,'c',3);
and it will work. A more suggestive way (by "syntactic sugar") is
%arr2 = ('a' => 1, 'b' => 2, 'b' => 3);
--
Don Roby
droby@copyright.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 18 Nov 1998 14:58:25 -0500
From: "Ci-Ci Mills" <cici@erols.com>
Subject: Re: required fields
Message-Id: <72v8p5$fa4$1@autumn.news.rcn.net>
This is how I did it....
use strict;
use CGI;
my @required = ("username","passwd","address","state","city","zip");
my $msg;
foreach (@required) {
unless (defined $query{$_}) {
$msg = "<P>One or more of the required fields is blank. Please fill out
ALL
required fields.</P>";
last;
}
}
Then, you can return the message in a "Here" document.
Hope this helps.
Ci-Ci Mills
cici@erols.com
Kumar Sundaram wrote in message <72uuld$oku$1@mur2.odyssey.on.ca>...
>I want to able to make some required fields for the user in the html file
>with a comma to separate them.
>for eg:
><input type="hidden" name="require" value="field1,field2,field3">
>Can someone provide me the part of the cgi/perl script to do this!!
>Thanks in advance!!
>Kumar
>
>
------------------------------
Date: Wed, 18 Nov 1998 19:49:32 GMT
From: dturley@pobox.com
Subject: Re: required fields
Message-Id: <72v8c5$juh$1@nnrp1.dejanews.com>
In article <72uuld$oku$1@mur2.odyssey.on.ca>,
"Kumar Sundaram" <softsci@eagle.ca> wrote:
> I want to able to make some required fields for the user in the html file
> with a comma to separate them.
> for eg:
> <input type="hidden" name="require" value="field1,field2,field3">
A cgi question, but...
You should make the required fields, and the check, part of the perl script,
not hidden fields in the form. If you do it your way, all the user has to do
is edit the html before submitting and they can get around the required
fields.
here's one way:
my %required = ('name'=>'Name',
'email'=>'Email Adresss',
'address'=>'Address',
'city'=>'City',
'state'=>'State',
'zip'=>'Zip/Postal Code',
'name_on_card'=>'Name on Credit Card',
'card_type'=>'Credit Card Type',
'card_number'=>'Credit Card Number',
'card_month'=>'Credit Card Expiration Month',
'card_year'=>'Credit Card Expiration Year',
);
check_required_fields();
sub check_required_fields {
my ($field,@missing_fields);
foreach $field (keys %required) {
if (!param($field)) {
push(@missing_fields,$required{$field});
}
}
if (@missing_fields) {
print header,
start_html(-bgcolor => '#ffffff',-title=>'Order Form Error'),
h2('Incomplete Form'),
"The form was not filled out completely. ",
"You must fill out all required fields.",p,
b('Empty Form Fields:'),br;
@missing_fields = sort(@missing_fields);
for (0..$#missing_fields) {
print "$missing_fields[$_]<BR>";
}
print p,"Please complete the form before submitting.",p,
a({href=>'javascript:history.go(-1);'},'Please try again.'),
end_html;
exit(0);
}
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 18 Nov 1998 19:36:24 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: reverse comma operator in the camel
Message-Id: <Pine.GSO.4.02A.9811181133080.27321-100000@user2.teleport.com>
On Wed, 18 Nov 1998, J.D. Laub wrote:
> #!/usr/local/bin/perl -w
> my @foo = (101, 303);
> my $a = (pop @foo, pop @foo)[0];
> print "a=$a.\n";
>
> This prints 303, the RIGHT argument in the list, which is the same as the
> comma operator. Can someone explain what Larry, Tom, & Randall are trying to
> convey with their "reverse comma operator" example?
The first pop yields 303, the second gives 101. The "reverse comma"
discards the second and returns the first, just as the scalar comma
operator will discard the first and return the second.
my $a = pop(@foo), pop(@foo); # gives value from second pop.
I think you were misled by the use of pop(), which is basically a
"backwards" operator in the first place: It gives the value which was last
in the array.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 18 Nov 1998 19:49:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: reverse comma operator in the camel
Message-Id: <72v8ce$j5e$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Tom Phoenix <rootbeer@teleport.com> writes:
: my $a = pop(@foo), pop(@foo); # gives value from second pop.
No, it doesn't. You've screwed up your precedence.
--tom
--
"Those who do not understand Unix are condemned to reinvent it, poorly."
--Henry Spencer
------------------------------
Date: Wed, 18 Nov 1998 14:46:05 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Scope question for Perl
Message-Id: <365323FD.EAF97B1E@min.net>
xaqtnr@my-dejanews.com wrote:
>
> Is there any documentation that will explain in detail how Perl handles the
> variables in relation to their scope and persistence. Or maybe someone can
> give me a general run-down. I know you can use local/my to declare variables,
Get this straight, before we go any further: local and my are not related
at all, and should not be lumped together like that.
You can declare a locally scoped variable with the 'my' keyword.
'local' is an operator which affects global variables; it does not
"declare" anything!
>...
> There are two 'x' variables, but they exist differently since their scope is
> within their respective functions. Even the following variables have different
> scope as far as I've found in C:
>...
> This will produce a 'undeclared variable' error since the first 'y' variable
> is not in the same scope as the one that is incremeted.
The Perl equivalent uses the 'my' keyword to declare locally scoped variables.
They are not entirely identical to C's automatic variables, but close enough.
> How does Perl handle all of this? Are variables only in scope within
> respective sub-routines, or are the local/my identifiers needed to restrict
> the variable to that function?
Lexical variables ('my' variables) are so-called because they are lexically
scoped. You can see the scope of the variable by looking at the source
code: where are the curly braces? The lexical scope of a 'my' variable
can also be a file (if it occurs outside any braces).
Get used to declaring all your variables with 'my', and you should be
happy.
--
John Porter
Please Don't "Courtesy CC" me.
I read this newsgroup fanatically. You know that!
("Emailed only" is fine, though.)
Bill Gates claims to be developing a stable operating system;
Linus Torvalds claims to be bent on world domination.
------------------------------
Date: Wed, 18 Nov 1998 15:36:07 -0500
From: Marty Landman <marty@catnmoose.com>
Subject: selective list assignment?
Message-Id: <36532FB7.7AC69D9C@catnmoose.com>
I want a 'pretty' way to assign selective variables from a list, i.e. I
want to code the equivalent of
($not1,$not2,$not3,$hh,$mm,$ss,$zz) = `date`;
where the first three elements are not needed... is there a better way
to indicate in one stmt that I'm not interested in the first 3 elmts of
the array?
--
_____ Marty Landman _______ http://www.catnmoose.com/ ______
Living Glass http://www.catnmoose.com/livinglass
Mountain Man http://www.catnmoose.com/mountainman
__________Cat 'n Moose Web Site Design & Development_________
------------------------------
Date: Wed, 18 Nov 1998 19:40:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Sounds easy when I type it fast
Message-Id: <Pine.GSO.4.02A.9811181137340.27321-100000@user2.teleport.com>
On Wed, 18 Nov 1998, Jenny Brandis wrote:
> I know nothing about programming but would like to make my site
> interactive with a searchable database and maybe get some user stats.
You probably need a programmer.
> Downloaded a couple of scripts that sound ok. (Matt's simple search,
> urlsrch.cgi, websearch and intermediate search.)
Downloading software like this is like "finding" pills; unless you're
technologically capable of telling the good from the bad, you have to get
them from a trusted source. A script that "sounds ok" may not be safe.
> Is it true that with cgi I can't test drive it on my computer like I
> do HTML?
Sounds like a CGI question; check the docs, FAQs, and newsgroups about CGI
programming. If you were a programmer, I'd tell you that you can use the
CGI module to make a Perl program which you can test without a webserver,
though. But you're not a programmer, so I won't say that. :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 18 Nov 1998 20:43:50 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: test for.t failure due to bad rounding
Message-Id: <Pine.GSO.4.02A.9811181240450.27321-100000@user2.teleport.com>
On Wed, 18 Nov 1998 everybodydies@my-dejanews.com wrote:
> it is, in fact, gconvert which is being used. unfortunately, it's
> responsible for the bad results (see enclosed c code which generates
> bad output).
Port Linux to your hardware. :-)
> i can only think that this is a problem with either solaris 2.5.1
> running on old hardware (an ancient ipx), or with the floating point
> hardware in the machine itself. ugh.
Well, the good news is that, thanks to perl, you know that this problem
exists. Maybe you can write your own gconvert, compile it into a library,
and build a perl which links to that. But the real solution would be to
replace those bad libraries, pieces of hardware, or whatever. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 18 Nov 1998 15:10:15 -0500
From: Uri Guttman <uri@fastengines.com>
To: sara starre <nospam.gear4u@hotmail.com>
Subject: Re: Two-Part RE question
Message-Id: <sar90h8ep94.fsf@camel.fastserv.com>
>>>>> "ss" == sara starre <nospam.gear4u@hotmail.com> writes:
ss> OK, this is a two-part question. The first part is only for the
ss> perl newsgroup hoseheads who flame everyone who asks a
ss> question. Here is your part, put your might brain to work on it
ss> and post your solution to alt.whocares:
i noticed you got technical 3 answers, 2 of which are from those
"hoseheads" you refer too (including me) and one was from a newbie and
his answer was correct but not well done.
did you thank anyone for the help? did you acknowledge anyone via email?
were YOU polite in return?
think about it before you post such an asinine message again. we do help
those who have tried to help themselves. it is being requested to do all
the work for the poster that is aggravating.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 18 Nov 1998 19:35:13 GMT
From: Alistair Cunningham <ac212@cam.ac.uk>
Subject: Re: writing to file on winnt perl cgi
Message-Id: <72v7hh$cas$1@pegasus.csx.cam.ac.uk>
ps <as@asd.asd> wrote:
> hi all
> do you know way the following line wont work on winnt Perl cgi script?
>
> open (FILE,">$FullPath\\Filename.ext") or die
> print FILE, "string";
^
I've never used Perl under NT, but I bet this is your problem. The
correct format is:
print FILE "string", "string2", $myvar, "etc\n";
Look no comma.
JAPH
Alistair Cunningham.
--
--------------------------------------------------------------------------
Alistair Cunningham Selwyn College, Cambridge Email: ac212@cam.ac.uk
------------------------------
Date: Wed, 18 Nov 1998 15:53:54 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: writing to file on winnt perl cgi
Message-Id: <MPG.10bcfdd5debc268e98971a@news.scescape.net>
In article <01be12cd$af1e8080$630de00a@pchelp2nt>, ps <as@asd.asd>
pounded in the following:
=> hi all
=> do you know way the following line wont work on winnt Perl cgi script?
=>
=> open (FILE,">$FullPath\\Filename.ext") or die
^
=> print FILE, "string";
=> For some reason I cant Opens the file for writing using this method
=> $fullPath is the absolute path to the directory in which I got the files.
Besides Alistair's response, you are missing a semicolon. If the open
failed, it would die with the return value from print. If the open
succeeded, it wouldn't print.
If the semicolon IS present, then disregard.
=> thanks
HTH,
=> Zohar
--Matthew
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4249
**************************************