[13575] in Perl-Users-Digest
Perl-Users Digest, Issue: 985 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 4 22:05:43 1999
Date: Mon, 4 Oct 1999 19:05:15 -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: <939089115-v9-i985@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 4 Oct 1999 Volume: 9 Number: 985
Today's topics:
Re: adding (summing) elements of an array (or hash) <rick.delaney@home.com>
Re: Bug with localtime() in Perl 5.004 and 5.005 (Ilya Zakharevich)
Re: Building perl from source <cassell@mail.cor.epa.gov>
Re: Email Attachments (David Efflandt)
Re: fork and segmentation fault (Charles DeRykus)
Re: Hashes w/multiple values per key (Perl Cookbook) <cassell@mail.cor.epa.gov>
Re: Help! I'm having big trouble searching my database sleepernyc@my-deja.com
Re: Help: Permission Denied when trying to create a fi (David Efflandt)
Re: How to start up Netscape or Internet Explorer from <cassell@mail.cor.epa.gov>
Re: How to start up Netscape or Internet Explorer from (Nim Chu)
Knowing sizeof (int) inside a Perl program <makkulka@cisco.com>
Re: Knowing sizeof (int) inside a Perl program <cassell@mail.cor.epa.gov>
Re: Newbie: Chomp and Case Conversion on Input <cassell@mail.cor.epa.gov>
Re: Newbie: Combining split and shift on One Statement <dove@synopsys.com>
Re: NewsClipper Script <cassell@mail.cor.epa.gov>
Re: pattern match. & ? operator <cassell@mail.cor.epa.gov>
Re: pattern match. & ? operator <rick.delaney@home.com>
pattern matching question <nessenj@jimsoffice.org>
Re: pattern matching question (David Efflandt)
Pulling positional data from a string <ultrak@my-deja.com>
regexp question - last occurrence of an expression befo (Gerry JJ Dyn-O-Myte Walker)
Re: Schnelle Bearbeitung von HTML-Seiten <cassell@mail.cor.epa.gov>
Re: setpwent (Martien Verbruggen)
try to test perl off-line <aryes2@email.msn.com>
Re: try to test perl off-line (Bill Moseley)
Re: try to test perl off-line <cassell@mail.cor.epa.gov>
using alarm for timeouts <freek@coolmail.net>
Re: Using SS Numbers as DBM Index: Best Way to Encrypt <george.kuetemeyer@mail.tju.edu>
XS and file handles <crdevilb@mtu.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 04 Oct 1999 23:48:22 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: adding (summing) elements of an array (or hash)
Message-Id: <37F93CC7.F1A8A992@home.com>
[posted & mailed]
Craig Berry wrote:
>
> Anybody else have an idea on how to beat 'foreach'?
use Benchmark;
use List::Util;
my @values = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
my $sum;
timethese(100000, {
'foreach' => sub { $sum = 0; foreach (@values) { $sum += $_; } },
'eval' => sub { $sum = eval join ' + ', @values; },
'sum' => sub { $sum = List::Util::sum @values; },
'formula' => sub { $sum = @values * (@values + 1) / 2; },
'const' => sub { $sum = 55; },
});
__END__
Benchmark: timing 100000 iterations of const, eval, foreach, formula,
sum...
const: 1 wallclock secs ( 0.49 usr + 0.00 sys = 0.49 CPU)
eval: 83 wallclock secs (67.43 usr + 0.07 sys = 67.50 CPU)
foreach: 5 wallclock secs ( 4.54 usr + 0.00 sys = 4.54 CPU)
formula: 1 wallclock secs ( 1.68 usr + 0.00 sys = 1.68 CPU)
sum: 2 wallclock secs ( 1.25 usr + 0.00 sys = 1.25 CPU)
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 4 Oct 1999 22:15:31 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Bug with localtime() in Perl 5.004 and 5.005
Message-Id: <7tb8u3$2en$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Alan Curry
<pacman@defiant.cqc.com>],
who wrote in article <_h7K3.14074$t%3.1085991@typ11.nn.bcandid.com>:
> >$seconds_per_day = 86400;
>
> Are you sure about that? What about DST and leap seconds?
The last part is a common misconception. There are no leap seconds in
time(). time() is 86400 * $d + $s. $d is the number of whole days
after the epoch, and $s is number of seconds during the last day.
A patch to perlfunc is welcome.
Ilya
------------------------------
Date: Mon, 04 Oct 1999 15:59:19 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Building perl from source
Message-Id: <37F93147.D65F88D4@mail.cor.epa.gov>
Bill Moseley wrote:
>
> I've got these installed on a Win 98 machine.
>
> MSVC++ 4.0
> Mingw32 w/ gcc 2.95
> Cygwin w/ gcc 2.95
>
> What's the best to build perl with? Or should I upgrade to MSVC++ 5
> first and use that?
I suggest that you get a copy of The Perl Journal #13
[spring 1999]. Nate Patwardhan has an entire article on
building your own win32 Perl. Among other things, he
doesn't use MSVC++ at all, and he prefers Cygwin32's egcs
over its gcc. He builds on NT, rather than win98, and he
points out one or two diffs. Like NT implements a POSIX
subsystem while 98 doesn't so you may not be able to get
your Perl to pass all the tests. He says:
"In my opinion, there's so much missing in Windows 95/98
that you should spend the $200 on Windows NT Workstation
so that your software will build correctly."
> I've heard that programs build with Cygwin libraries are slow. Anyone
> confirm that?
That's right. Use your machine with the best CPU and the
most RAM.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 5 Oct 1999 01:06:42 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Email Attachments
Message-Id: <slrn7vijpl.a5.efflandt@efflandt.xnet.com>
On Mon, 4 Oct 1999 13:13:37 +0100, Ian Bertie <ian@a38.com> wrote:
>
>I am trying to attach a file to a html form, but when I submit the form all
>that gets sent is the path to the file, and not the file itself. I cannot
>seem to get my email perl program to attach the file. Can anyone help.
>
>Thanks Ian.
The CGI and MIME::Lite modules work well together even for binary
attachments. However, you may need to install MIME::Lite yourself.
--
David Efflandt efflandt@xnet.com http://www.xnet.com/~efflandt/
http://www.de-srv.com http://cgi-help.virutalave.net/
http://thunder.prohosting.com/~cv-elgin/
------------------------------
Date: Tue, 5 Oct 1999 01:05:45 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: fork and segmentation fault
Message-Id: <FJ3v1L.EGz@news.boeing.com>
In article <Pine.GSO.4.10.9910021131300.19155-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
>On Fri, 1 Oct 1999 frodefi@my-deja.com wrote:
> ...
>
>> $SIG{CHLD} = sub { wait };
>
>This may be the problem. Signal handlers written in Perl are unsafe at
>this time, since the signal may happen when it's not safe to call a
>subroutine (for example, while allocating memory or rebuilding an internal
>data structure). Usually there's no problem, but you never know when
>you'll crash. (Still, these tend to be difficult to repeat. And your
>program is reliably crashing [to use an oxymoron] isn't it?)
>
Here's some more signal dementia - often a problem
with mass forking. From the Perl Cookbook:
"Because the kernel keeps track of undelivered signals using
a bit vector one bit per signal, if two children die before
your process is scheduled, you will get only a single SIGCHLD.
You must always loop when you reap in a SIGCHLD handler,
and so you can't use wait"."
Backticks, open, and system present potential traps too.
This may actually be relevant since there were backticks in
in the original post. The Cookbook has good explanations
here too.
--
Charles DeRykus
------------------------------
Date: Mon, 04 Oct 1999 16:03:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Hashes w/multiple values per key (Perl Cookbook)
Message-Id: <37F93245.218296F3@mail.cor.epa.gov>
kandeb@my-deja.com wrote:
>
> > Have you considered using a zero-width assertion as your pattern
> > here? Instead of using /^-*C/ you could use something like /^(?=-*C)/
> > so it wouldn't gobble up the first part of your line.
>
> For some reason, this isn't working at all for me. I get "0 chunks
> found." which indicates no match. It is syntactically okay (no
> complaints from -w), therefore the regexpr must not be quite right.
> First, here's a simple representation of the logfile being parsed:
>
> ------------------ Configuration: A -----------------
^ <------
Okay, there it is. You need a space in your regex. Try
using /^(?=-+ Config)/ .
Actually, if you know that your lines will always be like
this, you could try /^(?=-{18} Config)/
[That's start of the line, 18 dashes, a space, and the first
six letters of the word - you don't need to match the whole
line, just enough of the front of the line to disambiguate.]
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 22:20:32 GMT
From: sleepernyc@my-deja.com
Subject: Re: Help! I'm having big trouble searching my database
Message-Id: <7tb973$o50$1@nnrp1.deja.com>
Uh, right. Oversight.
http://www.tasteofbrooklyn.com/tob/cgi-bin/dbman/html.pl
Snore.
In article <37fe0279.195942069@news.ford.com>,
cpierce1@ford.com (Clinton Pierce) wrote:
> [poster cc'd in e-mail]
>
> On Mon, 04 Oct 1999 19:06:53 GMT, sleepernyc@my-deja.com wrote:
> >Might anyone be willing to look at this code and offer suggestions?
> >check out www.tasteofbrooklyn.com/tob/cgi-bin/dbman/main3.html
>
> There is no code here, only a stupid web page. You want is to look at
> your HTML or something?
>
> Begone! Next time show us some Perl we can look at.
>
> --
> Clinton A. Pierce "If you rush a Miracle Man, you get rotten
> clintp@geeksalad.org Miracles." -- Miracle Max, The Princess
Bride
> http://www.geeksalad.org
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 5 Oct 1999 01:13:57 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help: Permission Denied when trying to create a file for output
Message-Id: <slrn7vik79.a5.efflandt@efflandt.xnet.com>
On Mon, 4 Oct 1999 14:18:49 +0100, Anonymous <nobody@newsfeeds.com> wrote:
>Could someone tell me how to write data to a text file that is not in my
>cgi-bin directory?
>
>The "settings" dir has the permissions set to 766. What else do I need to
>do?
You need execute dir permission to create a file. Since you are 'nobody'
try 747. Of course then any other CGI on your system can write to your
files if they are also 'nobody'.
--
David Efflandt efflandt@xnet.com http://www.xnet.com/~efflandt/
http://www.de-srv.com http://cgi-help.virutalave.net/
http://thunder.prohosting.com/~cv-elgin/
------------------------------
Date: Mon, 04 Oct 1999 15:43:20 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to start up Netscape or Internet Explorer from a Perl script
Message-Id: <37F92D88.4E187C85@mail.cor.epa.gov>
Nim Chu wrote:
[snip]
> Thanks for the reply. I want to have more control over the browser
> session (by the way, I want to do this in Windows 95 or 98), e.g.
> (1) Close out the browser session,
> (2) Repeat send another URL over to the same browser window,
> but `netscape $url` will not return control back the perl until
> the user closes the session,
> (3) Detect if the user click on the "window close" button
> (4) If the user opened several browser sessions before, my perl script
> know which session it actually opened in the beginning to avoid
> mistakely sending the URL to a wrong session
It sounds like you want far more than can be guaranteed by
spawning off an instance of your browser. Perhaps you need
to step back and re-assess the underlying requirements of
your system. Insisting on a 'browser' session and all your
other requirements sounds like you have half a solution and
are trying to bulldoze your way to a whole answer.
Perl has a variety of modules like LWP::Simple and
LWP::UserAgent which can grab a webpage for you. Perhaps
that is what you really need.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 05 Oct 1999 03:47:13 GMT
From: nimchu@hal-pc.org (Nim Chu)
Subject: Re: How to start up Netscape or Internet Explorer from a Perl script
Message-Id: <7tbhqg$25na$1@news.hal-pc.org>
David Cassell <cassell@mail.cor.epa.gov> wrote:
>It sounds like you want far more than can be guaranteed by
>spawning off an instance of your browser. Perhaps you need
>to step back and re-assess the underlying requirements of
>your system. Insisting on a 'browser' session and all your
>other requirements sounds like you have half a solution and
>are trying to bulldoze your way to a whole answer.
>Perl has a variety of modules like LWP::Simple and
>LWP::UserAgent which can grab a webpage for you. Perhaps
>that is what you really need.
Yes, I want the Perl script to programmatically control the browser
session. I took the advice of the first person: look into using
win32:ole. It looks very close to what I want. But the ole example
only controls Word/Excel but not Internet Explorer -- I try to
understand what ole is and see if I can change it to control internet
explorer.
However, I'll look at your suggestion as well. May be what you suggest
will met my goal. Thanks.
------------------------------
Date: Mon, 04 Oct 1999 15:12:10 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Knowing sizeof (int) inside a Perl program
Message-Id: <37F9263A.8644F5FA@cisco.com>
I am writing a configuration script and I need to know
the value of sizeof(int), sizeof(char) etc inside
my perl program. What is the easiest way to do this.
--
------------------------------
Date: Mon, 04 Oct 1999 16:42:26 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Knowing sizeof (int) inside a Perl program
Message-Id: <37F93B62.5A371C6@mail.cor.epa.gov>
Makarand Kulkarni wrote:
>
> I am writing a configuration script and I need to know
> the value of sizeof(int), sizeof(char) etc inside
> my perl program. What is the easiest way to do this.
Do you mean the amount of space Perl takes up in RAM, or
the intsize which can be seen when you type 'perl -V'?
The latter is available if you:
use Config;
and read the appropriate key out of %Config .
I thought that by definition sizeof(char) had to be 1.
Huh. Oh well, live and learn... :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 16:24:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie: Chomp and Case Conversion on Input
Message-Id: <37F93746.4B0C0D23@mail.cor.epa.gov>
Michael W. Fleming wrote:
>
> In article <MPG.12629add13dcb82e98a030@nntp.hpl.hp.com>, lr@hpl.hp.com
> (Larry Rosler) wrote:
>
> >You're welcome. Now I have to wonder why anyone cares about piling
> >several operations into one statement. Does Cal State Bakersfield
> >charge exorbitant rates per semicolon?
>
> Only $.01 per 100, but they add up :).
>
> Call it economy, call it perverse logic, call it my version of PerlThink
> laziness--if I have a semi-standard way of treating my input, it's easier
> to remember one line.
Curiosity is fine. But remember that shoving everything onto
1 line is not the same as perlstyle. See the perlstyle manpage
for more information.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 17:40:48 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: Newbie: Combining split and shift on One Statement
Message-Id: <37F9490F.22B788C7@synopsys.com>
Hi Tom,
Tom Briles wrote:
> perldoc -f split
>
> explains this issue precisely.
I've looked at my version of perldoc -f split, and I don't see where it talks
about shift or anything like that. Do I not have the right version? Do you
know where I can get the right version?
Appended is my version of the perldoc -f split output.
Thanks for your help,
-=dav
---------------------- Begin Documentation ------------------------
split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split Splits a string into an array of strings, and returns it. By
default, empty leading fields are preserved, and empty
trailing ones are deleted.
If not in list context, returns the number of fields
found and splits into the `@_' array. (In list context,
you can force the split into `@_' by using `??' as the
pattern delimiters, but it still returns the list
value.) The use of implicit split to `@_' is deprecated,
however, because it clobbers your subroutine arguments.
If EXPR is omitted, splits the `$_' string. If PATTERN
is also omitted, splits on whitespace (after skipping
any leading whitespace). Anything matching PATTERN is
taken to be a delimiter separating the fields. (Note
that the delimiter may be longer than one character.)
If LIMIT is specified and positive, splits into no more
than that many fields (though it may split into fewer).
If LIMIT is unspecified or zero, trailing null fields
are stripped (which potential users of `pop()' would do
well to remember). If LIMIT is negative, it is treated
as if an arbitrarily large LIMIT had been specified.
A pattern matching the null string (not to be confused
with a null pattern `//', which is just one member of
the set of patterns matching a null string) will split
the value of EXPR into separate characters at each point
it matches that way. For example:
print join(':', split(/ */, 'hi there'));
produces the output 'h:i:t:h:e:r:e'.
The LIMIT parameter can be used to split a line
partially
($login, $passwd, $remainder) = split(/:/, $_, 3);
When assigning to a list, if LIMIT is omitted, Perl
supplies a LIMIT one larger than the number of variables
in the list, to avoid unnecessary work. For the list
above LIMIT would have been 4 by default. In time
critical applications it behooves you not to split into
more fields than you really need.
If the PATTERN contains parentheses, additional array
elements are created from each matching substring in the
delimiter.
split(/([,-])/, "1-10,20", 3);
produces the list value
(1, '-', 10, ',', 20)
If you had the entire header of a normal Unix email
message in `$header', you could split it up into fields
and their values this way:
$header =~ s/\n\s+/ /g; # fix continuation lines
%hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
The pattern `/PATTERN/' may be replaced with an
expression to specify patterns that vary at runtime. (To
do runtime compilation only once, use `/$variable/o'.)
As a special case, specifying a PATTERN of space (`' '')
will split on white space just as `split()' with no
arguments does. Thus, `split(' ')' can be used to
emulate awk's default behavior, whereas `split(/ /)'
will give you as many null initial fields as there are
leading spaces. A `split()' on `/\s+/' is like a
`split(' ')' except that any leading whitespace produces
a null first field. A `split()' with no arguments really
does a `split(' ', $_)' internally.
Example:
open(PASSWD, '/etc/passwd');
while (<PASSWD>) {
($login, $passwd, $uid, $gid,
$gcos, $home, $shell) = split(/:/);
#...
}
(Note that `$shell' above will still have a newline on
it. See the chop, chomp, and join entries elsewhere in
this document .)
------------- END DOCUMENTATION ------------------------------------
------------------------------
Date: Mon, 04 Oct 1999 15:50:21 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: NewsClipper Script
Message-Id: <37F92F2D.40BE01D6@mail.cor.epa.gov>
skorpion84@my-deja.com wrote:
>
> Has anyone here ever used the NewsClipper Script?
Not that I know of.
> I am trying to install it on my webhost providers machine and I only
> have access to my directory. The machine is a BSDI BSD/OS 4.0 and has
> perl5. I would like to know how to install single-user access only.
The Perl FAQ has several helpful question/answer pairs on this.
You can find them quickly using perldoc and searching on the
keyword 'module'.
> What permissions do I have to set on the files for the script to get it
Now that's really more of a CGI issue than a Perl issue. You
might check out the CGI Programming FAQ at
http://www.webthing.com/tutorials/cgifaq.html
[which is referenced in the Perl FAQ also, so you may already
know about it].
> to work. You can email me at revned@gis.net
No thank you. Usenet is a society based on threads which
live on newsfeeds, and hence posts need to appear in this
newsgroup in order for others to benefit. It's to your
benefit as well, since how do you know that my answer is
any good unless it gets the 'peer review' of this newsgroup?
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 16:17:11 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: pattern match. & ? operator
Message-Id: <37F93577.BFACC724@mail.cor.epa.gov>
s. morgan friedman wrote:
>
> hi all,
>
> i'm having a problem pattern matching and i can't seem to
You seem to be having an 'indent' problem too. Is this a
problem with your newsreader?
> find any help in o'reilly nor the FAQ, so i'm hoping
Well, at least you're *looking* in the FAQ. That's a
nice change.
> someone here has an idea :) i'm pretty new to all this,
> and i've been studying assiduously the documentation,
> but i think i missed something :(
Well, the real info on regexes is in the 'perlre' document,
which is on your hard drive already if you have installed Perl.
You can read it by typing 'perldoc perlre' at a command
prompt [among other ways].
> i want to match a pattern either like "one" or "one (two)";
> if there're parenthesis i want to get both data (one and
> two in this example) or if not, return the entire string
> (one). i'm trying to do it like this:
>
> $string = "one (two)";
> if ($string =~ /(.*)(\(.*\))?/) {
> print "one: $1\n";
> print "two: $2\n";
> }
>
> but this doesn't return the expected results, instead:
>
> one: one (two)
> two:
Funny, that's what I expected.
[snip]
> the problem with this is i want the (two) to be optional.
> this leads me to suggest my problem has something to do
> with the ?. i also tried using the .*? because i guessed
> it might be a greed problem, but to no avail. i'm clueless.
> do any of you have any ideas? thanks so much!!
Well, for someone purporting to be clueless, you're awfully
close already. It is a 'greediness' issue. The first part
of the regex matches everything it can, then after that you
have nothing left.. but that's okay because the '?' after the
second sets of parens says that part is optional.
There are a lot of ways you might try to fix this. One simple
approach: rather than matching .* [everything], try this:
if ( $string =~ /(\w+) (\(\w+\))?/ ) {
print "one: $1\n";
print "two: $2\n";
}
So now you match a string of 1 or more 'word' characters
[letters, numbers, and/or '_'], a space, then maybe a sequence
of 'word' characters in parens.
Read the perlre pages for much more.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 23:17:33 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: pattern match. & ? operator
Message-Id: <37F9358E.F4CCE7A2@home.com>
[posted & mailed]
s. morgan friedman wrote:
>
> $string = "one (two)";
> if ($string =~ /(.*)(\(.*\))?/) {
> print "one: $1\n";
> print "two: $2\n";
> }
>
> but this doesn't return the expected results, instead:
s/expected/desired/;
> one: one (two)
> two:
>
> what's interesting, though, is that if i take out the ?
> (which refers to the '(two)'), ie so that the (two) is
> no longer optional but mandatory, then it works perfectly!
Yes, since now you're forcing it to backtrack. There is no reason to
backtrack to get a match for (PATTERN)? when it can always match the
null string at whatever position the preceding pattern stopped.
> code:
>
> $string = "one (two)";
> if ($string =~ /(.*)(\(.*\))/) {
> print "one: $1\n";
> print "two: $2\n";
> }
else {
print "one: $string\n";
}
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Mon, 4 Oct 1999 16:34:37 -0700
From: James Nessen <nessenj@jimsoffice.org>
Subject: pattern matching question
Message-Id: <Pine.LNX.4.10.9910041629250.19541-100000@ns0.jimsoffice.org>
Hello,
Got a quick and hopefully easy question for everyone. I am trying to do
*exact* pattern matching to remove a user from a file. Well, the script
that I wrote did that and more. I removed a user "jam" and the script
went through and removed everyone with "jam" in front, ie "james", "jamie"
How can I modify my script to only remove the user "jam" and nothing else?
Here is an example of my source...
open(IN, "/etc/raddb/users") || die "Can't open users: $!\n";
open(OUT, ">/etc/raddb/users.tmp") || die "Can't open temp: $!\n";
while(<IN>) {
$userfound = 1;
$in = $_;
if ($in =~ /^P$u/){$userfound=0}
if ($userfound) {print OUT}
}
close(IN);
close(OUT);
TIA!
Jim
--
James Nessen
E. nessenj@jimsoffice.org
P. 916.296.5454
F. 916.313.3481
W. http://www.jimsoffice.org
------------------------------
Date: 5 Oct 1999 01:29:59 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: pattern matching question
Message-Id: <slrn7vil5a.a5.efflandt@efflandt.xnet.com>
On Mon, 4 Oct 1999 16:34:37 -0700, James Nessen <nessenj@jimsoffice.org> wrote:
>Hello,
> Got a quick and hopefully easy question for everyone. I am trying to do
>*exact* pattern matching to remove a user from a file. Well, the script
>that I wrote did that and more. I removed a user "jam" and the script
>went through and removed everyone with "jam" in front, ie "james", "jamie"
>How can I modify my script to only remove the user "jam" and nothing else?
Perhaps you should check for word boundaries (\b)?
--
David Efflandt efflandt@xnet.com http://www.xnet.com/~efflandt/
http://www.de-srv.com http://cgi-help.virutalave.net/
http://thunder.prohosting.com/~cv-elgin/
------------------------------
Date: Mon, 04 Oct 1999 22:13:36 GMT
From: Kermit Lowry, III <ultrak@my-deja.com>
Subject: Pulling positional data from a string
Message-Id: <7tb8q5$nvc$1@nnrp1.deja.com>
The following code snippet is from a ksh script that I am trying to
convert to Perl.
The script pulls each line from a file, grabs digits from positions 21
- 24 that determines the rest of the pertinent data on that line, and
then truncates the line at ( 24 + cut -c21-24) positions. $x is a
count that gets appended to the beginning of each line to keep the
sorted data in read sequence order during the sort. This number is
discarded after the sort is complete.
My first question is how to cut the positional data from the string?
And second is how do accomplish the sort?
**************************************
while read iline
do
datalen=`echo "$iline" | cut -c21-24 | tr -d ' '`
(( totreclen = datalen + 24 ))
echo "$iline" | eval cut -c1-${totreclen} | sed "s/^/$x /g" >>
${cashfile}f
(( x = x + 1 ))
done
# sort by inode (ascii) then sequence (numeric)
sort -T /tmp -k2.1,2.9 -k1,1n ${cashfile}f | sed 's/^[0-9]* //' >
${cashfile}.yy
y
TIA,
-- Kermit Lowry, III
----------------
"Only you can prevent forest fires!" -Smoky
klowry@DELETEfhlbatl.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 4 Oct 1999 23:42:43 GMT
From: gerry@xmission.com (Gerry JJ Dyn-O-Myte Walker)
Subject: regexp question - last occurrence of an expression before another
Message-Id: <slrn7vieri.o01.gerry@xmission.xmission.com>
How do I extract the last occurrence of an expression occurring before
another expression. For example in the following string:
A <b> lot </b> of <b> html </b> text, some of it in <b> bold </b>. I
want to extract the last <b> bold </b> section of <b> text </b> prior
to a list of items - <ul> <li> item one </ul> - maybe more <b> bold </b>
still.
I want to to extract only the last bold item (which is "text" in this
example) which occurs before the list <ul>.*<\/ul>
Any help is appreciated.
Gerry
------------------------------
Date: Mon, 04 Oct 1999 15:45:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Schnelle Bearbeitung von HTML-Seiten
Message-Id: <37F92DF8.EA078510@mail.cor.epa.gov>
Alex Rhomberg wrote:
>
> Christian Weerts wrote:
> >
> > Hallo
> >
> > ich suche nach einer möglichkeit, in mehreren html-seiten gleichzeitig eine(n) bestimmte
> >
> > Änderung / Link einzufügen. Gibt es da unter perl eine möglichkeit?
>
> ja
>
> I suggest posting english on an english newsgroup next time
> there exists also de.comp.lang.perl.misc
Actually, given the linguistic expertise floating around here,
there seems to be less resistance to posts in something other
than Englsih than there is in many other newsgroups. Witness
Larry Rosler's quick reply. So if you feel comfortable
answering in German, you may get less flack here than some
other groups.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 05 Oct 1999 01:10:31 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: setpwent
Message-Id: <becK3.96$xs2.4015@nsw.nnrp.telstra.net>
On 1 Oct 1999 04:18:05 -0500,
Abigail <abigail@delanet.com> wrote:
> Martien Verbruggen (mgjv@comdyn.com.au) wrote on MMCCXXII September
> MCMXCIII in <URL:news:vQVI3.130$Fy1.5807@nsw.nnrp.telstra.net>:
> ||
> || Setting fields in passwd strings is a very system and configuration
> || dependent thing (yp, NIS, shadow), and therefore hard to express in a
> || general API. AFAIK you will need to use OS specific tools.
>
>
> vi seems to be on any platform with a /etc/passwd file.
But /etc/passwd is not always where you want to change these things
(see references to NIS).
Martien
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd. | negative.
NSW, Australia |
------------------------------
Date: Mon, 4 Oct 1999 18:36:25 -0400
From: "aryes2" <aryes2@email.msn.com>
Subject: try to test perl off-line
Message-Id: <#CT$4jrD$GA.177@cpmsnbbsa05>
I would like to use my scripts in my computer, without being connected,
run from the browser a form and see if it is correct
help please
Andres Garzon
andgarzon@hotmail.com
------------------------------
Date: Mon, 4 Oct 1999 15:58:33 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: try to test perl off-line
Message-Id: <MPG.1262d0f6824bcf429897cd@206.184.139.132>
aryes2 (aryes2@email.msn.com) seems to say...
> I would like to use my scripts in my computer, without being connected,
> run from the browser a form and see if it is correct
Install a web server. But don't forget your command-line debugging
techniques.
Search for webservers on your favorite search engine (but I like
http://www.apache.org).
Also, keep in mind there's lots of CGI FAQs available.
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Mon, 04 Oct 1999 16:45:06 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: try to test perl off-line
Message-Id: <37F93C02.43FDBCC6@mail.cor.epa.gov>
aryes2 wrote:
>
> I would like to use my scripts in my computer, without being connected,
> run from the browser a form and see if it is correct
Good. This is what most people should do.
Get the CGI.pm module and a free webserver [Apache is one
of the non-Microsoft ones]. Install the webserver on your
machine. Write your CGI script using Perl and CGI.pm .
Point your browsers [plural - use more than one so you
know how other browsers will read your page] at your webpage.
Inspect. Voila!
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 04 Oct 1999 15:11:25 -0700
From: frEEk <freek@coolmail.net>
Subject: using alarm for timeouts
Message-Id: <37F9260C.F4B662AE@coolmail.net>
I'm trying to time out a connect using the method shown in the man
pages, but it is not working:
eval {
local $SIG{ALRM} = sub { die };
alarm(10);
$connected=connect($S,pack_sockaddr_in($port,$smtp));
alarm(0);
};
It simply allows the connect to hang on a bad ip, until the thread is
killed (by some other timeout I assume). I tend to think the problem is
that when running threaded perl (5.03) the signal is not reaching the
thread, but that's just a guess. Can someone tell me what's going on
here?
Thanks
--
Life is out to get me...
ERTW!
------------------------------
Date: Mon, 04 Oct 1999 18:58:49 -0400
From: George Kuetemeyer <george.kuetemeyer@mail.tju.edu>
Subject: Re: Using SS Numbers as DBM Index: Best Way to Encrypt Them
Message-Id: <37F93128.DC09924E@mail.tju.edu>
Fred Reimer wrote:
> It's against several laws to require SSN's for this purpose. If you're
> never going to decrypt them, why use them at all?
Thanks for your comments. We're trying to reconcile several data feeds. The
*only* common value is the ssn. We could match on names, but unfortunately the
names for the same person are not necessarily the same. Some feeds use a middle
initial, others don't. Some use one variant on a first name, some the other
(Jim/James). Once the reconciliation has been done, we will generate unique
identifiers and remove the ssn data.
------------------------------
Date: 5 Oct 1999 01:23:47 GMT
From: Colin R. DeVilbiss <crdevilb@mtu.edu>
Subject: XS and file handles
Message-Id: <7tbjv3$1ba$1@campus3.mtu.edu>
When writing an XS module that has to do file interaction, is there a
canonical way to pass a perl filehandle into an XSUB?
for example, is there a direct translation to C<FILE*> from a filehandle?
it seems like passing fileno(HANDLE) is inappropriate because the input
can be buffered in HANDLE before the C function can do an fdopen()..
any recommendations?
thanks.
Colin R. DeVilbiss
crdevilb@mtu.edu
------------------------------
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 985
*************************************