[7321] in Perl-Users-Digest
Perl-Users Digest, Issue: 945 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 29 12:32:38 1997
Date: Fri, 29 Aug 97 09:00:29 -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 Fri, 29 Aug 1997 Volume: 8 Number: 945
Today's topics:
Re: 'abandon' hope (was: Re: Need help: how to exit a s <rootbeer@teleport.com>
Re: A Complex Regex Needed <cstetson@vsicom.com>
bug? redirecting standard output for system() (David J. Fiander)
Re: bug? redirecting standard output for system() <seay@absyss.fr>
build problem <taurus@frontiernet.net>
Bus Error in ora_login smeyyappan@pyrasol.com
Re: CGI.pm, go to another script and delaying access ti <rootbeer@teleport.com>
Re: CGI.pm, go to another script and delaying access ti <tom@mitra.phys.uit.no>
Re: CGI.pm, go to another script and delaying access ti <rootbeer@teleport.com>
Re: crypt... does it work with shadow passwd <rootbeer@teleport.com>
Re: crypt... does it work with shadow passwd (Adam Rogoyski)
Re: dbm <rootbeer@teleport.com>
Re: Getting next byte of scalar <tom@mitra.phys.uit.no>
Re: Getting next byte of scalar (Greg Bacon)
Re: Here document with FILEHANDLE ? (Greg Bacon)
Re: Here document with FILEHANDLE ? <rootbeer@teleport.com>
Re: How can I print the size of a file???? (Andrew M. Langmead)
Re: How can I print the size of a file???? <rootbeer@teleport.com>
I have to ASK (COWBYS)
Learning Perl Excercises churley@gte.net
Re: My counter counts, but too munch <tw36027@glaxowellcome.com>
Re: My counter counts, but too munch (Greg Bacon)
Re: My counter counts, but too munch <rootbeer@teleport.com>
Newbievi question <mikeg@slpma8.ed.ray.com>
Re: Newbievi question (M.J.T. Guy)
ODBC not working <Michael_Drons@ins.com>
Re: Out of memory problem <rootbeer@teleport.com>
Re: Password verification with a shadow file ?? <rootbeer@teleport.com>
Re: Pattern Matching (M.J.T. Guy)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Aug 1997 08:21:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "M.J.T. Guy" <mjtg@cus.cam.ac.uk>
Subject: Re: 'abandon' hope (was: Re: Need help: how to exit a sub)
Message-Id: <Pine.GSO.3.96.970829082125.15991N-100000@julie.teleport.com>
On 29 Aug 1997, M.J.T. Guy wrote:
> You'd be in trouble if the "warn" failed ...
That's a tautology! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 97 10:01:05 +0100
From: "Christopher Stetson" <cstetson@vsicom.com>
Subject: Re: A Complex Regex Needed
Message-Id: <B02C4E65-358F9@209.73.1.36>
Doug,
> Why "no splitting"? Has split tormented you in the past and you have
> now black listed it?
No split because I have already written a split version and the code gets
pretty
long. If I can get the regex to do the pattern match in one fell swoop,
it condenses my code by a whole lot.
Basically, I am getting a series of variables for a search on a flatfile
DB. If I can do the search with one expression then it would be easier.
It is mostly an exercise in RE creation and I seem to be pusing the
limit on REs, which is what I wanted to do, but it seems like a fairly
simple idea, that turns out to be hard to implement.
I have tried a bunch of REs and none of them seem to work.
What I need to do is generate an RE based on the fields that return
actual values (if a default value comes through (checked against
@defaultKey) then it is treated like a field with no value). My thinking
was to create a long-ass RE with:
foreach $dbFieldName (@dbFieldNames) {
if ($searchKey = $query-param(-name = "$dbFieldName")) {
if ($searchKey ne $defaultKey{$dbFieldName}) {
$grepTerm .= ("$searchKey" . '.*?\S\t');
}
else {$grepTerm .= '.*?\S\t';}
}
else {$grepTerm .= '.*?\S\t';}
}
with the ".*?\S\t" being the generic search between fields. This generic
search thing is what is stumping me.
Chris
_____________________________//////////////////////////////////////
Christopher Stetson 122 East 42nd Street
Senior Technologist Suite 701
VSI Communications Group New York, NY 10183
cstetson@vsicom.com 212-986-6335
www.vsicom.com 212-328-0721 Fax
An Oblique Strategy "Water" brian eno
------------------------------
Date: 29 Aug 1997 09:45:47 -0400
From: davidf@mks.com (David J. Fiander)
Subject: bug? redirecting standard output for system()
Message-Id: <uiuwpp0fo.fsf@davidf-nt.mks.com>
Now, I know that I can say
system("echo this is a command >output");
for output to be redirected, but I'm curious about STDOUT
redirections and system.
I've tried this:
open(SAVOUT, ">&STDOUT");
open(STDOUT, ">output");
print "perl is redirected\n";
system("echo echo should be redirected");
open(STDOUT, ">&SAVOUT");
close(SAVOUT);
but the string "echo should be redirected is still appearing on
my terminal. This is perl 5.003 on Unix and the MKS port of perl
5.002 to Win/NT. I suspected that closing STDOUT before
reopening it might help (based on my knowlege of C programming),
but it didn't make a difference.
So, is this a bug, or just something that nobody every thought
of?
- David
------------------------------
Date: Fri, 29 Aug 1997 17:30:42 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: bug? redirecting standard output for system()
Message-Id: <3406EB22.312AE743@absyss.fr>
David J. Fiander wrote:
>
> Now, I know that I can say
>
> system("echo this is a command >output");
>
> for output to be redirected, but I'm curious about STDOUT
> redirections and system.
>
> I've tried this:
[snip]
> but the string "echo should be redirected is still appearing on
> my terminal. This is perl 5.003 on Unix and the MKS port of perl
> 5.002 to Win/NT. I suspected that closing STDOUT before
> reopening it might help (based on my knowlege of C programming),
> but it didn't make a difference.
>
> So, is this a bug, or just something that nobody every thought
> of?
>
> - David
I'd guess that it was a bug with 5.003 or you left something out when
you posted (and that something was the problem). I tried it and all my
output ended up in the file "output". As you can see, I just took your
code and added some error checking in case that was the problem. Didn't
seem to be. FWIW I'm running 5.004 level 0 and I get the same results
on linux 2.0.18 and Solaris 2.5.
#!/usr/local/bin/perl -w
use strict;
open(SAVOUT, ">&STDOUT") || die "one: $!\n";
open(STDOUT, ">output") || die "two: $!\n";
print "perl is redirected\n";
system("echo echo should be redirected");
open(STDOUT, ">&SAVOUT") || die "three: $!\n";
close(SAVOUT);
- doug
------------------------------
Date: Fri, 29 Aug 1997 10:26:20 -0400
From: "Anthony R. Whyte" <taurus@frontiernet.net>
Subject: build problem
Message-Id: <5u6l44$1amq$1@node17.cwnet.frontiernet.net>
Trying to build the latest stuff on my linux/slackware system but keep
dying around use of -ldl. There is a libdl.so.1.7.14* in my /lib
directory.
Thanks
DIES HERE WHEN I RUN MAKE:
=========================
rm -f libperl.a
ar rcu libperl.a perl.o gv.o toke.o perly.o op.o regcomp.o dump.o
util.o mg.o hv.o av.o run.o pp_hot.o sv.o pp.o scope.o pp_ctl.o pp_sys.o
doop.o doio.o regexec.o taint.o deb.o universal.o globals.o perlio.o
cc -L/usr/local/lib -o miniperl miniperlmain.o libperl.a -lgdbm -ldb
-ldl -lm -lc
/usr/i486-linux/bin/ld: cannot open -ldl: No such file or directory
OUTPUT OF MYCONFIG:
===================
Summary of my perl5 (5.0 patchlevel 4 subversion 3) configuration:
Platform:
osname=linux, osvers=2.0.0, archname=i486-linux
uname='linux darkstar 2.0.0 #1 mon jun 10 21:11:56 cdt 1996 i486 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=2.7.2
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=4, usemymalloc=n, randbits=31
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /shlib /lib /usr/lib
------------------------------
Date: Fri, 29 Aug 1997 10:41:50 -0600
From: smeyyappan@pyrasol.com
Subject: Bus Error in ora_login
Message-Id: <872868937.31420@dejanews.com>
Hi,
I successfully made oraperl v2.4 (Perl 4.036 and Oracle 7.3.2).
But when I tried to do Make test, ora_login returns bus error.
Can you tell me what's wrong?
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 29 Aug 1997 07:29:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: CGI.pm, go to another script and delaying access times...
Message-Id: <Pine.GSO.3.96.970829072532.15991G-100000@julie.teleport.com>
On 28 Aug 1997, Tom Grydeland wrote:
> Tom Phoenix <rootbeer@teleport.com> writes:
>
> > > Is there a code or module can I use to put a delay in my script? Like a
> > > chat script I have, I need to have it so it only allows an indivildual
> > > to hit update or chat, etc. once every 10 seconds or so.
>
> > Keep a list (in a file) of every person who has triggered the script in
> > the past ten seconds, and their "next time" (which is when they are
> > allowed to trigger the script next). [rest snipped]
>
> What's wrong with sleep()? Try perldoc -f sleep.
Since CGI scripts may be called several times per second, it's better to
make them run quickly rather than letting them stay around on the server.
And if your script sleeps for too long, that encourages tyros to trigger
your script again and again, causing even more server load. :-P In fact,
I think this was the exact problem which the poster is referring to.
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 16:35:28 +0200
From: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: CGI.pm, go to another script and delaying access times...
Message-Id: <nqog1rtvyz3.fsf@mitra.phys.uit.no>
Tom Phoenix <rootbeer@teleport.com> writes:
> Since CGI scripts may be called several times per second, it's better to
> make them run quickly rather than letting them stay around on the server.
> And if your script sleeps for too long, that encourages tyros to trigger
> your script again and again, causing even more server load. :-P In fact,
> I think this was the exact problem which the poster is referring to.
Well, I'm sure you're right. He asked for a *delay*, though...
> Tom Phoenix http://www.teleport.com/~rootbeer/
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Fri, 29 Aug 1997 08:52:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: CGI.pm, go to another script and delaying access times...
Message-Id: <Pine.GSO.3.96.970829084739.15991T-100000@julie.teleport.com>
On 29 Aug 1997, Tom Grydeland wrote:
> Tom Phoenix <rootbeer@teleport.com> writes:
>
> > Since CGI scripts may be called several times per second, it's better to
> > make them run quickly rather than letting them stay around on the server.
> > And if your script sleeps for too long, that encourages tyros to trigger
> > your script again and again, causing even more server load. :-P In fact,
> > I think this was the exact problem which the poster is referring to.
>
> Well, I'm sure you're right. He asked for a *delay*, though...
And my suggestion implements a delay - and very efficiently, since it's on
the client's side of the transaction. :-)
More importantly, my method lets you educate the users of the script as to
why they shouldn't pound on the 'submit' button. Using sleep will just
cause them to complain that your chatting script is too slow! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 07:14:32 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Andrew Kerr <kerr@cs.uregina.ca>
Subject: Re: crypt... does it work with shadow passwd
Message-Id: <Pine.GSO.3.96.970829071140.15991E-100000@julie.teleport.com>
On 28 Aug 1997, Andrew Kerr wrote:
> Subject: crypt... does it work with shadow passwd
> Well, the title says most of it... using Perl 5 on Irix 5.3
> with shadow passwording on. Will the crypt function work???
The crypt function doesn't (usually) know or care whether you use shadow
passwords. If you give it the right data, it will give you the right
results. Of course, if you're using shadow passwords, you may not have
the right data to give it, but that's hardly something you can blame on
the crypt function! :-)
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 13:58:02 GMT
From: ifqa242@spice.cc.utexas.edu (Adam Rogoyski)
Subject: Re: crypt... does it work with shadow passwd
Message-Id: <5u6kha$p1f$1@geraldo.cc.utexas.edu>
Andrew Kerr (kerr@cs.uregina.ca) wrote:
: : > > Well, the title says most of it... using Perl 5 on Irix 5.3
: : > > with shadow passwording on. Will the crypt function work???
: : > > So far it isn't for me, but it could be my code at this point :)
: : >
: : > Sure it'll work. You just have to read use /etc/shadow instead of
: : > /etc/passwd as the location of the crypt()ed string. Which means you
: : > have to be root.
: : >
: : > -Doug
: : Better if you use getpwnam and friends. You'll get the password if
: : you've got the priveleges and your code will be more portable!
: Well, two problems... 1. This is meant to be used via a webpage, so no
: root, cause I'm not letting perl run as root.
: 2. What is friends??? I know getpwnam and am using it, but haven't seen
: or read anything on friends.
I think what he was refering to was using getpwnam and similiar functions, not actually a function
called friends, such as other functions like getpwuid
--
__/\__. [-Temperance-] .__)\__
! \ oO / . :[Adam Rogoyski]: . \ oO / !
. /_\/_\ . :[ apoc@laker.net ]: . /_\/_\ .
\/ . :[ http://www.laker.net/apoc ]: . \/
------------------------------
Date: Fri, 29 Aug 1997 08:24:02 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: May Huang <may@livingston.com>
Subject: Re: dbm
Message-Id: <Pine.GSO.3.96.970829082239.15991O-100000@julie.teleport.com>
On Thu, 28 Aug 1997, May Huang wrote:
> I have encountered a problem when saving large chunk of data into
> dbm files. dbm has a size limitation of 1k per entry, is there any way
> to get around this?
The way is to use a different file format (and the corresponding different
DBM module) which doesn't suffer from that limitation. There are many
useful modules on CPAN. Hope this helps!
http://www.perl.com/CPAN/
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 16:34:15 +0200
From: Tom Grydeland <tom@mitra.phys.uit.no>
Subject: Re: Getting next byte of scalar
Message-Id: <nqohgc9vz14.fsf@mitra.phys.uit.no>
> In article <nqopvqyvwnj.fsf@mitra.phys.uit.no>,
> I stupidly wrote:
> : split "C*", $buf;
gbacon@adtran.com (Greg Bacon) writes:
> Huh? Do you mean
>
> map { ord } split //, $buf
>
> or perhaps
>
> unpack "C*", $buf
*embarrassed* Yes, I ment unpack. Terribly sorry. Won't happen
again.
I *did* test my solution before posting it, but I must have been
comatose before typing it in again.
> Greg
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: 29 Aug 1997 15:48:11 GMT
From: gbacon@adtran.com (Greg Bacon)
Subject: Re: Getting next byte of scalar
Message-Id: <5u6qvr$4c7$6@info.uah.edu>
In article <nqohgc9vz14.fsf@mitra.phys.uit.no>,
Tom Grydeland <tom@mitra.phys.uit.no> writes:
: I *did* test my solution before posting it, but I must have been
: comatose before typing it in again.
I've found that cut-and-paste is much more reliable. :-)
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 29 Aug 1997 14:39:24 GMT
From: gbacon@adtran.com (Greg Bacon)
To: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Here document with FILEHANDLE ?
Message-Id: <5u6mus$4c7$5@info.uah.edu>
[Posted and mailed]
In article <340acaf7.2339914@news.tornado.be>,
bart.mediamind@tornado.be (Bart Lateur) writes:
: "Jerry Xia" <jxia@worldnet.att.net> wrote:
:
: >Is there any way that I can open a file with using here document? What I am
: >trying to do is something like:
:
: Make that
:
: open (FTP, "ftp -n $hostname ".<<EOF . "|");
[snip]
: BTW I can't check if this will actually work, but the syntax will do
: what you expect.
Huh? It seems to me that he would expect it to work, else he wouldn't
be using it! :-)
For the record, the above solution certainly *won't* work. Your best
bet would be to use Graham Barr's Net::FTP module like:
use Net::FTP;
my $ftp = Net::FTP->new($hostname);
$ftp->login("xxx","password");
## get some info
$dirsref = $ftp->ls;
...;
$ftp->quit;
Net::FTP is available as part of the libnet distribution on the CPAN.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Fri, 29 Aug 1997 07:49:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jerry Xia <jxia@worldnet.att.net>
Subject: Re: Here document with FILEHANDLE ?
Message-Id: <Pine.GSO.3.96.970829074838.15991I-100000@julie.teleport.com>
On 29 Aug 1997, Jerry Xia wrote:
> Is there any way that I can open a file with using here document? What I am
> trying to do is something like:
>
> open (FTP, "ftp -n $hostname <<EOF
> user xxx
> ls -l
> ...
> bye
> EOF
> |") ;
It looks as if you're trying to run an FTP session from Perl. Don't you
want to use a module? It's more efficient, faster, cooler, more likely to
work... :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 14:15:44 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: How can I print the size of a file????
Message-Id: <EFoIA8.5BK@world.std.com>
"David J. Thomas" <thomasdj@wam.umd.edu> writes:
> $modTime = (stat($fullFilename))[9];
>This returns the last modified date and time of the file.
>I also want to return the size of this file to a variable as well.
Just access the other elements of the stat list as well.
($modTime, $fileSize) = (stat $fullFilename)[9,7];
>One more thing... I'd like to be able to print the total disk space and
>the amount that is used under my quota.
There is a Quota module that is available on CPAN sites, but you might
be able to get all of the info that you need by just running the
"quota" command from perl using system('quota -v') or `quota -v`.
--
Andrew Langmead
------------------------------
Date: Fri, 29 Aug 1997 07:59:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gary Colman <SPAMFREEcolmang@ms.com>
Subject: Re: How can I print the size of a file????
Message-Id: <Pine.GSO.3.96.970829075242.15991J-100000@julie.teleport.com>
On Fri, 29 Aug 1997, Gary Colman wrote:
> > I have the following line of code in a cgi-script:
> > $modTime = (stat($fullFilename))[9];
> > This returns the last modified date and time of the file.
> This is equivalent to:
> time() - (-M $fullFilename) * 86400
No, it's not. (And if that worked, in what way would it be better than
what was posted? It's neither more efficient nor easier to understand.)
> > I also want to return the size of this file to a variable as well.
> -S $Fullfilename
No, that's not right either. You've miscapitalized three letters in that
expression, and all of them count.
I'm not trying to be mean here; we all make mistakes. But I don't like to
see misinformation being distributed. Thanks!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 15:45:21 GMT
From: cowbys@aol.com (COWBYS)
Subject: I have to ASK
Message-Id: <19970829154501.LAA29882@ladder01.news.aol.com>
Humor Me if you would please:
I am looking for the FTP.pm module, I know what CPAN is and Ive been there,
my understanding was that i could go there and download modules, Ive gone
into "modules", "by module" and I dont see any ".pm" files, Isnt there an
easier way of
obtaining a particular ".pm" file from somewhere.
i mean, all I want to do is use ftp from within a perl script, and I know
I need FTP.pm or NET::FTP, for the record, I am running Perl for Win32
5.003, With IIS 3.0 on NT 4.0, I have no means of or experience with
compiling CPAN is great, but I thought it would be easier to find a module
and download it than I have found it to be. Hell, If somebody has
NET::FTP, or FTP.pm, email it to:
dave_fortenberry@attcapital.com
any help appreciated
------------------------------
Date: 29 Aug 1997 15:38:20 GMT
From: churley@gte.net
Subject: Learning Perl Excercises
Message-Id: <5u6qdc$d6c$1@gte2.gte.net>
I am using Perl for Win32 and am trying to do the excersises in
Chapter 1. My problem is on the Hello script, when you have to access
the wordlist file, I cannot get my program to open the file with the
paswords in it. The program will run and if I type my name it will
give the correct response however any other name typed in, I have to
use the default password. The names and passwords stored in the
wordslist file are not being accessed. Can anyone help me with this?
Please e-mail:
churley@gte.net
I appreciate any help,
Chris Hurley
------------------------------
Date: Fri, 29 Aug 1997 09:52:34 -0400
From: Thad Welch <tw36027@glaxowellcome.com>
To: "Lozano Mosterin, Jesus" <lozano@opalo.etsiig.uniovi.es>
Subject: Re: My counter counts, but too munch
Message-Id: <3406D422.58362FD7@glaxowellcome.com>
I think you're mis-using the index fuction. The index function will
return
the position of the found character starting at an index until the end
of the string.
For example:
index( "12220", "0", 1 ) will return 4.
A substr is want you want.
for ($j=0;$j<7;$j++) { $stat[$j]++ if (substr($temp,$j,1) eq "0") }
Lozano Mosterin, Jesus wrote:
> Hello
>
> I want to count the "0" chars in various strings of lengh 7,
> related to string position. I'm using this and sometimes works
> as expected, others don't, counting one ocurrence more in the
> seventh position
>
> for ($j=0;$j<7;$j++) { $stat[$j]++ if ($j == index($temp,"0",$j)); }
>
> Thanks for your help
>
> ---
> Please, answer by e-mail
------------------------------
Date: 29 Aug 1997 14:28:50 GMT
From: gbacon@adtran.com (Greg Bacon)
To: lozano@opalo.etsiig.uniovi.es (Lozano Mosterin, Jesus)
Subject: Re: My counter counts, but too munch
Message-Id: <5u6mb2$4c7$4@info.uah.edu>
[Posted and mailed]
In article <1997Aug29.053146.14333@opalo.etsiig.uniovi.es>,
lozano@opalo.etsiig.uniovi.es (Lozano Mosterin, Jesus) writes:
: I want to count the "0" chars in various strings of lengh 7,
: related to string position. I'm using this and sometimes works
: as expected, others don't, counting one ocurrence more in the
: seventh position
Have a look at perlfaq4, paying careful attention to the section
labeled
How can I count the number of occurrences of a substring
within a string?
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Fri, 29 Aug 1997 07:47:22 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Lozano Mosterin, Jesus" <lozano@opalo.etsiig.uniovi.es>
Subject: Re: My counter counts, but too munch
Message-Id: <Pine.GSO.3.96.970829073047.15991H-100000@julie.teleport.com>
On 29 Aug 1997, Lozano Mosterin, Jesus wrote:
> I want to count the "0" chars in various strings of lengh 7,
> related to string position. I'm using this and sometimes works
> as expected, others don't, counting one ocurrence more in the
> seventh position
>
>
> for ($j=0;$j<7;$j++) { $stat[$j]++ if ($j == index($temp,"0",$j)); }
(I don't see why that shouldn't do what it says, which may not be what you
meant. :-) That's not counting the "0" characters; it's incrementing
$stat[$j] if it's finding a "0" at position $j in the string. I'm not sure
what you really want. Can you give some examples of data, and what you
want in @stat afterwards? But here are some things which might be what you
want.
$number_of_zeroes = ($temp =~ tr/0//);
@stat = map { $_ ? 0 : 1 } split //, $temp;
for (0..6) { $stat[$j]++ if substr($temp, $_, 1) eq "0" }
for ( $j=index($temp,"0"); $j>=0; $j=index($temp,"0",$j) ) {
$stat[$j]++
}
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 09:33:36 -0400
From: Michael Genovese <mikeg@slpma8.ed.ray.com>
Subject: Newbievi question
Message-Id: <3406CFB0.5239@slpma8.ed.ray.com>
Hello:
I'm a newbie on PERL programming.
I recently tried to write a small PERL script to manipulate the PATH
environment variable. All did NOT work as expected; I managed to
isolate the code that isn't doing what I expect below.
Following the code fragment is a sample output.
Here are my questions :
(1) why is only the FIRST element of the array changed ?
(2) why does a for-loop and a foreach loop give me slightly
different outputs ? Admittedly, this is only for the first
element, but why ?
(3) The problem does NOT seem to happen (and the entire array IS
changed) IF I use a foreach loop BOTH times. Why ?
------------------------------------------------------------
#!/usr/local/bin/perl
#
# Simple script to "clean up" the PATH environment variable!
#
{
$x = $ENV{PATH}; # Copy the PATH environment variable for
processing!
@y = split /:/ , $x; # Split the path into separate directories!
$y = @y; # Get Number of elments!
for ($i=0; $i<$y; ++$i) {
# Add in blanks to make later processing easier!
@y[i] = " " . @y[$i] . " " ;
printf("OK [ %3d ] = *%s*\n", $i, @y[$i]);
}
$i = 0;
for $z (@y) {
printf("BAD [ %3d ] = *%s*\n", $i, $z);
++$i;
}
}
------------------------------------------------------------
OK [ 0 ] = * /bin *
OK [ 1 ] = */home/rdapp2u2/mikeg/bin*
OK [ 2 ] = */home/rdapp2u2/stubbe/bin*
OK [ 3 ] = */usr/bin*
OK [ 4 ] = */usr/sbin*
OK [ 5 ] = */usr/ccs/bin*
OK [ 6 ] = */usr/openwin/bin*
OK [ 7 ] = */opt/SUNWspro/bin*
OK [ 8 ] = */usr/bin/X11*
OK [ 9 ] = */usr/ucb*
OK [ 10 ] = */usr/local/bin*
OK [ 11 ] = */opt/SUNWspro/man*
OK [ 12 ] = */usr/share/man*
OK [ 13 ] = */usr/openwin/man*
OK [ 14 ] = */usr/local/man*
OK [ 15 ] = */usr/lib/lp/postscript*
OK [ 16 ] = */email*
OK [ 17 ] = */usr/sbin*
OK [ 18 ] = */usr/local/bin*
OK [ 19 ] = */interleaf/ileaf5/bin*
OK [ 20 ] = */opt/NeWSprint/bin*
OK [ 21 ] = */usr/local/prt/usertools/bin*
OK [ 22 ] = *.*
BAD [ 0 ] = * . *
BAD [ 1 ] = */home/rdapp2u2/mikeg/bin*
BAD [ 2 ] = */home/rdapp2u2/stubbe/bin*
BAD [ 3 ] = */usr/bin*
BAD [ 4 ] = */usr/sbin*
BAD [ 5 ] = */usr/ccs/bin*
BAD [ 6 ] = */usr/openwin/bin*
BAD [ 7 ] = */opt/SUNWspro/bin*
BAD [ 8 ] = */usr/bin/X11*
BAD [ 9 ] = */usr/ucb*
BAD [ 10 ] = */usr/local/bin*
BAD [ 11 ] = */opt/SUNWspro/man*
BAD [ 12 ] = */usr/share/man*
BAD [ 13 ] = */usr/openwin/man*
BAD [ 14 ] = */usr/local/man*
BAD [ 15 ] = */usr/lib/lp/postscript*
BAD [ 16 ] = */email*
BAD [ 17 ] = */usr/sbin*
BAD [ 18 ] = */usr/local/bin*
BAD [ 19 ] = */interleaf/ileaf5/bin*
BAD [ 20 ] = */opt/NeWSprint/bin*
BAD [ 21 ] = */usr/local/prt/usertools/bin*
BAD [ 22 ] = *.*
Can anyone help ?
Yours,
Mike G.
------------------------------
Date: 29 Aug 1997 15:53:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Newbievi question
Message-Id: <5u6rag$o7c$1@lyra.csx.cam.ac.uk>
Michael Genovese <mikeg@slpma8.ed.ray.com> wrote:
>Here are my questions :
> (1) why is only the FIRST element of the array changed ?
> (2) why does a for-loop and a foreach loop give me slightly
> different outputs ? Admittedly, this is only for the first
> element, but why ?
> (3) The problem does NOT seem to happen (and the entire array IS
> changed) IF I use a foreach loop BOTH times. Why ?
>
>Can anyone help ?
Yes - you can help yourself by running that script as
perl -w -Mdiagnostics myscript
and it would have said
Scalar value @y[i] better written as $y[i] at - line 9 (#1)
(W) You've used an array slice (indicated by @) to select a single element of
an array. Generally it's better to ask for a scalar value (indicated by $).
The difference is that $foo[&bar] always behaves like a scalar, both when
assigning to it and when evaluating its argument, while @foo[&bar] behaves
like a list when you assign to it, and provides a list context to its
subscript, which can do weird things if you're expecting only one subscript.
On the other hand, if you were actually hoping to treat the array
element as a list, you need to look into how references work, because
Perl will not magically convert between scalars and lists for you. See
perlref.
Unquoted string "i" may clash with future reserved word at - line 9 (#2)
(W) You used a bareword that might someday be claimed as a reserved word.
It's best to put such a word in quotes, or capitalize it somehow, or insert
an underbar into it. You might also declare it as a subroutine.
Scalar value @y[$i] better written as $y[$i] at - line 9 (#1)
Scalar value @y[$i] better written as $y[$i] at - line 10 (#1)
Mike Guy
------------------------------
Date: Fri, 29 Aug 1997 10:54:01 -0400
From: Mike Drons <Michael_Drons@ins.com>
Subject: ODBC not working
Message-Id: <3406E289.49EF@ins.com>
I have perl for win32 build 307 with the ODBC.pm module. My perl script
works fine if I run it from the command line. It does not work when IIS
version 3.0 runs it. It dies when it creates the new ODBC object. I
think it is a permission problem but don't know where to look. Any
suggestions?
Mike Drons
Michael_Drons@ins.com
------------------------------
Date: Fri, 29 Aug 1997 08:17:36 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Daniel Mills <dmills@riag.com>
Subject: Re: Out of memory problem
Message-Id: <Pine.GSO.3.96.970829081347.15991L-100000@julie.teleport.com>
On Fri, 29 Aug 1997, Daniel Mills wrote:
> I running the following simple script on on a VMS machine and get
> an "Out of Memory" error whenever the input file is very large (> 10M).
What version of Perl are you running? Many memory leaks from previous
versions have been plugged in 5.004_03.
> open(TXT,"cbgnl\$dump:dot.sgm");
It doesn't waste any memory to check the return value from open. :-)
> undef $/;
> while(<TXT>){
Are you really needing to read the entire file into memory at once? If
your application can do so, it's more polite to process it line-by-line.
> while(/\d+\s/gs){
I don't think that the /s option adds anything there.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 08:12:00 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: mgrabenstein@isinet.com
Subject: Re: Password verification with a shadow file ??
Message-Id: <Pine.GSO.3.96.970829075952.15991K-100000@julie.teleport.com>
On Fri, 29 Aug 1997 mgrabenstein@isinet.com wrote:
> I need to validate a user's password entered from a Web form.
Oh, I hate to see passwords being thrown around on the web. But I suppose
you must.
> Problem is the system has a shadow password file and I do _not_ want the
> CGI to have, or call a program with special privledges (ie. root).
Why not? Here's one idea: Set up a root-privileged script (or daemon)
which, when given a username and a password attempt, reports whether or
not the attempt works. It wouldn't be too hard to make it secure, and it
could be used by many programs at once, whether they're written in Perl or
not. (SunOS does something like this, internally, via the crypt(3)
function. I wish more vendors offered that.)
> I have a work around, but don't like it. :-) I used the:
> use Net::FTP;
> module and open a FTP session and logon as that user.
Ingenious! But I can see why you wouldn't like it. (And be careful that
user 'anonymous' doesn't try to get away with anything! :-) Of course,
you _are_ doing what you said you don't want to do: You're calling a
program (that is, ftpd) with root privileges. Does that make my suggestion
sound any better?
If you decide to make such a script or daemon, I'll be glad to work with
you to make sure it's secure and to turn it into a Perl module for CPAN.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 14:42:00 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Pattern Matching
Message-Id: <5u6n3o$lnr$1@lyra.csx.cam.ac.uk>
Tom Grydeland <tom@mitra.phys.uit.no> wrote:
>Joseph Essas <joseph@tcs9000.com> writes:
>
>> $string="abcdeabce";
>
>> I need to find the first place where there is: a..something that not
>> 'bcd'..e
>
>/a(?!bcd).*e/ *might* be what you want. Your question is too unclear.
I would have guessed Joseph wanted
/a(?!bcde).*?e/
But it should be instructive to study perlre to find out what these two
suggestions do, how they differ, and whether either of them is what you
want.
Mike Guy
------------------------------
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 945
*************************************