[6947] in Perl-Users-Digest
Perl-Users Digest, Issue: 572 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 21:07:55 1997
Date: Wed, 4 Jun 97 18:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 4 Jun 1997 Volume: 8 Number: 572
Today's topics:
Re: Atomic file create or fail if already existing (Jot Powers)
Re: data structure question (Chipmunk)
File glob works as root, but fails as regular user (?) <dglaser@intercall.net>
Re: Finding string length (Nathan V. Patwardhan)
Re: Finding string length <sibsib@hotmail.com>
Re: Finding string length (Tad McClellan)
Re: Help building a regexp (bug?) <rootbeer@teleport.com>
Re: Help building a regexp (bug?) <ajohnson@gpu.srv.ualberta.ca>
Re: Help building a regexp (bug?) (Eric Roode)
Re: Help building a regexp (bug?) (Eric Roode)
HELP port PERL from HP-UX to SPARC5 <anna@water.ca.gov>
Help with weird cron interaction (Dave Mencin)
How can I set up this server to run perl faster?... <perlprogrammer@hotmaill.com>
Re: how do I delete all the $s from a string(probably s (Michael James Braunstein)
Re: Isdigit(), isalpha() in Perl (Winfried Koenig)
Re: Making a pool, but one man = one vote (Craig Berry)
Re: mount command in an suid script - howto ? <rootbeer@teleport.com>
Re: Newbie question <ajohnson@gpu.srv.ualberta.ca>
Re: open won't open files in subdirectories? <pociask@maricopa.edu>
Re: Opening File Handle to a function. (Andy Wardley)
Re: pack template that packs like 'a' but unpacks like <rootbeer@teleport.com>
Re: Reading Comma delimited, Quoted String records (Tad McClellan)
Re: Segmentation fault from multiple mkdirs in Perl scr <rootbeer@teleport.com>
Re: tr problems with variables <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Jun 1997 22:23:47 GMT
From: jot@tmp.medtronic.com (Jot Powers)
Subject: Re: Atomic file create or fail if already existing
Message-Id: <5n4ptj$pm1$1@gazette.corp.medtronic.com>
In article <5n479t$6b4@puma.rentec.com>, rick@rentec.com (R Bradley) writes:
>Leonard Megliola (lmegliol@inertia.acs.uci.edu) wrote:
>: I need an atomic operation which will create a new file if it
>: doesn't exists, but fail if the file already does exist.
>
>If you're on Unix you can man open(2) and look at O_EXCL and O_CREAT.
>The open in the POSIX module should behave in the same way.
If Tom were here, I think he would say something like:
"These would fail under NFS."
To the best of my knowledge, it is really not possible to do atomic
file operations over NFS.
--
Jot Powers jot@tmp.medtronic.com
Unix System Administrator, Medtronic Micro-Rel
"Subtlety is the art of saying what you think and getting out of the way
before it is understood."
------------------------------
Date: 4 Jun 1997 22:40:20 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: data structure question
Message-Id: <5n4qsk$krh$1@dartvax.dartmouth.edu>
In article <5n4av3$41e@news-central.tiac.net>
mike@stok.co.uk (Mike Stok) writes:
> In article <5n1n51$unk$1@dartvax.dartmouth.edu>,
> Chipmunk <Ronald.J.Kimball@dartmouth.edu> wrote:
>
> >> while ($quote=<QUOTES>){
> >
> >This will end prematurely if a line in the file evaluates to false
> >(such as "0\n");
> >I'd suggest:
> >while (<QUOTES>) {
>
> ...but "0\n" is true.
I have decided that from now on the string "0\n" shall be false.
Just thought you'd all like to know.
:-)
Chipmunk
------------------------------
Date: Wed, 04 Jun 1997 20:06:35 -0400
From: David Glaser <dglaser@intercall.net>
Subject: File glob works as root, but fails as regular user (?)
Message-Id: <3396030B.70C0D8E6@intercall.net>
Hi All,
I'm totally new at perl, learning it via llama and camel books on a
linux 2.0.27 system. Here's my problem (code sample from the llama
book):
When I try anything like
While ($filename = <*.secret>) {
.....
....
}
(which is actually part of the "say hello" script at the end of chap. 1
of the llama book)
The file glob for "*.secret" works perfect when I'm su to root, and I
can print the filenames returned, etc...,
but if I'm my normal non-root user I get a message:
sh: /dev/null: permission denied
The "say hello" script continues to operate in either root or non-root
user runs, and there are no apparent typos in the script, at least
because it compiles with no errors........
I don't understand what I'm doing wrong, or if I missed something
simple... I've read the man pages and the book sections on glob() and
<> but have found no answer. I attempted a bit of system("echo
*.secret") and this seems to work, so I'm pretty sure I don't have any
permissions problems....
In testing & reading to educate myself it appears that perl calls the
shell (sh) in order to do the glob, and appears to try to execute
/dev/null which of course is chmod ugo-x and so gives the message
"permission denied" above (at least that's what it looks like to me).
If someone can point me at some doc that I missed, or maybe can explain
it, I would greatly appreciate it.
Thanks.
--
"Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read." - Groucho
David Glaser
dglaser@intercall.net
------------------------------
Date: 4 Jun 1997 21:36:00 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Finding string length
Message-Id: <5n4n40$84q@fridge-nf0.shore.net>
Kieran Tully (tullyk@tcd.ie) wrote:
: How can I find the length of a string (or more particularly a line) in
: Perl ?
What's wrong with length(WHATEVER) ?
I know how to get the length of an array; is there a way to convert
: a string so that it can be treated as an array of chars ? (or does Perl
Sure. (@mychars) = split(//, $val);
: even have a concept of arrays of chars ? - as you can probably guess, I'm
: quite new to it.)
To tell you the truth, I've never really had to fool with an array of
characters; since Perl has regular expressions, s, tr, etc., I can't
think of a situation where I'd have to.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Wed, 04 Jun 1997 19:32:39 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: Finding string length
Message-Id: <3395FB17.56C9BD88@hotmail.com>
Kieran Tully wrote:
> How can I find the length of a string (or more particularly a line) in
> Perl ? I know how to get the length of an array; is there a way to convert
> a string so that it can be treated as an array of chars ? (or does Perl
> even have a concept of arrays of chars ? - as you can probably guess, I'm
> quite new to it.)
Kieran -
Please try the very-appropriately-named perl FAQ, which is posted
to this group quite often.
You could also try a DejaNews search (www.dejanews.com).
You could also read the very comprehensive man pages.
Scott
--
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net
------------------------------
Date: Wed, 4 Jun 1997 17:27:51 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Finding string length
Message-Id: <75q4n5.teb.ln@localhost>
Kieran Tully (tullyk@tcd.ie) wrote:
[ snip ]
: is there a way to convert
: a string so that it can be treated as an array of chars ?
[ snip ]
@chars = split //, $string;
[ though for your real question length() would be the way to go... ]
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 4 Jun 1997 15:56:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Roode <sdn@mv.mv.com>
Subject: Re: Help building a regexp (bug?)
Message-Id: <Pine.GSO.3.96.970604154807.26571F-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, Eric Roode wrote about matching names from a list:
> One complication is that the names can contain special characters;
> in fact, one of the names has a pipe character in it. So I have
> to include \Q and \E in my join. No problem, I thought.
Actually, there might be a problem. If \Q is already found in an
interpolated string, it won't be further interpolated, as this shows.
$foo = '\\Q Is the | or \\ quoted?';
$bar = "$foo Nope!";
print "$bar\n";
The double-quotish string (in your case, the regexp) is first checked for
\Q-type magic, then for things to interpolate. Once a string is
interpolated, it's not checked again for magic.
The solution is to use quotemeta on the items before they're ready for
interpolation, something like this. (I haven't checked this, but I think
it will do what you need.)
@names = qw(fred barney mr.slate dino);
$any = join "|", map(quotemeta($_), @names);
$pattern = "$any.*?$any";
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Wed, 04 Jun 1997 12:13:29 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
To: Eric Roode <sdn@mv.mv.com>
Subject: Re: Help building a regexp (bug?)
Message-Id: <3395A239.661E71DF@gpu.srv.ualberta.ca>
[cc'd to cited author]
Eric Roode wrote:
!
! I am trying to match lines of the form:
!
! (junk) word (junk) word (junk)
!
! where (junk) is irrelevant, and (word) is any one of a given
! list of words. This list is used in several places in the
! program, and is subject to change, so I want to define the
! list at the top of the program, and build a regexp from it.
! Presumably the best way to do this is by join'ing the words
! with a pipe character.
!
! One complication is that the names can contain special
! characters; in fact, one of the names has a pipe character
! in it. So I have to include \Q and \E in my join. No
! problem, I thought. However, if you run the following
! fragment, you will see that it did not work as I expected:
!
!
! I am using perl 5.003 on an SGI and on a Sequent. Obviously,
! I could break the line up into words and parse them
! individually, but this seems clumsy to me when a simple
! regexp should do it. Clues, anyone?
but if your list of names is long it creates a lengthy
regex with many alternations---could be slow. The following
is a variation on a 'defined identifier' recognizer I am working on
for a perl implementation of an existing literate programming
tool:
the identifiers are keys in a hash, then every line
can be broken into possible identifiers rather easily using
(\S+) for your case and simply loop through the supposed
names and test for existence of that hash key---print line
if exists, and exit line-loop:
%names=map{$_=>1} qw(Eric Matt Jeff na|me);
while (<DATA>) {
while (/(\S+)/g) {
exists $names{$1} && print $_ and last;
}
}
__DATA__
line with na|me and Eric
line with no names
line with Matt
this also avoids the necessity of dealing with metacharacters
in a regex...you can modify to do something other than just
printing the line at the first occurence of a recognized
name.
hope it helps
regards
andrew
------------------------------
Date: Thu, 5 Jun 1997 00:34:54 GMT
From: sdn@mv.mv.com (Eric Roode)
Subject: Re: Help building a regexp (bug?)
Message-Id: <EBA1M6.3qI@mv.mv.com>
In article <Pine.GSO.3.96.970604154807.26571F-100000@kelly.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Wed, 4 Jun 1997, Eric Roode wrote about matching names from a list:
[...]
>Actually, there might be a problem. If \Q is already found in an
>interpolated string, it won't be further interpolated, as this shows.
>
> $foo = '\\Q Is the | or \\ quoted?';
> $bar = "$foo Nope!";
> print "$bar\n";
>
>The double-quotish string (in your case, the regexp) is first checked for
>\Q-type magic, then for things to interpolate. Once a string is
>interpolated, it's not checked again for magic.
Ah, I hadn't thought of that.
>The solution is to use quotemeta on the items before they're ready for
>interpolation, something like this. (I haven't checked this, but I think
>it will do what you need.)
>
> @names = qw(fred barney mr.slate dino);
> $any = join "|", map(quotemeta($_), @names);
> $pattern = "$any.*?$any";
>
>Hope this helps!
Excellent! I'm sure it will. Thanks.
Eric
P.S.: Nice example: "mr.slate" <grin>
--
"I feel my body weakened by the years
As people turn to gods of cruel design
Is it that they fear the pain of death
Or could it be they fear the joy of life?" -- Toad The Wet Sprocket
------------------------------
Date: Thu, 5 Jun 1997 00:32:52 GMT
From: sdn@mv.mv.com (Eric Roode)
Subject: Re: Help building a regexp (bug?)
Message-Id: <EBA1It.3pK@mv.mv.com>
In article <3396bfe2.23799454@10.0.2.33>,
Ronald L. Parker <ron@farmworks.com> wrote:
>On Wed, 4 Jun 1997 11:16:42 GMT, sdn@mv.mv.com (Eric Roode) wrote:
>
>When I run your program (ActiveWare NTPerl build 303) I get:
>
>Input: QEricE and QMattE
>Output: Explicit pattern: Eric, Matt
> Without quoting: Eric, Matt
> With quoting: QEricE, QMattE
> Double quoting: QEricE, QMattE
You're right; I forgot to include that last line.
>Building on the results of your match for the explicit pattern, I
>found something you might be able to use to work around this problem:
>
> eval "(\$one,\$two) = /($anyQ).*($anyQ)/oi";
> print "Eval: $one, $two\n" if $one && $two;
Yeah, I think that would work. Guess TMTOWTDI :-)
Eric
--
"I feel my body weakened by the years
As people turn to gods of cruel design
Is it that they fear the pain of death
Or could it be they fear the joy of life?" -- Toad The Wet Sprocket
------------------------------
Date: Wed, 04 Jun 1997 16:32:13 -0700
From: Anna Fong <anna@water.ca.gov>
Subject: HELP port PERL from HP-UX to SPARC5
Message-Id: <3395FAFD.1AFE@water.ca.gov>
I have a perl script running on an HP-UX 9.05. An HTML form triggers the script. It
runs as expected. When I tried using the script on a SPARC5, it bombs. The script
doesn't use any libraries. The HP is running NCSA httpd 1.4.1 and perl5.001. The
SPARC is running Netscape Enterprise httpd (version unknown) and perl5.002.
The message in the error log doesn't make any sense.
Are there certain things I should be checking for?
Anna
------------------------------
Date: Wed, 04 Jun 1997 17:42:24 -0500
From: dmencin@unavco.ucar.edu (Dave Mencin)
Subject: Help with weird cron interaction
Message-Id: <dmencin-0406971742240001@lhotse.unavco.ucar.edu>
I have been having a problem running a perl script from a crontab.
I have verified all the paths (i.e. a simple perl program works fine.)
I run the following two programs.
*****TEST.pm*****
package TEST;
use Exporter ();
@ISA = qw( Exporter );
@EXPORT = qw( test_routine );
sub test_routine {
print STDOUT "Entering test_routine\n";
print STDOUT "This is a test message\n";
}
***********
is called by the following program
*****tester*****
#!/usr/bin perl
use TEST;
print STDOUT "Entering tester and calling test_sub\n";
test_routine ();
print STDOUT "Ending ...\n";
**********
if at the command line I enter
perl tester | /usr/ucb/Mail -s "test" dmencin@unavco
I get a an email with the following output
Entering tester and calling test_sub
Entering test_routine
This is a test message
Ending ...
if I put the following line in my crontab
* * * * * perl tester | /usr/ucb/Mail -s "test" dmencin@unavco
I get a blank email every minute.
All paths are set up in cron using the PATH statement as documented in crontab.
Looking in the system cron log I see that perl itself has a return code of 2.
Any ideas on how to proceed from here ?
Dave
dmencin@unvaco.ucar.edu
--
dmencin@unavco.ucar.edu
________________________________________________________
[]o[] []o[] David Mencin :: Geodetic Eng.
\ / UNAVCO
\ / University NAVSTAR Consortium
\ / P.O. Box 3000, Boulder CO, 80307
<> 497 - 8024 FAX:497 - 8028
/\
_______________________________________________________
------------------------------
Date: Sun, 01 Jun 1997 23:22:22 -0700
From: perl guy <perlprogrammer@hotmaill.com>
Subject: How can I set up this server to run perl faster?...
Message-Id: <32C32A590C2FC98A.DEE78EECC673D950.F1A9127287613D60@library-proxy.airnews.net>
Huge aplogies for the major cross-postings.. but I have NO idea where to
post to, other then the fact that it has to do wth all the formentioned
subjects.
Ok, first off, I am running perl 5.003 on a Linux Kernel 2.0.18 on an
i486 server with Red Hat 4, Apache 1.1.1, 5 disk partiions of 300 Megs
each, 48 MEGS RAM with a 60 MEG swap file..
I am running a chat site that is getting a huge amount of traffic, and I
need to find out a way, to only run one continous instance of perl, or
something that won't chew up the drive or slow things down so terribly!
It's literally killing the hard drive from all the people. I need to
find out a way to configure something too possibly for the best way to
run the server for this sort of thing. I wish it was on the NT bo,
because I could do an ISAPI type thing.. but what can I do on a Linux
with Perl?. I seriously have no idea. every time someone transfers the
data, it's calling to the perl.exe, and wth all the people at once, it's
too much! I read the error logs, and I see a lot of these errors for
example:
"send script output lost connection to client -blah-", *mostly these*
"request lost connection to client -blah-", *a lot of these*
"access to /my_dir/chat.pl failed for -blah-, reason: POST or PUT
without Content-length:" *a few of these*
That's not really the problem though.. I assume that the time out,
keepalive, keepalive timeout, etc. time needs to be set differently..
I'm not sure what these need to be set to really.. as I did the perl..
but my server admin seems to need advice on how to configure the server
better, and I am clueless.. This is why it's partly being posted in the
unix/linux. As well as for the server configs that may help or IDEAS
that may help me with how to run less instances, etc of the perl.exe?. I
am so lost.. the script works great, untill I get over 50 or 60 people
in the rooms.. then it gets very slow and has problems.. it starts to
crash my server, and I have to telnet in and restart the websever 3
times a day!.. it's getting out of control, and I don't have weeks or
months ro read up on this.. unfortunately, it's too late to take the
site down until *I* find out how to configure the script, and the
server, etc.. I am also posting this to the perl news groups, as wel as
cgi because I'm sure that someone there will have some experiance of how
to run things more smoothly in the script configuartion.. something I
may have missed.. sorry this is so vague.. but this is all my problem
seems to be, and I don't have a clue of what to do now!. I hope someone
can help.. for an idea of what's going on (at a slow time of the day), I
go to telnet and type in "ps -aux" and I get this.. you can see how it's
killing my drive..
BTW, the pipe is not being hogged up at all.. it's taking barely any...
Here's what the mess looks like..
USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND
nobody 29774 0.3 1.5 1232 720 ? S 22:11 0:02 httpd
nobody 29936 0.2 1.5 1228 728 ? S 22:14 0:01 httpd
nobody 29985 0.3 1.5 1232 728 ? S 22:15 0:02 httpd
nobody 29991 0.2 1.4 1204 704 ? S 22:15 0:01 httpd
nobody 30075 0.2 1.5 1228 720 ? S 22:16 0:01 httpd
nobody 30128 0.3 1.5 1232 724 ? S 22:17 0:01 httpd
nobody 30180 0.2 1.5 1228 720 ? S 22:18 0:01 httpd
nobody 30189 0.1 1.5 1232 728 ? S 22:18 0:01 httpd
nobody 30504 0.4 1.5 1208 708 ? S 22:24 0:00 httpd
nobody 30528 0.4 1.4 1208 704 ? S 22:24 0:00 httpd
nobody 30531 0.3 1.4 1204 704 ? S 22:24 0:00 httpd
nobody 30534 0.1 1.4 1204 704 ? S 22:24 0:00 httpd
nobody 30582 0.5 1.4 1204 704 ? S 22:25 0:00 httpd
nobody 30587 0.3 1.4 1208 704 ? S 22:25 0:00 httpd
nobody 30589 0.4 1.4 1204 704 ? S 22:25 0:00 httpd
nobody 30590 0.3 1.4 1208 704 ? S 22:25 0:00 httpd
nobody 30595 0.6 1.4 1208 704 ? S 22:25 0:00 httpd
nobody 30598 0.3 1.5 1232 724 ? S 22:25 0:00 httpd
nobody 30602 0.3 1.4 1204 704 ? S 22:25 0:00 httpd
nobody 30604 0.1 1.5 1208 708 ? S 22:25 0:00 httpd
nobody 30620 0.3 1.5 1208 708 ? S 22:25 0:00 httpd
nobody 30622 0.1 1.4 1208 704 ? S 22:25 0:00 httpd
nobody 30623 0.3 1.5 1216 708 ? S 22:26 0:00 httpd
nobody 30630 0.3 1.4 1208 704 ? S 22:26 0:00 httpd
nobody 30633 0.2 1.4 1208 700 ? S 22:26 0:00 httpd
nobody 30636 0.0 1.4 1204 704 ? S 22:26 0:00 httpd
nobody 30641 0.2 1.4 1208 700 ? S 22:26 0:00 httpd
nobody 30642 0.4 1.4 1208 700 ? S 22:26 0:00 httpd
nobody 30687 6.7 3.2 2088 1516 ? R 22:26 0:01 perl5.003 /my
home dir path
nobody 30688 6.0 3.2 2088 1516 ? R 22:26 0:01 perl5.003 /my
home dir path
nobody 30691 7.0 3.2 2092 1520 ? R 22:26 0:01 perl5.003 /my
home dir path
nobody 30692 7.1 3.2 2092 1520 ? R 22:26 0:01 perl5.003 /my
home dir path
nobody 30694 6.2 3.1 2084 1496 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30695 6.6 3.2 2084 1512 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30698 6.5 3.0 2076 1452 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30699 7.0 3.1 2080 1492 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30700 0.0 1.4 1188 672 ? S 22:27 0:00 httpd
nobody 30702 7.7 2.8 2028 1320 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30703 0.1 1.4 1188 672 ? S 22:27 0:00 httpd
nobody 30704 8.4 2.8 2032 1324 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30706 0.1 1.4 1188 672 ? S 22:27 0:00 httpd
nobody 30707 9.5 2.8 2032 1324 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30708 10.1 2.6 1960 1252 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30709 0.1 1.4 1188 672 ? S 22:27 0:00 httpd
nobody 30710 8.0 2.0 1728 964 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30711 11.0 2.3 1864 1120 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30712 8.0 1.6 1548 776 ? R 22:27 0:00 perl5.003 /my
home dir path
nobody 30713 7.0 1.6 1540 768 ? R 22:27 0:00 perl5.003 /my
home dir path
How can I stop this, por fi the problem?. Anyone.. please help.. I beg
of you.. any suggestions, or any pointers to a site that specifically
talks about this.. I have endlessly searched dejanews, and all the other
arhives, been to all the sites for Apache, Linux, Unix, Perl, CGI,
etc..etc.. and no one has any info on this delima..
Thank you very much for the time you took to even read this.. :)
#stressed$%....
------------------------------
Date: 4 Jun 1997 22:11:10 GMT
From: mjb1@alpha3.csd.uwm.edu (Michael James Braunstein)
Subject: Re: how do I delete all the $s from a string(probably simple)
Message-Id: <5n4p5u$lmd@uwm.edu>
The Halls wrote:
: Hi,
:
: For a simple perl script I'm writing, I need to delete all the $
: characters in a variable. Say if my code is:
:
: my $extra_price_1 = '$123.89';
:
: I need the result to be 123.89. I thought it would be something like:
:
: $extra_price_1 =~ s/$//g
:
: This is probably something really simple, but I'm not at all sure what
: the syntax is(I'm very new to Perl). Could anyone help me out? Thanks a
: lot.
$extra_price_1 =~ tr/\$//d; # deletes all '$' chars from var.
# not sure if it needs quoting, did anyway
--
M i c h a e l J a m e s B r a u n s t e i n
I&MT UNIX and Micro-Computer consultant
mjb1@csd.uwm.edu | mjb1@execpc.com | http://www.uwm.edu/~mjb1
------------------------------
Date: Wed, 4 Jun 1997 21:48:11 GMT
From: win@in.rhein-main.de (Winfried Koenig)
Subject: Re: Isdigit(), isalpha() in Perl
Message-Id: <EB9twB.I6H@in.rhein-main.de>
Tom Phoenix <rootbeer@teleport.com> writes:
>On Mon, 2 Jun 1997 ddean@aracnet.net wrote:
>> Is there a function similar to the C functions isdigit or alpha in Perl
>Not as a builtin. But you can easily check whether a letter falls within a
>certain character set. This is often done with regular expressions,
>although it's more efficient to use tr/// if it can do the job. See
>perlop(1) for details. (If you want to do these things in a locale
>dependant manner, see perllocale(1) in Perl version 5.004.)
And if you have the POSIX module:
#!/usr/local/bin/perl -w
use POSIX;
@s = qw(abc 123 ab12 abc!);
foreach (@s) {
print "$_ is print\n" if isprint $_;
print "$_ is alnum\n" if isalnum $_;
print "$_ is digits\n" if isdigit $_;
print "$_ is alpha\n" if isalpha $_;
}
--
Winfried Koenig, Arendsstrasse 12, D-63075 Offenbach
Phone: +49 69 868707, Mail: <win@in.rhein-main.de>
------------------------------
Date: 5 Jun 1997 00:21:49 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Making a pool, but one man = one vote
Message-Id: <5n50qt$3pk$1@marina.cinenet.net>
Ron Mayer (mayer@mpactinc.com) wrote:
: cberry@cinenet.net (Craig Berry), <5m2f8h$nkr$1@marina.cinenet.net>:
: >David Podeur (podeurda@hpweb.utc.fr) wrote:
: >: [...]
: >: I have already make the form but what i need know is to be sure
: >: that no student can vote twice (or more...).
: >: [...]
: >
: >First, this might better have been addressed to the CGI newsgroup; it's
: >not a Perl-specific problem.
:
: Agreed, but there are possible answers specific to perl (see below).
Well, it's a semantic issue. Perl (like any potential CGI implementation
language) will have its own specific ways of handling general problems.
But there's nothing unique to Perl in the *capability* of implementing
any of the approaches embodied in the CPAN modules you recommend. Small
difference, true enough.
: >Second, there is no reliable way to accomplish what you're after in the
: >general case other than to ask each student to provide her own username
: >when she submits the form, and rely on the honor system. One can pretend
: >to do more than this, but each possible method (HTTP data, cookies, and so
: >forth) either fails for some clients and/or servers, is subject to trivial
: >circumvention, or both.
:
: Isn't "no reliable way" a bit of an overstatement?
:
: .../CPAN/modules/00modlist.long.html
:
: has a section named
: "14) Authentication, Security and Encryption (see also Networking)"
: which seems to provide the functionality he needs.
A reliable automatic user authentication scheme (in which the user
does not manually provide any data, see below) requires more data
exchange between the parties (client and server) than is present in an
http: exchange. Encryption of transactions between client and server is
(relatively) easy, via https or whatnot, but authentication is another issue.
: >... control what browser ... special features of this particular
: >configuration ... HTTP environment variables ... cookies ... user
: >can manually delete cookies from her client-side filesystem, and that
: >spoofing usernames may not be all that hard either.
:
: I know zip about CGI, so I don't know whether or not the restrictions
: imposed by CGI would make authentication as impossible as you say, but
: the existance of for-pay services on the net make me suspect the
: easily spoofed approaches you mentioned aren't the only thing available.
The for-pay net services rely on one or both of:
* Manual entry of a password/PIN.
* Use of proprietary front-end software which stores and transmits
a unique registration code.
: Surely some sort of digital signature should work, and IMHO for perl
: the best place to look is in the CPAN section I mentioned.
A digital signature scheme requires significant investment of time and
skill in getting users set up to use it. If you have a fixed pool of
voters, there are two good ways to run things:
* Use names as IDs. If a voter appears to have voted already, warn them
that a possible voting violation has occurred, with a similar email to
the voting administrator. If necessary, resolve the true status of such
ballots by phone, email, or (best of all) in person.
* Use a PIN as an ID, and hand/email distribute the PINs prior to the
election.
: (Or even more trivially, but unrelated to perl, give each student a
: unique random number between 1 and ten million and make them include
: that number with their vote. As long as you have a secure way of
: distributing those numbers the chances of someone voting twice are small.)
That's the PIN scheme. But notice it involves an outside-CGI element,
the PIN distribution step. My point has been that secure voting using
CGI *only* is impossible; there has to be some external work to support it.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Wed, 4 Jun 1997 16:13:12 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de>
Subject: Re: mount command in an suid script - howto ?
Message-Id: <Pine.GSO.3.96.970604161210.766C-100000@kelly.teleport.com>
On 4 Jun 1997, Helmut Jarausch wrote:
> use POSIX qw(setuid);
> setuid(0);
You could do that, but it's easier to do this, which has the same result.
$< = 0; # Set uid to root
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Wed, 04 Jun 1997 11:33:50 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Newbie question
Message-Id: <339598EE.5C280571@gpu.srv.ualberta.ca>
eliasm wrote:
>
> Andrew Johnson wrote:
> >
[snip: several clear examples for obtaining the number of
characters in a string]
> > ;)
> > andrew
>
> Now, what is so wrong with the command "length"?
>
Intuition, thats whats wrong with it. really! Who would think that
length might return a count of things in a string
rather than, say, something in millimeters or points or
picas? What if the strings had been written in a proportional
width font---clearly the expectation then might be that
length("iii") should be less than length("mmm").
The previous examples at least are explicitly giving numbers
based on string position or counting matches or the like,
and therefore are much more maintainable and easily understood.
Moreover, a few of the examples obviously work much harder to
get the results than a simple length command---and wouldn't
you sleep better knowing you've created perl code that works
harder at its job?
Finally, given that the length() command is not prominently
featured in the 2nd ed. Camel, (its short, two paragraph
description doesn't occur until way beyond page 150 and is
hidden in amongst other commands also starting with the letter
"l"), and that it's so obviously counter-intuitive, your
recommendation of it's use here can only be seen as some
kind of attempt at subterfuge and obfuscation!
Besides, others already mentioned it :-)
regards
andrew
.
.
.
.
.
.
.
just in case: while (1) {print ":-)"}
------------------------------
Date: Wed, 04 Jun 1997 15:44:31 -0700
From: Jason Pociask <pociask@maricopa.edu>
Subject: Re: open won't open files in subdirectories?
Message-Id: <3395EFCF.1CEB@maricopa.edu>
Forget it, I found the problem: for some reason the "open" routine
needs the full path name, not a relative path name. I used the cwd()
call to get the current path if the input ARGV resulted in a filename
that started with "./", removing the period and prefixing the full
path onto the subdir/filename. Works fine now.
Changes (also Use Cmd; at top)
$cwd = cwd();
print "Searching For: $casesw $str In paths: @ARGV Path: $cwd\n";
find (\&wanted, @ARGV);
sub wanted {
my $n = $File::Find::name;
if (substr($n,0,1) eq ".") {
$n = "$cwd" . substr($n,1,255);
} else {
$n = substr($n,2,255);
}
I'm sure there's slicker ways than using substr, sorry!
Jason Pociask wrote:
>
> I have a perl script that I want to have walk a directory
> and all subdirectories, opening each -Text file and searching
> for lines that contain at least one instance of a search mask.
> Example output when it dies: (first is a subdir, file_uno a text file)
> ...stuff...
> Searching For: -i foo In paths: .
> /
> first/
> first/file_uno
> Could not open input text file first/file_uno
> fbs.dist.maricopa.edu>
------------------------------
Date: 4 Jun 1997 16:55:20 +0100
From: abw@peritas.com (Andy Wardley)
Subject: Re: Opening File Handle to a function.
Message-Id: <5n4358$5j4@aoxomoxoa.peritas.com>
Junaid Shah [C] <shahjn@cig.mot.com> wrote:
>
>What I want to do is process the output from a function call. I want to
>do the following but I guess I can't, any ideas.
>
Like this... (see also Camel II page 193)
#!/usr/bin/perl -w
# open "|-" causes an implicit fork into reading and writing processes
my $pid = open (MYPIPE, "|-");
# check we didn't get an undef returned from the open
die "fork: $!\n" unless defined($pid);
# if $pid is 0, we are in the child process
$pid || &filter();
# the parent can now do whatever it likes, call functions, etc.
# any output sent to MYPIPE will be piped into the child process
print MYPIPE "hello world\n";
# or select(MYPIPE) for implicit output to MYPIPE
select(MYPIPE);
print "that's all folks...\n";
#
# this is the function which the child process uses to manipulate
# output from the parent process
#
sub filter {
# child process reads from STDIN which is attached to
# MYPIPE of parent process
while (<STDIN>) {
print "child read: $_";
}
# exit child process when finished
exit;
}
#
# Output is as follows:
#
# child read: hello world
# child read: that's all folks...
Hope that helps
A
--
Andy Wardley <abw@peritas.com> **NEW** http://www.peritas.com/~abw
A responsible and professional individual who has no need for silly
comments, inane banter or bizarre "in-jokes" in his signature file.
------------------------------
Date: Wed, 4 Jun 1997 16:09:33 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Valeriy E. Ushakov" <uwe@ptc.spbu.ru>
Subject: Re: pack template that packs like 'a' but unpacks like 'A'
Message-Id: <Pine.GSO.3.96.970604160126.766B-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, Valeriy E. Ushakov wrote:
> Since string is printable, I want nulls to be stripped off when I unpack
> the struct. But when I pack the struct, I want padding with nulls since
> this is the way C wants it.
Oho! I (finally) get it! :-) The problem is that pack and unpack aren't
symmetric when you use 'a' in a template: Trailing nulls are put on with
pack, but they aren't stripped off during unpack.
That's not right, IMHO. In fact, I'd be tempted to call it a bug, except
that AFAIK it's been this way since time immemorial. So, I encourage you
to file a bug report with perlbug which asks why it's not symmetric, and
which includes your patch to make a new, symmetric, 'a' template
character.
Who knows? You might get this fixed after all!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Wed, 4 Jun 1997 14:04:47 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reading Comma delimited, Quoted String records
Message-Id: <f8e4n5.jp9.ln@localhost>
Kevin Smith, ShadeTree Software, Inc. (kevin@shady.com) wrote:
: In article <nj00n5.3ph.ln@localhost> tadmc@flash.net (Tad McClellan) writes:
: >
: >...
: >
: >Perl FAQ, part 4:
: >
: >--------------------------------------------------------------------
: >=head2 How can I split a [character] delimited string except when
: > inside [character]? (Comma-separated files)
: >
: >Take the example case of trying to split a string that is comma-separated
: >into its different fields. (We'll pretend you said comma-separated, not
: >comma-delimited, which is different and almost never what you mean.) You
: >can't use C<split(/,/)> because you shouldn't split if the comma is inside
: >quotes. For example, take a data line like this:
: >
: > SAR001,"","Cimetrix, Inc","Bob Smith","CAM",N,8,1,0,7,"Error, Core Dumped"
: >
: >Due to the restriction of the quotes, this is a fairly complex
: >problem. Thankfully, we have Jeffrey Friedl, author of a highly
: >recommended book on regular expressions, to handle these for us. He
: >suggests (assuming your string is contained in the special variable
: >$_):
: >
: > @new = ();
: > push(@new, $+) while $text =~ m{
: > "([^\"\\]*(?:\\.[^\"\\]*)*)",? # groups the phrase inside the quotes
: > | ([^,]+),?
: > | ,
: > }gx;
: > push(@new, undef) if substr($text,-1,1) eq ',';
: >--------------------------------------------------------------------
: Isn't it assuming the string is in $text?
Yep. It has been fixed in the new version of the Perl FAQ.
Sorry for quoting the old one...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 4 Jun 1997 16:20:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bruno Prior <bruno@prior.ftech.co.uk>
Subject: Re: Segmentation fault from multiple mkdirs in Perl script - Help!
Message-Id: <Pine.GSO.3.96.970604161735.766E-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, Bruno Prior wrote:
> Subject: Segmentation fault from multiple mkdirs in Perl script - Help!
>
> I have written a basic Perl(4) script
If you've found a bug in this ancient version of Perl, that's another good
reason to install 5.004!
> I am running this on a P120, 32 Mb RAM, under Linux 1.3.45.
So the only thing you have left from 1992 is your copy of Perl? :-)
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Wed, 4 Jun 1997 16:27:29 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Dani Macho Ortiz <dani@apb.es>
Subject: Re: tr problems with variables
Message-Id: <Pine.GSO.3.96.970604162119.766F-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, Dani Macho Ortiz wrote:
> tr /$char1/$char2/;
For technical reasons, tr/// needs to be determined at compile time,
instead of at runtime. Because of that, they aren't variable interpolated.
(They are backslash interpolated, so you can write tr/a-\377/x/ .)
One way to do what you want is to use (slower) regular expression
processing. The /o ending tells Perl to compile this just once; read about
that in perlop(1).
s/$char1/$char2/go;
If you want the speed advantage of tr///, or if you might need to change
your characters at runtime, there are other ways to do this, involving
eval. Let me know if you need to try those.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 572
*************************************