[16978] in Perl-Users-Digest
Perl-Users Digest, Issue: 4390 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 20 18:15:50 2000
Date: Wed, 20 Sep 2000 15:15:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969488126-v9-i4390@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Sep 2000 Volume: 9 Number: 4390
Today's topics:
Re: newbie string chopping question nobull@mail.com
Re: OT! Sports colors (Was: Re: Can you store a conditi <russ_jones@rac.ray.com>
OT! Sports colors (Was: Re: Can you store a condition i <lr@hpl.hp.com>
Re: Parse::RecDescent: Problem with a Grammar <stephen@twocats.dont-spam.demon.co.uk>
parsing parentheses nested files bhaskaracharya@my-deja.com
Perl CGI & Windows 98 <rbessler@att.net>
Re: Perl economy <lr@hpl.hp.com>
Perl Golf Apocalypse rathmore@tierceron.com
Perl Online Questions Updated cd_root@my-deja.com
piping data to a C program via a "open" <boriente@my-deja.com>
Re: piping data to a C program via a "open" <dmeyers@panix.com>
Re: Pure perl encrypt/decryption? (Mark-Jason Dominus)
Re: reading from a file <ren.maddox@tivoli.com>
Re: Reg-ex Needed <noone@dontbother.com>
Re: Reg-ex Needed <yanick@babyl.sympatico.ca>
RegEx Question <usenet@dstanek.com>
Re: RegEx Question <ren.maddox@tivoli.com>
Re: rounding error problem <tim@ipac.caltech.edu>
Re: Running lengthly perl scripts over cgi <amonotod@netscape.net>
Re: search a string <tim@ipac.caltech.edu>
Re: Shortest code for Fibonacci? <jcook@strobedata.com>
STDOUT && mod_perl maitkin@my-deja.com
Strange results using system vs backticks (Reposted in <tmvatcher@bigfoot.com>
Re: Strange results using system vs backticks (Reposted <tmvatcher@bigfoot.com>
Re: Time help (John J. Trammell)
Re: translate JavaScript to CGI (read cookie) <jeff@vpservices.com>
Re: translate JavaScript to CGI (read cookie) <russ_jones@rac.ray.com>
Re: translate JavaScript to CGI (read cookie) <nospam@jillanddirk.com>
Re: translate JavaScript to CGI (read cookie) <nospam@jillanddirk.com>
Re: translate JavaScript to CGI (read cookie) (Jerome O'Neil)
Re: translate JavaScript to CGI (read cookie) <nospam@jillanddirk.com>
Re: translate JavaScript to CGI (read cookie) (Jerome O'Neil)
Re: translate JavaScript to CGI (read cookie) <nospam@jillanddirk.com>
Re: What's wrong with that regexp? nobull@mail.com
Where can I find a cgi for Usenet forum <xchen@helix.nih.gov>
Re: Where can I find a cgi for Usenet forum (Clinton A. Pierce)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Sep 2000 20:47:31 +0100
From: nobull@mail.com
Subject: Re: newbie string chopping question
Message-Id: <u9bsxig818.fsf@wcl-l.bham.ac.uk>
"Ric Smith" <rickyfusion@nospamfusionserver.com> writes:
> Subject: newbie string chopping question
"Newbie question"... OK I'll give you a fishing lesson.
> Is there a function...
Perl functions are listed in perldoc perlfunc.
> to chop the characters off a string after a specified character?
So you want to do string manuplation... so look in perlfunc and find
the appropriate group.
Functions for SCALARs or strings
chomp, chop, chr, crypt, hex, index, lc, lcfirst,
length, oct, ord, pack, q/STRING/, qq/STRING/,
reverse, rindex, sprintf, substr, tr///, uc, ucfirst,
y///
Now guess which one you need. chop() and chomp() sound hopeful so you
go RTFM and find that they don't do what you want. So go back to the
list and find the next best sounding candidate... "substr". Now you
RTFM for substr and discover it is the function you need.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 20 Sep 2000 13:58:13 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: OT! Sports colors (Was: Re: Can you store a condition in a variable?)
Message-Id: <39C908C5.C5267626@rac.ray.com>
Larry Rosler wrote:
>
>
> University of Michigan has 'maize' and blue! (It looks gold to me,
> though.)
>
> I understand why Brazil's colors might be green and yellow, given their
> flag. But the Aussies' colors are incomprehensible, given their flag's
> red, white and blue, as a good descendant of Mother England. Perhaps
> someone can explain.
>
It's not an explanation, but here's a link to Frank Deford's story
from NPR.
http://search.npr.org/cf/cmn/cmnpd01fm.cfm?PrgDate=09/20/2000&PrgID=3
And WAY off topic and fairly disgusting:
Once my girlfriend and I were invited to a Halloween costume party,
and she really wanted to go, but she was sick with the yellow
jaundice. I told her she ought not to go, but she just had to, so she
wore a green leotard and went as an ear of corn. But it ended in
tragedy because on the way home we were cutting across a field and the
hogs caught her and ate her.
(I heard Buck Owens use that one once in concert.)
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Wed, 20 Sep 2000 11:07:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: OT! Sports colors (Was: Re: Can you store a condition in a variable?)
Message-Id: <MPG.14329c9f68059fb198ad9b@nntp.hpl.hp.com>
In article <39C8BA03.15D70FFD@rac.ray.com> on Wed, 20 Sep 2000 08:22:11
-0500, Russ Jones <russ_jones@rac.ray.com> says...
> Jonathan Stowe wrote:
> >
> > On Tue, 19 Sep 2000 12:21:04 -0700 Larry Rosler wrote:
> > > In article <slrn8sf5vb.5fq.abigail@alexandra.foad.org> on 19 Sep 2000
> > > 16:45:37 GMT, Abigail <abigail@foad.org> says...
> > >>
> > >> (Yellow and green? *shudder*)
> > >
> > > Check out the Australiam team's colors. Also the University of Oregon
> > > (Ducks!, how appropriate), But *shudder* anyway. :-)
> >
> > Brazilian footbal team too.
>
> How odd. The topic of how almost no sports teams had yellow as a
> color, it was always gold, was raised in Frank DeFord's (sp?)
> commentary today on Morning Edition on NPR. Virginia Military Academy
> has a school color of yellow, too.
University of Michigan has 'maize' and blue! (It looks gold to me,
though.)
I understand why Brazil's colors might be green and yellow, given their
flag. But the Aussies' colors are incomprehensible, given their flag's
red, white and blue, as a good descendant of Mother England. Perhaps
someone can explain.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 20 Sep 2000 21:44:30 +0100
From: "Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk>
Subject: Re: Parse::RecDescent: Problem with a Grammar
Message-Id: <969484215.9704.0.nnrp-01.9e98901a@news.demon.co.uk>
Damian Conway <damian@cs.monash.edu.au> wrote in message
news:8q90jd$4jh$1@towncrier.cc.monash.edu.au...
> Indeed. The actions within a RecDescent rule are converted to
> C<do> blocks within the parsing subroutines RecDescent
> generates. Something like:
>
> rule: /pattern/ subrule { action() }
>
> becomes:
>
> sub rule {
> # match against /pattern/
>
> # recursively call subrule()
>
> $result = do { action };
>
> # other Important Stuff here
> }
>
>
> If you put a C<return> in an action, you blast straight out of the
> parsing subroutine, without doing the other Important Stuff :-(
Right. All is now clear (to me, at least :-). As you probably guessed,
the picture I had in my mind was that the { action() } was converted
into a sub { action() }.
I think this point could be clarified in the docs.
Steve Collyer
------------------------------
Date: Wed, 20 Sep 2000 18:52:49 GMT
From: bhaskaracharya@my-deja.com
Subject: parsing parentheses nested files
Message-Id: <8qb11l$a55$1@nnrp1.deja.com>
hi,
Are there standard ways to process parentheses nested files?
I tried various ways like having subs to countparentheses(add 1 for open
and -- for closing, etc) and pushing each word to an array but it looks
tedoious...Are there any good parsing modules to do this? Any examples
are appreciated..
thanks
E,g
(Net data[255]
(wire (path m2 360 844 220 844 221)
(connect (terminal smd data[255]) (terminal via))
)
(wire (path m3 720 119 147 119 147 119 148 (lead_ext 680) (trail_ext
680))
(connect (terminal via) (terminal via))
)
)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 21:16:22 GMT
From: "Richard Bessler" <rbessler@att.net>
Subject: Perl CGI & Windows 98
Message-Id: <GO9y5.146$tl2.7819@bgtnsc07-news.ops.worldnet.att.net>
This is a multi-part message in MIME format.
------=_NextPart_000_004F_01C0231D.F7BDAAC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Quick Question
I'm running from my home Windows 98 (with ActiveState's PERL =
loaded on it), and is it at all possible for me to set up my system so I =
can run CGI scripts (through browser) locally (for free :-))? I'd =
appreciate any assistence on this, and if I need something, could you =
point me to the right direction?=20
Thanks,
Richard
------=_NextPart_000_004F_01C0231D.F7BDAAC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Quick Question</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> I'm =
running=20
from my home Windows 98 (with ActiveState's PERL loaded on it), and is =
it at all=20
possible for me to set up my system so I can run CGI scripts (through =
browser)=20
locally (for free :-))? I'd appreciate any assistence on this, and if I =
need=20
something, could you point me to the right direction? </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Richard</FONT></DIV></BODY></HTML>
------=_NextPart_000_004F_01C0231D.F7BDAAC0--
------------------------------
Date: Wed, 20 Sep 2000 12:26:06 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl economy
Message-Id: <MPG.1432af25f9c38db398ad9f@nntp.hpl.hp.com>
In article <CL%x5.7$ii2.829@vic.nntp.telstra.net> on Wed, 20 Sep 2000
09:50:26 GMT, scott@mobinfo.com.au <scott@mobinfo.com.au> says...
...
> Is there a more succinct way to do this:
>
> $a = '/home/scott/inc /usr/include /home/scott/program/include'
> x join(' ', map({ $_ = '-I' . $_ } split(/\s+/, $a)))
> 0 '-I/home/scott/inc -I/usr/include -I/home/scott/program/include'
>
> This *almost* does what I want:
> x join(' -I', split(/\s+/, $a))
> 0 '/home/scott/inc -I/usr/include -I/home/scott/program/include'
>
> but it doesn't prefix the 1st dir with '-I', which is why I
> resorted to using 'map' above.
>
> Anyone know a more efficient (less maninpulation &/or lines-of-code) way?
>
> Actually, I think that should b "less characters-of-code"! :)
No, it should be 'fewer' ...
join ' -I', "", split " ", $a
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 20 Sep 2000 18:20:17 GMT
From: rathmore@tierceron.com
Subject: Perl Golf Apocalypse
Message-Id: <8qav47$7gt$1@nnrp1.deja.com>
http://www.oreillynet.com/pub/e_sess/643 lists a fun promo for a
session of Perl golf at the O'Reilly Open Source Software Convention
which was held in July of this year.
I was wondering if there is a web site that lists the 9 "holes", and
the winners. I find Perl golf an intriguing exercise but I'm too new to
Perl to play myself. However, seeing how others play the game is a
great way to learn. (Isn't it?)
Rathmore
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 21:18:00 GMT
From: cd_root@my-deja.com
Subject: Perl Online Questions Updated
Message-Id: <8qb9hh$l99$1@nnrp1.deja.com>
We've added over 100 more questions to our perl related online database
at:
http://www.networkessentials.com/certified/perl
We've also corrected some typos thanks to the watchful eyes of pervious
visitors. :-)
There are also Sun Solaris Questions at:
http://www.networkessentials.com/certified/sca
And Oracle Database Administrator Questions at:
http://www.networkessentials.com/certified/ocp
And OpenVMS System Management questions at:
http://www.networkessentials.com/certified/vms
and more ... check us out.
cj
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 18:11:15 GMT
From: barry oriente <boriente@my-deja.com>
Subject: piping data to a C program via a "open"
Message-Id: <8qaujd$722$1@nnrp1.deja.com>
Our existing WIN2K environment consists of some PERL scripts that
execute a C program via the OPEN statement with a pipe. We pass parms
via the OPEN statement and pipe the results back to the PERL script.
The C program is compiled as an EXE and uses argv[] to retrieve the
arguments.
The OPEN statement looks like this:
open (RESULTS, "$cpgm $parm1 $parm2 \"$datastring\"|");
- where $cpgm is the c .exe
- the other parms data used by the c progam
We are running into problems where the data being passed has reached
it's limit (approx 4K). After that all bets are off.
We've tried the following (which works):
open (RESULTS, "$cpgm $parm1 $parm2 $filename|");
where $filename is a file containing the data
open (RESULTS, "$cpgm $parm1 $parm2 0<$filename|");
where $filename is a file containing the data and is piped
to STDIN
Is there way, using the OPEN statement above, to pipe the data directly
to STDIN (not via a file) and have the C program read from
STDIN?
--
barry oriente
barry.oriente@mcmaster.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Sep 2000 17:27:31 -0400
From: Dave <dmeyers@panix.com>
Subject: Re: piping data to a C program via a "open"
Message-Id: <yob3diulpoc.fsf@panix3.panix.com>
barry oriente <boriente@my-deja.com> writes:
> Is there way, using the OPEN statement above, to pipe the data directly
> to STDIN (not via a file) and have the C program read from
> STDIN?
perldoc -q pipe
It will show you some very help stuff about IPC::open2
--d
--
dmeyers@panix.com
------------------------------
Date: Wed, 20 Sep 2000 22:03:14 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Pure perl encrypt/decryption?
Message-Id: <39c93403.3210$120@news.op.net>
In article <MPG.14317ae9c5de7dc3989687@nntp.onyx.net>,
Andy Flisher <andrew.flisher@onyx.net> wrote:
>Splitting text on the way in is easier as it's 8 chars, but there's no
>guarantee that you're gonna get 8 chars back.
Perhaps I'm mistaken, but I thought that Blowfish was a block cipher,
which means that yes, there *is* a guarantee that you're gonna get 8
chars back, because that's the whole point.
------------------------------
Date: 20 Sep 2000 14:46:27 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: reading from a file
Message-Id: <m3bsxivobw.fsf@dhcp11-177.support.tivoli.com>
Powlow <powlow@my-deja.com> writes:
> wooohh!
> a response!
A bit impatient are we? While you can often get a response quicker
than this, the vagaries of news feeds make expecting quick responses
an unpleasant activity.
> thanks. actually i found out how to do it.
> it wasn't a newline character.
> i used s/\s+$// to remove the trailing space which funnily enough
> didn't work with s/ //g or something similar.
> drove me nuts.
Sounds like it probably was probably a carriage return, or perhaps a
tab. Maybe even a form feed.... :)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 20 Sep 2000 12:19:05 -0700
From: "Robert Lund" <noone@dontbother.com>
Subject: Re: Reg-ex Needed
Message-Id: <ssi3doljf2vq82@corp.supernews.com>
> : I need a REGEX to change all commas in a line to a pipe symbol ( | ).
> : ANY data between <STX> and <ETX> should be ignored though... for
> : example:
>
>
> $string = "data1, 5,6,2,<STX>hello, <ETX> my name is Robert, ".
> "wow <STX>, that is, neat!!<ETX>,,\n";
>
> $with_tags = join '',
> map { y/,/|/ unless /^<STX>.*<ETX>$/; $_ }
> split m/(<STX>.*?<ETX>)/,
> $string;
>
> $without_tags = join '',
> map { /^<STX>(.*)<ETX>$/ ? $1 : y/,/|/ && $_ }
> split /(<STX>.*?<ETX>)/,
> $string;
>
This worked really well thank you... what if I wanted to split that line by
commas into a list, and have the commas between <STX> and <ETX> ignored?
Also having the <STX> and <ETX> tags removed would be nice... the above
string would be broken into a list with the following elements:
data1
5
6
2
hello,
my nams is Robert
wow
, that is, neat!!
<EMPTY>
\n
Thanks again!
--Robert
------------------------------
Date: Wed, 20 Sep 2000 19:49:24 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Reg-ex Needed
Message-Id: <8x8y5.255803$Gh.6373935@news20.bellglobal.com>
Robert Lund <noone@dontbother.com> wrote:
<snip>
: This worked really well thank you... what if I wanted to split that line by
: commas into a list, and have the commas between <STX> and <ETX> ignored?
Then you would joyfully go perldoc -q split'ing... :)
Or, if you want your professor/project manager to get a
heart attack:
$_ = "Waiter, there <STX>is<ETX> a, gasp, camel <STX>yes,".
"a camel<ETX> in my soup";
for ( split /,/ )
{
s/<STX>(.*?)<ETX>/$1/g;
if( s/<STX>// ... s/<ETX>// and $& ne '<STX>' )
{
$_[-1] .= ",$_";
}
else
{
push @_, $_;
}
};
$, = "\n";
print @_;
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: Wed, 20 Sep 2000 15:20:51 -0400
From: "David Stanek" <usenet@dstanek.com>
Subject: RegEx Question
Message-Id: <8qb2fs$iqs$1@news.chatlink.com>
Is there any way to do something like [^(</blockquote>)] so I can say get
any character until it gets to </blockquote>? The file I am parsing looks
something like:
some html
<blockquote> some html
<blockquote>
what I need
</blockquote>
some html
</blockquote>
some more html
How can I get the "what I need" text?
David Stanek
------------------------------
Date: 20 Sep 2000 15:18:50 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: RegEx Question
Message-Id: <m38zsmvmtx.fsf@dhcp11-177.support.tivoli.com>
"David Stanek" <usenet@dstanek.com> writes:
> Is there any way to do something like [^(</blockquote>)] so I can say get
> any character until it gets to </blockquote>? The file I am parsing looks
> something like:
> some html
> <blockquote> some html
> <blockquote>
> what I need
> </blockquote>
> some html
> </blockquote>
> some more html
> How can I get the "what I need" text?
First, don't do it that way. Use HTML::Parser (or something
similar). There are just too many oddities in HTML to worry about
getting it right.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 20 Sep 2000 12:23:20 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: rounding error problem
Message-Id: <39C90EA7.22B1221E@ipac.caltech.edu>
Jim Chim wrote:
> I have wrote a script for data analysis. The result is not
> reasonable. After inspection of the script, it might due to the rounding
> error of the data. My typical data attain values of 99999999, did perl are
> using double precision just like FORTRAN did or is there any function to
> handle this problem
Need short, on-point code samples with data showing the problem to have any idea
what you're talking about. Yes perl uses double precision.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Wed, 20 Sep 2000 21:28:24 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Running lengthly perl scripts over cgi
Message-Id: <8qba4s$m1g$1@nnrp1.deja.com>
In article <8q8hts$e4f$1@nnrp1.deja.com>,
amonotod <amonotod@netscape.net> wrote:
> In article <8q89cl$37i$1@nnrp1.deja.com>,
> dj_morri@my-deja.com wrote:
> > I wish to run a perl script spawned via a web cgi interface. Only
> <snip>
> > Surely there must be a perl solution, instead of resorting to
<snip you and me>
> I used Dave Roths Daemon.pm Directory Monitor to monitor a `jobs'
> directory, and a cgi interface to create a file in the jobs directory.
> The dirmon script picks up the file, logs some user info, starts the
> cgi script as a local app, then deletes the job file. The local run
> cgi script then does what I need it to do, using Win32::spawn.
>
> I'd post my code, but it is embarrassingly ugly (pronounce as OOG-lè,
> and think about Moronzilla! as you say it), and I just can't bear to
> have it criticized. If you're interested, email me, I'll sanitize it
> in regards to localized info and let you have it.
<snip me>
What the hell, here it is:
http://www.geocities.com/amonotod/srvrmngmnt/index.html
Hope you like it, but even if you don't, it still works great for me!
HTH,
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 12:00:11 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: search a string
Message-Id: <39C9093B.C36940EF@ipac.caltech.edu>
nodo70@my-deja.com wrote:
>
> What's a good algorithm to search a string and get a next string which
> are contained in an array? For instance, if I have an array called
> @string = ('cc', '-Xa', 'v', '-o', 'hello', 'hello.c', '-I/include');
> and I just want to get a string "hello" right after a string "-o". Do
> I have to go through the whole array by index or have better idea just
> one line would do? Please advise. Thanks.
If you're parsing the command line, your best bet is to use one of the many fine
extension modules which do this for you. See your local CPAN site.
But if you're looking for idioms to do something more general, ne way would be a
compact form of exactly what you suggested:
my = $string[(grep($string[$_] eq '-o',0..$#string))[0]+1];
... but that leaves little room for error checking. This might be safer:
my %oandarg = grep(s/^-(o|out|outfile)$/o/.../.*/,@string); # Alters @string
print "$oandarg{o}\n";
... or the short circuiting version:
for (@string) {
next if ! (/^-(o|out|outfile)$/.../.*/);
$oarg = $_;
}
... or a pure hash solution:
my (%args,%revargs);
@args{@string} = 0..$#string;
print "$revargs{$args{-o}+1}\n";
I'll leave you to read perlop, perlre, perlfunc and perlvar to parse those.
Others will have many other solutions.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Wed, 20 Sep 2000 12:53:54 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C915D2.525DB093@strobedata.com>
> : I'm saying that power (exponentiation) when implemented on a computer
> : will test out to be O(1).
> We'd love to see your implementation.
I would just use the built-in function ** which the perl source will
eventually compile down to the Intel exponentiation FPU instructions
(for my platform).
I cite as evidence to my claim that using exponentiation is O(1) for the
limited set of real numbers available on the Intel FPU the following
program and results. Perhaps I put too much faith in "use benchmark".
I do not know how this will behave on non-Intel floating point
implementations. I was trying to make a simple claim that the Intel FPU
does exponentiation in O(1).
If exponentiation were not O(1), I would expect to see a differenc in
performance for **2 and **3000. I do not see this difference.
------------------------ Source ------------------------
#! perl -w
use strict;
use Benchmark;
my $Base = 1.234;
my $LargePower = 3000;
my $SmallPower = 2;
print "Large power answer " . ($Base ** $LargePower) ."\n";
print "Small power answer " . ($Base ** $SmallPower) ."\n";
print "\n";
my $ans;
timethese(1000000, {
'Small power' => sub { $ans = $Base ** $SmallPower },
'Large power' => sub { $ans = $Base ** $LargePower },
});
------------------------ Output ------------------------
Large power answer 8.820213377741e+273
Small power answer 1.522756
Benchmark: timing 1000000 iterations of Large power, Small power...
Large power: 1 wallclock secs ( 1.54 usr + -0.01 sys = 1.53 CPU) @
652315.72/s
(n=1000000)
Small power: 2 wallclock secs ( 1.55 usr + 0.00 sys = 1.55 CPU) @
643915.00/s
(n=1000000)
------------------------------------------------
I imagine that those numbers are the same, given errors in calculation.
If they are prefectly accurate, it seems that it is faster to take the
3000th power of a number than to square it.
--
jcook@strobedata.com Live Honourably 4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page http://www.strobedata.com
My home page O- http://jcook.net
------------------------------
Date: Wed, 20 Sep 2000 21:26:35 GMT
From: maitkin@my-deja.com
Subject: STDOUT && mod_perl
Message-Id: <8qba1g$m02$1@nnrp1.deja.com>
perl v5.6.0 built for PA-RISC2.0
Have a report running under mod_perl which uses
a perl format like this:
format STDOUT =
blah blah blah
No errors, but the format refuses to print data back to the browser.
If I start Apache in single instance mode (i.e. httpd -X), the html
output of the report is printed to the terminal where I started
the web server. If I start the web server via apachectl, the data
is never seen. Either way, it doesn't make in back to the browser.
The mod_perl to CGI porting faq states:
"In mod_perl both STDIN and STDOUT are tied to the socket the request
came from. STDERR is tied to the error_log file. "
Which makes sense, but it doesn't seem to be working.
thoughts?
-thx!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 11:39:48 -0700
From: "Toni M. Vatcher" <tmvatcher@bigfoot.com>
Subject: Strange results using system vs backticks (Reposted in plain text)
Message-Id: <39C90474.CB469C2C@bigfoot.com>
Sorry about the HTML posts... hope this is easier to read.
I'm running ActiveState Perl 522 on Windows NT 4.0
I have a call to an executable within my perl script.
I create a variable to contain the command:
$system_cmd = "$ENV{prog_dir}\\program.exe -option $param1
$param2";
Then I use system as follows:
$status = system $system_cmd;
My program appears to be calling the executable twice... (I verified
from within the debugger that I dont' somehow have the "system" command
twice)
When I use backticks as follows:
$results = `$system_cmd`;
it only gets called once.
I prefer to use system in this case because the executable takes a long
time to run and its output provides % completion information to the
user.
This behavior does not seem to happen when I change $system_cmd to "dir"
or to run a different executable. The executable that has the problem
runs fine (only once) from outside the perl script.
Does anybody have any idea why this is happening or what I can do to fix
it?
Or, if there's a way to get the output of the backticks to go to the
display as the program runs rather than waiting to the end, I guess that
would get me what I need. Although, I'd really like to understand
what's going on...
Thanks!
Toni Vatcher
tmvatcher@bigfoot.com
------------------------------
Date: Wed, 20 Sep 2000 11:41:49 -0700
From: "Toni M. Vatcher" <tmvatcher@bigfoot.com>
Subject: Re: Strange results using system vs backticks (Reposted in plain text)
Message-Id: <39C904ED.B9534455@bigfoot.com>
After posting the previous message, I figured out what was happening.
I still would like to understand why perl did what it did, though...
The program that I was calling wasn't returning any status at all - its
return value was defined as "void".
If I put the program inside a DOS batch file and just added a dummy
command (dir) at the end of the batch file, it would only be called
once. Without the dir command the batch job was called twice. (The
reason it wasn't called over and over is that the program aborts if it
is run without the necessary setup that's in my perl script).
So... I got them to update the program to return "good" status and all
is well.
Toni Vatcher
tmvatcher@bigfoot.com
------------------------------
Date: 20 Sep 2000 18:40:26 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Time help
Message-Id: <slrn8sh6q5.22c.trammell@nitz.hep.umn.edu>
On Wed, 20 Sep 2000 10:40:06 -0500, Tom Briles <sariq@texas.net> wrote:
>"John J. Trammell" wrote:
>>
>> On Wed, 20 Sep 2000 14:54:30 +0100, Rui Miguel Venancio
>> <rui.miguel@srd.alcatel.pt> wrote:
>>
>> >I have one variable with the system date (eg. 20000919 - YYYYMMDD),
>> >And I have another variable with a date in the future
>> >(eg: 20001005 - YYYYMMDD).
>> >
>> >I want to see a message if the second date have less than 4 weeks of
>> >the first date !!!!
>>
>> You're looking for the Date::Calc module and its Delta_Days function.
>
>That's overkill. The formatted dates shown are very easily parsed for
>input into the timelocal() function.
>
I've put it to the test; here's the output of my Benchmark:
[ ~/test/time-001 ] ./foo.pl
Benchmark: timing 10000 iterations of date-calc, time-local...
date-calc: 2 wallclock secs ( 1.61 usr + 0.00 sys = 1.61 CPU)
@ 6211.18/s (n=10000)
time-local: 12 wallclock secs (11.76 usr + 0.00 sys = 11.76 CPU)
@ 850.34/s (n=10000)
[ ~/test/time-001 ]
This is for routines that do identical parsing of strings, then either
- call Date::Calc::Delta_Days
- use Time::Local to calculate Epoch seconds, take the
difference, and divide by 24*3600
then use the result in a comparison against 28 days.
Anyone able to confirm or deny this? Looks like Date::Calc is
simpler and faster to me.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Wed, 20 Sep 2000 11:24:03 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <39C900C3.6FC8F977@vpservices.com>
Dirk Koppers wrote:
>
> I set a cookie using JavaScript
Doesn't matter how the cookie was set. A cookie is a cookie.
> I need to read the variables from the cookie with CGI.
Use CGI.pm (comes with all modern perls).
See the CGI.pm documentation section titled "HTTP Cookies" and the
sample "cookie.cgi" script that comes with the module.
For example:
#!/usr/local/bin/perl -Tw
$|++;
use strict;
use CGI;
$query = new CGI;
my %items = $query->cookie(-name=>'lightbox');
# the cookie called 'lightbox'
# is now in a perl hash called '%items'
HTH,
--
Jeff
------------------------------
Date: Wed, 20 Sep 2000 13:24:47 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <39C900EF.8EDE5B92@rac.ray.com>
Dirk Koppers wrote:
>
(snip)
>
> Now my question:
> I want to "translate" this function to read this cookie with
> CGI-script. With other words: The table that is created need
> to be created with CGI so I need to read the variables from
> the cookie with CGI.
>
What kind of help did you want? Do you know JavaScript and Perl? Or
did you just want someone to do it for you?
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Wed, 20 Sep 2000 15:07:48 -0400
From: "Dirk Koppers" <nospam@jillanddirk.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <8qb1t7$f3vbv$1@ID-39012.news.cis.dfn.de>
>What kind of help did you want? Do you know JavaScript and Perl? Or
>did you just want someone to do it for you?
Wouldn't that be nice. But realisticaly: Yes I know some JavaScript and
Perl. It is very messy what I write but it often works for me.
I just hoped you could help me on the right track. I need to read the
variables from the cookie in my script. I know how to do that with
JavaScript but not with CGI.
From an other poster I got this:
+++++++++++++++
> #!/usr/local/bin/perl -Tw
> $|++;
> use strict;
> use CGI;
> $query = new CGI;
> my %items = $query->cookie(-name=>'lightbox');
> # the cookie called 'lightbox'
> # is now in a perl hash called '%items'
++++++++++++++++++
Now how do I acces this "hash". Do I use the "split" command to read each
variable?
The cookie looks like this:
++++++++++++++++++++++
lightbox
null[image1|id1|pathtoimage1|JPG|1][image2|id2|pathtoimage2|JPG|1][image3|
id3|pathtoimage3|JPG|1][etc...]
www.humanistic-photography.com/
0
3102621696
30124224
1861654560
29369140
*
++++++++++++++++++++++++++++++++
Again cookie works with javascript I only need to read it with CGI
To see an example of what I have right now goto:
http://www.humanistic-photography.com/cgi-bin/imagefolio/imageFolio.cgi?di
rect=GENERAL/business_people
Add images to the LightBox and view the LightBox by clicking on "view
lightbox". You will see that it works but to improve this I need to add
some CGI functionality.
Thanks,
Dirk Koppers
------------------------------
Date: Wed, 20 Sep 2000 15:10:15 -0400
From: "Dirk Koppers" <nospam@jillanddirk.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <8qb219$f4v96$1@ID-39012.news.cis.dfn.de>
> #!/usr/local/bin/perl -Tw
> $|++;
> use strict;
> use CGI;
> $query = new CGI;
> my %items = $query->cookie(-name=>'lightbox');
> # the cookie called 'lightbox'
> # is now in a perl hash called '%items'
>
Thanks Jef,
I think I can work with this if you could help just a little with the next
step though:
I assume I can read this hash (%items) and split the variables? How do I
read the hash?
Thanks again,
Dirk Koppers
------------------------------
Date: Wed, 20 Sep 2000 19:14:42 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <C08y5.596$zo2.195798@news.uswest.net>
"Dirk Koppers" <nospam@jillanddirk.com> elucidates:
>> #!/usr/local/bin/perl -Tw
>> $|++;
>> use strict;
>> use CGI;
>> $query = new CGI;
>> my %items = $query->cookie(-name=>'lightbox');
>> # the cookie called 'lightbox'
>> # is now in a perl hash called '%items'
>>
>
>
> Thanks Jef,
>
> I think I can work with this if you could help just a little with the next
> step though:
>
> I assume I can read this hash (%items) and split the variables? How do I
> read the hash?
You go buy a frikin' book, or read the dang documents. Perl has a minimum
of data types, so at a bare minimum, you aught to know how to use them.
Here's a hint.
perldoc -f keys
perldoc -f values
perldoc -f each
------------------------------
Date: Wed, 20 Sep 2000 15:37:39 -0400
From: "Dirk Koppers" <nospam@jillanddirk.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <8qb3l1$esjgc$1@ID-39012.news.cis.dfn.de>
> You go buy a frikin' book, or read the dang documents. Perl has a
minimum
> of data types, so at a bare minimum, you aught to know how to use them.
Thank you for your kind words. I do agree though, I should be able to
figure out what a hash is and what I can do with it. Instead of reading a
complete manual I hoped someone could lead me the way. I already read a
lot about Perl and JavaScript (never enough) but since I don't use it
often I keep forgetting those basics.
Thanks for participating in my search to solve this problem.
Dirk Koppers
P.S. I cant use:
perldoc -f keys
perldoc -f values
perldoc -f each
I don't have perl installed, sad he :-(. Instead I write a script, upload
it to the server and see if it works. Very unprofessional but it gets me
there. Often with help of you guys!!
------------------------------
Date: Wed, 20 Sep 2000 20:01:06 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <6I8y5.615$zo2.213518@news.uswest.net>
"Dirk Koppers" <nospam@jillanddirk.com> elucidates:
>> You go buy a frikin' book, or read the dang documents. Perl has a
> minimum
>> of data types, so at a bare minimum, you aught to know how to use them.
>
>
> Thank you for your kind words. I do agree though, I should be able to
> figure out what a hash is and what I can do with it. Instead of reading a
> complete manual I hoped someone could lead me the way.
Asking how to use a hash is strong evidence that you need more than
leading. It says "I am completely unfamiliar with Perl."
> I already read a lot about Perl and JavaScript (never enough) but since
> I don't use it often I keep forgetting those basics.
What document did you read that didn't introduce you to hashes?
> P.S. I cant use:
> perldoc -f keys
> perldoc -f values
> perldoc -f each
> I don't have perl installed, sad he :-(.
Perl is freely available for your platform. If you are doing
development work, you aught to have in installed.
You can also point your browser at www.perl.com and click on the
big red "documentation" link, and read the same documents.
--
"Civilization rests on two things: the discovery that fermentation
produces alcohol, and the voluntary ability to inhibit defecation.
And I put it to you, where would this splendid civilization be without
both?" --Robertson Davies "The Rebel Angels"
------------------------------
Date: Wed, 20 Sep 2000 16:24:47 -0400
From: "Dirk Koppers" <nospam@jillanddirk.com>
Subject: Re: translate JavaScript to CGI (read cookie)
Message-Id: <8qb6d2$f6f96$1@ID-39012.news.cis.dfn.de>
> Asking how to use a hash is strong evidence that you need more than
> leading. It says "I am completely unfamiliar with Perl."
>
If you say so.
> > I already read a lot about Perl and JavaScript (never enough) but
since
> > I don't use it often I keep forgetting those basics.
>
> What document did you read that didn't introduce you to hashes?
The reading I've done was alway regarding a problem I couldn't fix. By
looking at examples given everywhere on the net I did most of my learning.
The term "hash" has been introduced to me and I am sure I have used it
before. It just didn't ring a bell.
Have a nice day and thanks for you comments,
Dirk Koppers
>
> > P.S. I cant use:
> > perldoc -f keys
> > perldoc -f values
> > perldoc -f each
> > I don't have perl installed, sad he :-(.
>
> Perl is freely available for your platform. If you are doing
> development work, you aught to have in installed.
>
> You can also point your browser at www.perl.com and click on the
> big red "documentation" link, and read the same documents.
>
> --
> "Civilization rests on two things: the discovery that fermentation
> produces alcohol, and the voluntary ability to inhibit defecation.
> And I put it to you, where would this splendid civilization be without
> both?" --Robertson Davies "The Rebel Angels"
------------------------------
Date: 20 Sep 2000 20:29:05 +0100
From: nobull@mail.com
Subject: Re: What's wrong with that regexp?
Message-Id: <u9em2eg8vy.fsf@wcl-l.bham.ac.uk>
"FX" <FX@hasnomail.com> writes:
"Hasnomail"? What about "hasnoperlmanauals"? Perl regular
expressions are documented in the "perlre" manual.
> I want to check if a filename, contained in a file, is a valid one.
> I don't want then to have \ / : * ? " < > |
> So I tried this :
>
> if ($fileName =~ /-?[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]$/){
> print "bad file name : $fileName";
> }
You have anchored the pattern to the end of the string so are checking
only if the last character is one of the forbidden characters.
You are really emphatic about the | aren't you? You include it no
less than 9 times in your character class!
You are also check so see if the illegal character is preceded by an
optional hyphen. This is meaningless as every character in every
string is always preceded by 0, 1 or more hyphens.
if ($fileName =~ /[\\\/:*?"<>|]/){
print "bad file name : $fileName";
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 20 Sep 2000 15:59:39 -0400
From: "Jack Chen" <xchen@helix.nih.gov>
Subject: Where can I find a cgi for Usenet forum
Message-Id: <8qb4p2$bqm1@icet.net.nih.gov>
Hi,
There are many forum/BBS cgi available on the net, but I can not find one
which can hook up to the Usenet, just like deja.com does. I want put a
Message board on the net so people can read/reply Usenet messages on the
web.
Thanks in advance
Jack
------------------------------
Date: Wed, 20 Sep 2000 21:14:48 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Where can I find a cgi for Usenet forum
Message-Id: <cN9y5.1804$hD4.490195@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8qb4p2$bqm1@icet.net.nih.gov>,
"Jack Chen" <xchen@helix.nih.gov> writes:
> There are many forum/BBS cgi available on the net, but I can not find one
> which can hook up to the Usenet, just like deja.com does. I want put a
> Message board on the net so people can read/reply Usenet messages on the
> web.
Because doing so would:
1. Potentially consume VAST amounts of bandwidth
2. Be very slow -or- take up LARGE amounts of disk space
3. Violate most ISP's AUPs.
4. Violate most Newsfeed's AUPs.
5. Compete with services already in place (like deja)
Usenet is not a cheesy little BBS system like Slashdot.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4390
**************************************