[18874] in Perl-Users-Digest
Perl-Users Digest, Issue: 1042 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 2 11:05:40 2001
Date: Sat, 2 Jun 2001 08:05:10 -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: <991494310-v10-i1042@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 2 Jun 2001 Volume: 10 Number: 1042
Today's topics:
"The Camel Book", "The Ram Book" or "Perl : The Program <cjr@tuks.co.za>
Re: "The Camel Book", "The Ram Book" or "Perl : The Pro <bowman@montana.com>
Re: "The Camel Book", "The Ram Book" or "Perl : The Pro <pne-news-20010602@newton.digitalspace.net>
[OT] Re: Flame,help or killfile ? <joe+usenet@sunstarsys.com>
Re: Can anyone find the problem with this script ?!?!?! <joe+usenet@sunstarsys.com>
Common Problems with Taint Mode <davsoming@lineone.net>
Re: Common Problems with Taint Mode <joe+usenet@sunstarsys.com>
Re: date calc modules (Tad McClellan)
Re: Fcntl usage with tie? <m.grimshaw@salford.ac.uk>
Re: Flame,help or killfile ? <flavell@mail.cern.ch>
from ASP to Perl <bee@mindspring.com>
Re: module for MS SQL (Abigail)
Re: Newbie question ... nobull@mail.com
Re: Newbie question ... (Tad McClellan)
Re: Posting Etiquette (Abigail)
regex question. $25 for answer. (Marc Fest)
Re: regex question. $25 for answer. <keesh@users.sf.net>
Re: regex question. $25 for answer. <krahnj@acm.org>
Re: regex question. $25 for answer. <tinamue@zedat.fu-berlin.de>
Re: regex question. $25 for answer. (Abigail)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 2 Jun 2001 13:43:33 +0200
From: Kerneels Roos <cjr@tuks.co.za>
Subject: "The Camel Book", "The Ram Book" or "Perl : The Programmer's Companion - Nigel Chapman"
Message-Id: <991482040.275358@nntp.up.ac.za>
Hi,
I'm a 2 month old newbie to perl and cgi in general. Where I work the
infamous CAMEL book(s) are by this time long gone, snatched or perhaps part
of the collection of objects that the Burmuda Triangle eats from time to
time. I was wondering if there are a free electronic copy of this or some
other foundation laying text available?
Kind regards,
C.J. Roos.
------------------------------
Date: Sat, 2 Jun 2001 07:41:28 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: "The Camel Book", "The Ram Book" or "Perl : The Programmer's Companion - Nigel Chapman"
Message-Id: <D%5S6.393$X_2.1378@newsfeed.slurp.net>
"Kerneels Roos" <cjr@tuks.co.za> wrote in message
news:991482040.275358@nntp.up.ac.za...
>
> I'm a 2 month old newbie to perl and cgi in general. Where I work the
> infamous CAMEL book(s) are by this time long gone, snatched or perhaps
part
> of the collection of objects that the Burmuda Triangle eats from time to
> time. I was wondering if there are a free electronic copy of this or some
> other foundation laying text available?
Much of Camel II was almost a hardcopy version of the docs included with
every Perl package. These docs ARE the foundation laying text.
------------------------------
Date: Sat, 02 Jun 2001 16:53:04 +0200
From: Philip Newton <pne-news-20010602@newton.digitalspace.net>
Subject: Re: "The Camel Book", "The Ram Book" or "Perl : The Programmer's Companion - Nigel Chapman"
Message-Id: <e8vhhtg1gjjn34pk67fmtbhcpe0hiplahj@4ax.com>
On Sat, 2 Jun 2001 13:43:33 +0200, Kerneels Roos <cjr@tuks.co.za> wrote:
> the infamous CAMEL book(s)
"infamous"? Are you sure you meant that?
> I was wondering if there are a free electronic copy of this
There are copies available without charge on some pirate sites, yes.
What's wrong with buying your own copy or asking your employer to buy
you one? If it's a tool you need and all other copies are sunning
themselves in Bermuda, it's a legitimate request.
If you like HTML versions, you could try for the Bookcase (don't recall
the exact name), which includes several Perl books on CD-ROM.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 02 Jun 2001 07:44:59 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: [OT] Re: Flame,help or killfile ?
Message-Id: <m3ae3rm7gk.fsf@mumonkan.sunstarsys.com>
buggs <buggs@geekmail.de> writes:
> Considering the recent discussions on this topic
> you migth be interested in the following.
>
> See Simons article:
> http://www.perl.com/pub/2001/05/29/tides.html
That's not Simons article; it appears that Casey West wrote it.
> Reactions on the article:
> http://use.perl.org/article.pl?sid=01/06/01/048204&mode=flat&threshold=
>
> And a new site mentioned in the article:
> http://learn.perl.org
A lovely, myopic vision of utopia- and it makes a mighty fine wheel, too.
http://learn.perl.org/beginners-faq
Those are exactly the recommended guidelines for posting here, in
case anyone hadn't noticed. And they're already outmoded- apparently
CGI questions have been forked off to another mailing list. Sound
familiar?
<rant>
It will be interesting to see how order is maintained in a place
where everyone is nice to people that aren't interested in following
the rules.
Hmm, what next- a low volume, high signal/noise moderated list, perhaps?
IMHO, people with such strong convictions about the horrors of clp.misc
should
1) read the clp.moderated charter and figure out why it didn't help,
2) consider why some other language groups (like c.l.c- which discusses
*Standard* C) handle more traffic with IMHO a higher s/n ratio
than clp.misc.
3) suck it up and first try to fix this place before recreating it.
They just might find that there's little that can be done to "mentor"
a PFY into submissive conformity.
Some people just don't want to learn that their confusion really isn't
perl related at all, and would prefer a bad answer to an offtopic
question rather than being told where to get a good one. But of course
most of them will wait for the mailing list's ensuing web interface to
protect their precious status as yet another anonymous coward.
</rant>
And yes, being a japh wizard does not imply you are an expert at
anything else, much less an expert programmer. Answering OT questions
on a mailing list for beginners is misguided pedagogy, and IMHO is far
worse than flaming someone for doing so.
--
Joe Schaefer "A man cannot be too careful in the choice of his enemies."
--Oscar Wilde
------------------------------
Date: 02 Jun 2001 10:22:40 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Can anyone find the problem with this script ?!?!?!
Message-Id: <m31yp3m05r.fsf@mumonkan.sunstarsys.com>
"SilverSting" <reply@group.thanx> writes:
> Here is my script, write form info to text file. Can anyone help me with
> errors.
Yes- on the beginners@perl.org list. You can sign up at
http://learn.perl.org
--
Joe Schaefer "A cynic is a man who knows the price of everything and the
value of nothing."
--Oscar Wilde
------------------------------
Date: Sat, 2 Jun 2001 11:00:45 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Common Problems with Taint Mode
Message-Id: <thhe1p22kgdi2c@corp.supernews.co.uk>
I simply dont get it!
How can I use this script with -T enabled? I have been reading over at:
http://www.oreilly.com/catalog/cgi2/chapter/ch08.html
that environment variables such as IFS, CDPATH, ENV, and BASH_ENV. arn't
needed-
Also (as I understand it) calling external programs, I must make sure that
$ENV{PATH} does not contain any directories that can be modified by anyone
other than their owner.
If my script needs to require ""or include "" should I explicitly add the
current directory to @INC or include the full or relative path to the code?
It also suggest adding these two lines:
$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
If so whats the format?
Can the problem stem from pipe | ?
I'm no wiser now than I was a week ago!
#!/usr/bin/perl -wT
require "subparseform.lib";
&Parse_Form;
$email = $formdata{'email'};
open (EMAILS, ">>address.txt");
flock(EMAILS, 2);
print EMAILS "$email\n";
flock(EMAILS, 8);
close (EMAILS);
print "Content-type: text/html\n\n";
print "Your email address ($email) has been successfully entered for our
newsletter.";
print "Thank you. You will receive a confirmation email shortly.";
$from = "newsletter\@some-domain.com";
open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
print MAIL "To: $email \nFrom: $from\n";
print MAIL "Confirmation Email\n\n";
print MAIL "Thank you for signing up. Your email address ($email) has
been added successfully!\n\n";
print MAIL "Have a nice day.\n";
close (MAIL);
sub ErrorMessage {
print "<P>The server has a problem. Aborting script. \n";
exit;
}
#### David
------------------------------
Date: 02 Jun 2001 09:24:05 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Common Problems with Taint Mode
Message-Id: <m366efm2ve.fsf@mumonkan.sunstarsys.com>
"David Soming" <davsoming@lineone.net> writes:
> I simply dont get it!
> How can I use this script with -T enabled? I have been reading over at:
> http://www.oreilly.com/catalog/cgi2/chapter/ch08.html
> that environment variables such as IFS, CDPATH, ENV, and BASH_ENV. arn't
> needed-
The reason taint checks test your %ENV settings is that the environment
is part of the info your script is passing to the external program. You
need to be careful with those settings, in case the external program
you are calling isn't as careful as you are. Taint checks are meant
to help protect not just your perl script, but the program you are
calling as well.
> Also (as I understand it) calling external programs, I must make sure that
> $ENV{PATH} does not contain any directories that can be modified by anyone
> other than their owner.
Right- and be sure to check out the documentation in perlsec-
% perldoc perlsec
It talks about taint requirements in some detail.
> If my script needs to require ""or include "" should I explicitly add the
> current directory to @INC or include the full or relative path to the code?
> It also suggest adding these two lines:
> $ENV{PATH} = "/bin:/usr/bin";
> delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
> If so whats the format?
I usually just use
local %ENV;
and wipe out the entire environment right where I'm calling the
external program. Ignoring the flock()ing for append overkill,
here's how I'd change your script (untested):
[...]
> open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
> print MAIL "To: $email \nFrom: $from\n";
> print MAIL "Confirmation Email\n\n";
> print MAIL "Thank you for signing up. Your email address ($email) has
> been added successfully!\n\n";
> print MAIL "Have a nice day.\n";
> close (MAIL);
{
local %ENV; #sendmail doesn't need any ENV for delivery
# see % perldoc -q "send mail" for better sendmail flags
open MAIL => "|/usr/sbin/sendmail -t" or goto &ErrorMessage;
print MAIL <<"MAIL";
To: $email
From: $from
Subject: Confirmation Email
Thank you for signing up- you have been successfully added!
Have a nice day.
MAIL
close MAIL or warn "trouble delivering to '$to': $?";
}
HTH
--
Joe Schaefer "Things may come to those who wait, but only the things left by
those who hustle."
-- Abraham Lincoln
------------------------------
Date: Sat, 2 Jun 2001 08:26:44 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: date calc modules
Message-Id: <slrn9hhms4.b5a.tadmc@tadmc26.august.net>
Rob Parker <chickenmilkbomb@hotmail.com> wrote:
>I am looking for a module
http://search.cpan.org
is where you look for modules.
comp.lang.perl.modules
is where you discuss modules.
>that will allow me to calulate dates in the
>future. I need to take the current date (or any arbitrary date) and
>calculate the settlement date for a trade 3 *business* days in the
^^^^^^^^
>future.
The same term that you felt should be highlighted might also prove
to be a good search term...
:-)
>By the way, I am an experienced java programmer
>I am really
>excited about learning Perl
>Finally - another language that is portable, easy to use.
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
What language are you referring to there?
Or maybe you just mean that Java is "easy to use"?
(that would seem a hard position to support)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 02 Jun 2001 11:28:34 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Fcntl usage with tie?
Message-Id: <3B18BFD2.D46CA22E@salford.ac.uk>
Hi Martien, (hoping the other thread dies a natural death)
You asked for examples of what works and what doesn't with finite
scripts (my query is on the use O_RDONLY).
This is perl, version 5.005_02 built for IP22-irix.
(The use of more code than I need to simply tie a DB_File is purely to
illustrate the puzzle and represents an abstraction of far larger
scripts that I'm currently using.)
1st. EXAMPLE:
This works:
#!/usr/local/bin/perl -w
use VH;
use strict; use diagnostics;
use Fcntl;
my $db = new DB;
my %DB;
if(!(%DB = $db->open_db('test.db', O_RDONLY)))
{
print "Failed\n\n";
}
else
{
print "Success\n";
print "First entry = $DB{0}\n\n";
}
exit;
############# end of code
#!/usr/local/bin/perl -w
# OOP VH package
package VH;
use strict; use diagnostics;
use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(new open_db);
##############################
# All open, close, read and write database operations
package DB;
use DB_File;
sub new
{
my $class = shift;
my $self = {};
%$self = @_;
bless $self;
}
sub open_db
{
my $self = shift;
my @input = @_;
my %DB;
tie(%DB, 'DB_File', $input[0], $input[1]) || return 0;
return %DB;
}
1;
######################## end of code
...and prints:
Success
First entry = Music Technology and Studio Production Examination
Semester Two¬PMR-MAR¬Level 1¬Answer all
questions¬trevor¬t.warner@salford.ac.uk
#########################
2nd. EXAMPLE:
This works (replacing O_RDONLY with 0 (zero) and 'tie' is called from
within the same package):
#!/usr/local/bin/perl -w
use strict; use diagnostics;
use TEST;
my %DB;
if(!(%DB = open_db))
{
print "failure\n\n";
}
else
{
print "Success\n";
print "First entry = $DB{0}\n\n";
}
exit;
######################## end of code
#!/usr/local/bin/perl -w
use strict; use diagnostics;
use Fcntl; use DB_File;
package TEST;
use vars qw(@ISA @EXPORT);
use Exporter();
@ISA = qw(Exporter);
@EXPORT = qw(open_db);
sub open_db
{
my %DB;
if(!(tiedb(\%DB, 'test.db', 0, 0444)))
{
return 0;
}
return %DB;
}
sub tiedb
{
my($D, $dbb, $modea, $modeb) = @_;
tie(%{$D}, 'DB_File', $dbb, $modea, $modeb) || return 0;
return 1;
}
1;
############## end of code
.......and prints:
Success
First entry = Music Technology and Studio Production Examination
Semester Two¬PMR-MAR¬Level 1¬Answer all
questions¬trevor¬t.warner@salford.ac.uk
The PUZZLE:
In EXAMPLE 2, if I replace
if(!(tiedb(\%DB, 'test.db', 0, 0444)))
with
if(!(tiedb(\%DB, 'test.db', O_RDONLY, 0444)))
I get the error:
Bareword "O_RDONLY" not allowed while "strict subs" in use at TEST.pm
line 14 (#1)
(F) With "strict subs" in use, a bareword is only allowed as a
subroutine identifier, in curly braces or to the left of the "=>"
symbol.
Perhaps you need to predeclare a subroutine?
Uncaught exception from user code:
Uncaught exception from user code:
Compilation failed in require at ./test.pl line 4.
main::BEGIN() called at TEST.pm line 27
eval {...} called at TEST.pm line 27
BEGIN failed--compilation aborted at ./test.pl line 4.
If I replace it with:
if(!(tiedb(\%DB, 'test.db', 'O_RDONLY', 0444)))
or
if(!(tiedb(\%DB, 'test.db', "O_RDONLY", 0444)))
I get the warning:
Argument "O_RDONLY" isn't numeric in entersub at
/usr/local/lib/perl5/5.00502/IP22-irix/DB_File.pm line 255 (#1)
(W) The indicated string was fed as an argument to an operator that
expected a numeric value instead. If you're fortunate the message
will identify which operator was so unfortunate.
Success
First entry = Music Technology and Studio Production Examination
Semester Two¬PMR-MAR¬Level 1¬Answer all
questions¬trevor¬t.warner@salford.ac.uk
The QUESTION:
What is the distinguishing feature between the 2 examples that allows me
to use O_RDONLY (without quotes) without complaints in EXAMPLE 1 but not
in EXAMPLE 2?
------------------------------
Date: Sat, 2 Jun 2001 14:35:28 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Flame,help or killfile ?
Message-Id: <Pine.LNX.4.30.0106021402570.28340-100000@lxplus003.cern.ch>
On Sat, 2 Jun 2001, buggs wrote:
> http://www.perl.com/pub/2001/05/29/tides.html
>
> Reactions on the article:
> http://use.perl.org/article.pl?sid=01/06/01/048204&mode=flat&threshold=
Thanks for mentioning this.
A random quote:
|| I'd love to see c.l.perl* becomes a more helpful and less
|| confrontational place.
Strange as it may seem, I think that's the view of most of the
participants here. But they want to discuss Perl, not to act as a
first-level help desk for people who demonstrate that they aren't
interested in learning Perl - don't believe it's necessary to read any
documentation, not even FAQs - feel it's entirely OK to say in effect
"cut the crap, GIVE me working code to do what I demand, or shut up".
And (what clearly irks quite a number of participants) they would
happily quote the entire previous discussion in every posting,
complete with umpteen quoted copies of the CNET disclaimer, if nobody
was allowed to rebuke them for it. They don't seem to be able to
comprehend that if everyone did this, it just wouldn't scale.
I think it's great that someone is willing to get them started and up
to sufficient speed to participate here. I just don't want to see the
debating chamber used as a first-level helpdesk. Not because I want
to be elitist, but because in practical terms - that phrase again - it
doesn't scale.
I've learned a great deal in the past, just by lurking here. I hope
others can do the same. If they're knee deep in FAQs that they have
already perused on their own hard disks, they might never spot the
real points at which there's something to learn.
cheers
------------------------------
Date: Sat, 2 Jun 2001 07:30:27 -0400
From: "bc" <bee@mindspring.com>
Subject: from ASP to Perl
Message-Id: <9faira$bd$1@slb6.atl.mindspring.net>
i use mandrake (and/or) redhat, i also use ASP/VBScript with my windows box,
i want to change to Perl on my linux box, but i do not know how to install
it and or get to the point of coding it in a text editor? where or how,
any advice anyone, i'de appreciate it, lots! :)
------------------------------
Date: Sat, 2 Jun 2001 13:25:24 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: module for MS SQL
Message-Id: <slrn9hhqa4.igv.abigail@tsathoggua.rlyeh.net>
rich (nospam@newsranger.com) wrote on MMDCCCXXXI September MCMXCIII in
<URL:news:PQIR6.241$v4.3542@www.newsranger.com>:
^^
^^ Hi,
^^ I usually use the MySQL database along with the module, DBI::MYSQL. For one
^^ reason or another I have to use Microsofts SQL server now. Could anybody
^^ recommend the best module for connecting to this database?
If there would be a single "best module", than there wouldn't be much of
a reason to use anything else.
I've never used MS SQL server, but I've used Sybase a lot. And since MS SQL
branched off Sybase, you should be able to connect to MS SQL using the
Sybase Client libraries (althought I guess, MS being MS, at one point, this
will no longer be possible). I've always used Sybase::DBlib to connect to
Sybase servers, without much problems.
Abigail
--
BEGIN {print "Just " }
CHECK {print "another "}
INIT {print "Perl " }
END {print "Hacker\n"}
------------------------------
Date: 02 Jun 2001 15:34:55 +0100
From: nobull@mail.com
Subject: Re: Newbie question ...
Message-Id: <u9snhjdk6o.fsf@wcl-l.bham.ac.uk>
mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> On 1 Jun 2001 21:22:02 -0700,
> Paul Cho <cybok@nobreak.com> wrote:
> 5) Always program with -w and strict, unless you know why not.
Actually if you are using 5.6 or later I'd recommend 'use warnings'
over -w as some commonly used modules are not warning clean.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 2 Jun 2001 08:17:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie question ...
Message-Id: <slrn9hhmaa.b5a.tadmc@tadmc26.august.net>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On 1 Jun 2001 21:22:02 -0700,
> Paul Cho <cybok@nobreak.com> wrote:
>
>1) You need to start using -w
>2) You need to start using strict.
>3) You need to start using -w and strict.
>4) Use -w and strict.
>5) Always program with -w and strict, unless you know why not.
>
>Did I mention that you probably should use -w and strict?
"Don't forget to enable warnings and strictures even when you're not
writing in Perl. It's *that* important."
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 2 Jun 2001 10:06:15 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Posting Etiquette
Message-Id: <slrn9hhekn.igv.abigail@tsathoggua.rlyeh.net>
Chris Stith (mischief@velma.motion.net) wrote on MMDCCCXXXI September
MCMXCIII in <URL:news:thg0i1quhdah6e@corp.supernews.com>:
||
|| Why do we (yes, "we" -- I've been known to do it too)
|| publicly announce killfiling people on such a regular basis? I mean,
|| if someone has been so blatantly rude that they deserve a slap in
|| the face along with being ignored, that's one thing. Often, though,
|| people get a public *plonk* for things which seem a trifle.
For two, obvious, reasons:
1) To let others know such behaviour isn't appreciated, and what the
consequences will be.
2) Because sometimes it feels better to do it publicly than privately.
I usually killfile privately; only sometimes publicly.
Abigail
--
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'
------------------------------
Date: 2 Jun 2001 03:54:50 -0700
From: wx34@yahoo.com (Marc Fest)
Subject: regex question. $25 for answer.
Message-Id: <56876115.0106020254.342cb9f7@posting.google.com>
Hi, whoever can help me with this first, will get a $25 check in the
mail.
What's the regex for matching a single digit and only a single digit?
Ie I want to find a "lone" digit that must not be inside a group of
digits; it might be at the beginning or at the and of the string or
somewhere inside. For example, if $_="427427dsf497 3sds 44ddsf616",
then the regex should match 3 in this case on not any of the other
digits.
I've tried /\D*(\d)\D*/ but that didn't work.
Thank you for helping.
Pls reply to marc@delete_this_NOSPAMfest.net
Cheers from Miami Beach,
Marc.
------------------------------
Date: Sat, 02 Jun 2001 11:01:43 GMT
From: "Ciaran McCreesh" <keesh@users.sf.net>
Subject: Re: regex question. $25 for answer.
Message-Id: <rI3S6.26302$zb7.3356780@news1.cableinet.net>
In article <56876115.0106020254.342cb9f7@posting.google.com>, "Marc Fest"
<wx34@yahoo.com> said:
> Hi, whoever can help me with this first, will get a $25 check in the
> mail.
Bad start :)
> What's the regex for matching a single digit and only a single digit?
> Ie I want to find a "lone" digit that must not be inside a group of
> digits; it might be at the beginning or at the and of the string or
> somewhere inside. For example, if $_="427427dsf497 3sds 44ddsf616", then
> the regex should match 3 in this case on not any of the other digits.
> I've tried /\D*(\d)\D*/ but that didn't work. Thank you for helping.
(Copy sent by mail to keep OP happy)
/(^|\D)\d($|\D)/
Is that what you want?
Regards,
Ciaran
--
Ciaran McCreesh
mail: keesh at users dot sf dot net
web: http://www.opensourcepan.com
------------------------------
Date: Sat, 02 Jun 2001 11:09:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex question. $25 for answer.
Message-Id: <3B18C96E.B591F847@acm.org>
Marc Fest wrote:
>
> Hi, whoever can help me with this first, will get a $25 check in the
> mail.
>
> What's the regex for matching a single digit and only a single digit?
> Ie I want to find a "lone" digit that must not be inside a group of
> digits; it might be at the beginning or at the and of the string or
> somewhere inside. For example, if $_="427427dsf497 3sds 44ddsf616",
> then the regex should match 3 in this case on not any of the other
> digits.
>
> I've tried /\D*(\d)\D*/ but that didn't work.
Because \D* matches _zero_ or more non digits so it will _allways_
match. You need to match at least one non digit for this to work.
/\D(\d)\D/
If you also want to match at either the beginning or the end of the
string:
/(?:^|\D)(\d)(?:\D|$)/
> Thank you for helping.
You're welcome
John
--
use Perl;
program
fulfillment
------------------------------
Date: 2 Jun 2001 11:11:44 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: regex question. $25 for answer.
Message-Id: <9fahlg$36mvk$2@fu-berlin.de>
hi,
Marc Fest <wx34@yahoo.com> wrote:
> Hi, whoever can help me with this first, will get a $25 check in the
> mail.
wow that's cool - $25 for 5 minutes...
> What's the regex for matching a single digit and only a single digit?
> Ie I want to find a "lone" digit that must not be inside a group of
> digits; it might be at the beginning or at the and of the string or
> somewhere inside. For example, if $_="427427dsf497 3sds 44ddsf616",
> then the regex should match 3 in this case on not any of the other
> digits.
> I've tried /\D*(\d)\D*/ but that didn't work.
try:
01:02pm tina@lux:perl 1084> perl -e'
$_="1 abc fg456hi7 jk8";
while ( m/(^|\D+)(\d)(\D+|$)/g) {
print "<$1>\t*[$2]*\t<$3>\n";
pos($_) =pos($_)-1;
}'
(disclaimer: i don't know if decrementing pos() works for
all cases).
> Pls reply to marc@delete_this_NOSPAMfest.net
oh, what a pity, i don't do that. so i won't get the
money, huh?
regards,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: Sat, 2 Jun 2001 13:34:35 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: regex question. $25 for answer.
Message-Id: <slrn9hhqrb.igv.abigail@tsathoggua.rlyeh.net>
Marc Fest (wx34@yahoo.com) wrote on MMDCCCXXXII September MCMXCIII in
<URL:news:56876115.0106020254.342cb9f7@posting.google.com>:
:: Hi, whoever can help me with this first, will get a $25 check in the
:: mail.
::
:: What's the regex for matching a single digit and only a single digit?
:: Ie I want to find a "lone" digit that must not be inside a group of
:: digits; it might be at the beginning or at the and of the string or
:: somewhere inside. For example, if $_="427427dsf497 3sds 44ddsf616",
:: then the regex should match 3 in this case on not any of the other
:: digits.
/(?<!\d)\d(?!\d)/
Matches a digit that isn't preceeded, nor followed by a digit.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1042
***************************************