[15585] in Perl-Users-Digest
Perl-Users Digest, Issue: 2998 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 9 21:10:38 2000
Date: Tue, 9 May 2000 18:10:18 -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: <957921017-v9-i2998@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 9 May 2000 Volume: 9 Number: 2998
Today's topics:
Re: Random number (Abigail)
Re: Random number (Abigail)
Re: Random number <lr@hpl.hp.com>
read/write to file on different machine? jhalbrook@my-deja.com
Re: read/write to file on different machine? (Jerome O'Neil)
regular expression: how do I accept +integers or +float <et@telus.net>
Re: regular expression: how do I accept +integers or +f <lr@hpl.hp.com>
Re: regular expression: how do I accept +integers or +f <Jonathan.L.Ericson@jpl.nasa.gov>
Re: semaphores under perl <rootbeer@redcat.com>
Re: signal trapper <andy@u2me3.com>
Strange Characters from Perl Script <dguiney@lineone.net>
Re: Strange Characters from Perl Script <lr@hpl.hp.com>
Re: system(@args) command <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Unix command as other user <rootbeer@redcat.com>
Re: using Perl's RE to do basic manipulation of a flex <ronnie@catlover.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 May 2000 22:28:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Random number
Message-Id: <slrn8hh499.efl.abigail@ucan.foad.org>
On Fri, 28 Apr 2000 11:49:11 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
++ In article <3909D77B.11AE365F@walgreens.com> on Fri, 28 Apr 2000
++ 13:24:59 -0500, Andrew N. McGuire <andrew.mcguire@walgreens.com> says...
++
++ ...
++
++ > ... If srand is called more
++ > than once, rand will not work properly. As Larry pointed
++ > out some older versions of Perl require better initialization
++ > than what I pointed out ( although that was not my point ).
++
++ I might as well show the entire initialization that I use:
++
++ srand $^T ^ $$ + ($$ << 15) if $] < 5.004 && 1 =~ ?1?; # Once only.
++
++ So shoot me for the flagless once-only switch. :-)
Cute, but does it have any advantages over:
BEGIN {srand $^T ^ $$ + ($$ << 15) if $] < 5.004}
?
Abigail
------------------------------
Date: 9 May 2000 22:40:22 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Random number
Message-Id: <slrn8hh4um.efl.abigail@ucan.foad.org>
On Fri, 28 Apr 2000 12:17:31 GMT, Chello <stephane@siw.ch> wrote:
++ Hi all,
++
++ I have a little problem I have to generate a random number with two limits
++ (upper limit and down limit) for example 1 and 4. When I call the script
++ this script would have to display "1" or "2" or "3" or "4". Does somebody
++ knows how to do it? Do you have an example?
++
my $r = [1 .. 4] -> [rand 4];
Abigail
------------------------------
Date: Tue, 9 May 2000 15:47:42 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Random number
Message-Id: <MPG.138235687987e4cf98aa3e@nntp.hpl.hp.com>
In article <slrn8hh499.efl.abigail@ucan.foad.org> on 9 May 2000 22:28:57
GMT, Abigail <abigail@foad.org> says...
> On Fri, 28 Apr 2000 11:49:11 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
...
> ++ srand $^T ^ $$ + ($$ << 15) if $] < 5.004 && 1 =~ ?1?; # Once only.
> ++
> ++ So shoot me for the flagless once-only switch. :-)
>
>
> Cute, but does it have any advantages over:
>
> BEGIN {srand $^T ^ $$ + ($$ << 15) if $] < 5.004}
>
> ?
A truly infinitesimal advantage (other than the legitimate use of ??,
which has been decried).
It was embedded into a subroutine just ahead of the only call to rand()
in the program, so would never be executed at all unless the rand() was
needed, whereas in the BEGIN it would always be executed once.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 09 May 2000 23:35:53 GMT
From: jhalbrook@my-deja.com
Subject: read/write to file on different machine?
Message-Id: <8fa7co$bnb$1@nnrp1.deja.com>
I'm assuming that one can read/write to flat-files (CSV)
on a different machine than where the script runs. Is
this true? If so, can someone please help me get started
by pointing me in the right direction. I'll pay if you
can help.
Thank you, in advance.
J. Halbrook
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 10 May 2000 00:10:59 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: read/write to file on different machine?
Message-Id: <nO1S4.24$o61.1125@news.uswest.net>
In article <8fa7co$bnb$1@nnrp1.deja.com>,
jhalbrook@my-deja.com writes:
> I'm assuming that one can read/write to flat-files (CSV)
> on a different machine than where the script runs. Is
> this true? If so, can someone please help me get started
> by pointing me in the right direction.
NFS is always freindly for this type of thing.
Check your systems documentation for 'mount.'
> I'll pay if you can help.
Just send a donation in my name to a childrens charity, and
we'll call it square.
Beer makes for a fine barter as well.
------------------------------
Date: Tue, 9 May 2000 17:24:06 -0700
From: "Ed Toivanen" <et@telus.net>
Subject: regular expression: how do I accept +integers or +floats only?
Message-Id: <bW1S4.7462$t8.36993@news.bc.tac.net>
Hi,
I'm trying to accept only positive numbers, that look like either integers
or floats. When I say "look like", I mean 1 or 1.1 or .1, not in reference
to any particular data type.
The signed portion isn't that important, so that is OK.
This is my regular expression so far.
if( $days[$i] =~ /\d+\.{0,1}\d{0,1}/){ #makes any non-digit = 0 except
for decimal
#accept value
} else {
$days[$i] = 0;
}
The problem is that while this thing does filter out 'abc' it does not
filter out 't9.0'. As you can see, I am trying to accept one or more digits,
0 or 1 decimal point, and 0 or 1 digit after the decimal.
How can I make this thing work?
Thanks, Ed
et@telus.net
------------------------------
Date: Tue, 9 May 2000 17:39:54 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: regular expression: how do I accept +integers or +floats only?
Message-Id: <MPG.13824fb95e9c93ae98aa45@nntp.hpl.hp.com>
In article <bW1S4.7462$t8.36993@news.bc.tac.net> on Tue, 9 May 2000
17:24:06 -0700, Ed Toivanen <et@telus.net> says...
> I'm trying to accept only positive numbers, that look like either integers
> or floats. When I say "look like", I mean 1 or 1.1 or .1, not in reference
> to any particular data type.
>
> The signed portion isn't that important, so that is OK.
>
> This is my regular expression so far.
> if( $days[$i] =~ /\d+\.{0,1}\d{0,1}/){ #makes any non-digit = 0 except
> for decimal
> #accept value
> } else {
> $days[$i] = 0;
> }
>
> The problem is that while this thing does filter out 'abc' it does not
> filter out 't9.0'. As you can see, I am trying to accept one or more digits,
> 0 or 1 decimal point, and 0 or 1 digit after the decimal.
>
> How can I make this thing work?
By reading the wonderful Perl FAQ!
perldoc -q number
will point you here:
perlfaq4: "How do I determine whether a scalar is a
number/whole/integer/float?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 09 May 2000 17:44:03 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: regular expression: how do I accept +integers or +floats only?
Message-Id: <3918B0D3.1529BB47@jpl.nasa.gov>
Ed Toivanen wrote:
> I'm trying to accept only positive numbers, that look like either integers
> or floats. When I say "look like", I mean 1 or 1.1 or .1, not in reference
> to any particular data type.
>
> The signed portion isn't that important, so that is OK.
Why not do something like this:
if ($days[$i] > 0){
#accept value
}else{
$days[$i] = 0;
};
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Tue, 9 May 2000 15:27:03 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: semaphores under perl
Message-Id: <Pine.GSO.4.10.10005091524340.3921-100000@user2.teleport.com>
On Tue, 9 May 2000, Cary Lewis wrote:
> I am running under BSDI so semget is there. How can I install the
> appropriate module locally, if the system does not already have it
> configured this way?
Re-compile and re-install perl, making sure that it's configured to
recognize your system has semget and friends. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 9 May 2000 23:17:05 +0100
From: "Andy Chantrill" <andy@u2me3.com>
Subject: Re: signal trapper
Message-Id: <8fa2pb$fko$1@plutonium.btinternet.com>
Hey,
Good suggestion, but I already tried that ...
1. Upon capture of a signal; set a flag.
2. End signal trapper;
3. User hits [enter] to re-initialise "status" sub-routine.
4. "Caught Signal" error is displayed to user.
^ Only problem with that is that because the user is sitting at a standard
input prompt, they have to hit [enter] (or an invalid selection followed by
[enter]) in order to re-initialise the "status" sub-routine, and display the
error. I'd prefer the error to be displayed straight away, as soon as the
signal is trapped.
Thanks, Andy.
andy@u2me3.com
------------------------------
Date: Tue, 9 May 2000 23:11:54 +0100
From: "David Guiney" <dguiney@lineone.net>
Subject: Strange Characters from Perl Script
Message-Id: <8fa2fu$4em$1@supernews.com>
I have written a perl cgi script on a unix server (running apache) which
collects form data and displays it as html page. The same script on windows
based servers works fine when I input characters like the plus sign or round
brackets. When I run this on the unix server it returns strange codes eg
left and right brackets are returned as %28 and %29. Can you please suggest
any reason why this may be happening and is there a fix. The script is a
simple one written in perl.
If you want to test this you can use the web page:
www.celticmarketing.com/testform.html
This calls the following script:
*******************************
#!/usr/bin/perl
print "Content-type: text/html\n\n";
# - get form information and parse data
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
#
#- split up into pairs and convert from hex
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
#
######################### - trap extraneous input - ####################
$value =~s/<!--(.|\n)*-->//g;
######################### - deal with duplicates - ####################
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
#output the data
print "Here is the form data:<ul>";
foreach $key (keys %formdata) {
print "<li>$key: $formdata{$key}";
print logf "$key: $formdata{$key}\n";
}
print "</ul>";
#also output all the environment variables
print "<p><p>and here are all the environment variables:<ul>";
foreach $key (keys %formdata) {
print "<li>$key: $ENV{$key}"; }
print "</ul>";
Any help would be much appreciated.
David
------------------------------
Date: Tue, 9 May 2000 15:57:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Strange Characters from Perl Script
Message-Id: <MPG.1382379c3bcd66a898aa40@nntp.hpl.hp.com>
In article <8fa2fu$4em$1@supernews.com> on Tue, 9 May 2000 23:11:54
+0100, David Guiney <dguiney@lineone.net> says...
> I have written a perl cgi script on a unix server (running apache) which
> collects form data and displays it as html page. The same script on windows
> based servers works fine when I input characters like the plus sign or round
> brackets. When I run this on the unix server it returns strange codes eg
> left and right brackets are returned as %28 and %29. Can you please suggest
> any reason why this may be happening and is there a fix. The script is a
> simple one written in perl.
...
> $key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
When you are copying cargo-cult code (good alliteration, again), copy it
exactly. There are is a space in each of those regexes where than can
be none in the input string.
I dispute your assertion that this works differently on different
operating systems. It can't work right anywhere.
...
> Any help would be much appreciated.
Replace your input parsing with CGI.pm, right away.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 09 May 2000 15:25:11 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: system(@args) command
Message-Id: <39189047.8BDE3AEF@jpl.nasa.gov>
spurcell wrote:
> My question:
> I am thinking that system(@args) should return either a true or false, or a
> 1 or 0. I don't like the way it is just hanging there with no checks whether
> it was successful or not.
>
> Does anyone have a good way of checking if this was good or bad?
'perldoc -f system' (Faster than posting c.l.p.misc and fewer
keystrokes.)
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Tue, 9 May 2000 15:11:10 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Unix command as other user
Message-Id: <Pine.GSO.4.10.10005091504210.3921-100000@user2.teleport.com>
On Tue, 9 May 2000, JagMan wrote:
> How do I execute unix command as user joe in perl? I am running perl
> with root id.
Change your user-id (and probably group-id). Read perlsec, see $< and $>
and $( and $) in perlvar, read perlsec again, and be really sure you know
what you're doing. :-)
It may also be a good idea to read your system's manpages for the system
calls that perl has to use behind the scenes. Start with setuid(2), and
see also the ones it refers you to.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 09 May 2000 23:07:51 GMT
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: using Perl's RE to do basic manipulation of a flex file
Message-Id: <39181C9E.4BFE6D1F@catlover.com>
> Is it simply that you want to match substring-foo in string-bar, but your
> pattern matches more or less than you wish?
Yes.
> Can you cut the problem down to just two or three possible source strings,
I want to change:
[A-Za-z]{DIGIT} {some_function(); return ALPHA_WITH_DIGIT_TOKEN;}
{ANOTHER_TOKEN}[0-9] { blah( ) ; return TOKEN2 ; }
into
[A-Za-z]{DIGIT} { printf("[ALPHA_WITH_DIGIT_TOKEN] %s",yytext); }
{ANOTHER_TOKEN}[0-9] { printf("[TOKEN2] %s", yytext); }
> and your attempt at making a pattern to do the job?
The following RE produces undesirable output becuase it starts at the
first left bracket ( the bracket containing {DIGIT} instead of starting
at the second left bracket ):
$temp = <<'EOP';
[A-Za-z]{DIGIT} { some_function(); return ALPHA_WITH_DIGIT_TOKEN; }
{ANOTHER_TOKEN}[0-9] { blah(); return TOKEN2 ; }
EOP
$temp =~ s#{.*?return\s+(\w+).*?}#{printf("[$1] %s", yytext);}#gs;
print $temp;
This RE is not correct either:
$temp =~ s#(?={.*?})*{.*?return\s+(\w+).*?}#{printf("[$1] %s",
yytext);}#gs;
^^^^^^^^^^ zero or more bracket pairs in front
------------------------------
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 2998
**************************************