[15924] in Perl-Users-Digest
Perl-Users Digest, Issue: 3337 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 13 00:10:31 2000
Date: Mon, 12 Jun 2000 21:10:16 -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: <960869415-v9-i3337@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 12 Jun 2000 Volume: 9 Number: 3337
Today's topics:
Re: Larry Rosler interview on perl.com! <htp@mac.com>
Re: Larry Rosler interview on perl.com! <htp@mac.com>
Re: Larry Rosler interview on perl.com! <dparrott@ford.com>
Re: Larry Rosler interview on perl.com! (Damian Conway)
Re: Length of an Array <tony_curtis32@yahoo.com>
Re: Length of an Array <lauren_smith13@hotmail.com>
Re: Length of an Array (Craig Berry)
Re: Need to reload program after a sleep period <rootbeer@redcat.com>
newbie help: how to extract line by column position gelshocker@my-deja.com
Re: newbie help: how to extract line by column position (Prasanth A. Kumar)
Re: Perl is FAST!!! <phill@modulus.com.au>
Re: Perl is FAST!!! <y-o-y@home.com>
Re: Perl is FAST!!! <uri@sysarch.com>
Re: Perldebug - jump command? <rootbeer@redcat.com>
Re: print pdf <dparrott@ford.com>
regular expression help (matching exactly n times) <ppith@my-deja.com>
Re: regular expression help (matching exactly n times) (Clinton A. Pierce)
Re: regular expression help (matching exactly n times) <phill@modulus.com.au>
Re: regular expression help (matching exactly n times) <bwalton@rochester.rr.com>
Re: regular expression help (matching exactly n times) (Mark-Jason Dominus)
Re: Strange permission problems with ActivePerl 613 <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Jun 2000 10:54:40 +0930
From: Henry <htp@mac.com>
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <htp-60B026.10544013062000@news.metropolis.net.au>
>> Assuming the proponents of standardisation get their way, is there
>> any way we can 'rig it' to _prevent_ third parties from developing
>> their own compilers, which support their proprietary extensions,
>> and plunging us into a situation akin to the web?
Dan Sugalski:
> I think this is a bad idea. I think Larry Wall would too, though whether
> he thinks it's a worse idea than having a solid standards document is
> another issue. (I doubt he'd have a problem with the document, though.
> Official sanction of the document, yes. But the doc itself? Doubt it)
Sorry, I didn't mean rig the document itself, I meant "rig it" in a more
general sense. Perhaps the Perl license? I mean, everything to do with
Perl is copyright, even if it's free, so there's gotta be something
there we can leverage to protect our collective arse...
>> Specifically, and bluntly, is there a way to stop MICROSOFT from
>> humping the camel?
>
> Specifically targetting microsoft's silly. Besides, as far as perl
> is concerned I expect a number of software vendors would be just as
> bad if not worse.
Microsoft was the worst example I could think of, so I figured if we
came up with something that thwarts the Evil Empire, it should be proof
against just about anything.
I _wasn't_ thinking of...
if ($applicant eq 'Microsoft') { $application = 'Rejected'; }
else { $application = 'Approved'; }
More along the lines of...
"Thou shalt not modify the compiler - PERIOD."
>> I see absolutely no reason why compiler extensions should be allowed
>> at all. If a company wants added functionality, they can simply put
>> it in a module (Perl, C, precompiled, not, whatever).
>
> There's a lot you can't do without messing with the lexer/parser or other
> assorted under-the-hood bits. Building footer formats, for example, would
> require this, as would some other things. True, a lot can be done with
> modules, but you couldn't implement, say, "use Python" with them.
OK then, how about...
"Thou shalt not _distribute_ a modified compiler - PERIOD."?
Drew Simonis:
> [the point] is... the _language_ needs to be standardized, not the
> interpreter. Once the language is set in stone (or the base line
> for that language) then two things happen. The first is that
> what is already in place is formalized. The second is that the
> language continues to grow on a new, sturdy foundation.
I wasn't talking about the language. I'd already said "Assuming the
proponents of standardisation get their way".
Now, I don't support a standard, for reasons I've mentioned previously
(and which I'll touch on again in a sec). So what I'm doing now is
fishing for a contingency plan that I can support in case the standard
actually happens.
> It can't be a bad thing. It can only be a good thing.
It _can_ be a bad thing.
It opens up Perl to exploitation, attack, and subversion from sources
that currently leave it alone because of its 'mostly harmless' status.
It will also cull an extremely creative (albeit slightly whacko) fringe
element in the Perl community - the likes of which made Perl what it is
today. This would be as depressing (to me at least) as watching a 1000
year old castle be bulldozed to make room for a Macdonalds.
> Standards don't restrict growth.
True, they don't restrict growth. They do, however, restrict diversity,
freedom, liberty, culture, and a whole pile of other things that you may
or may not feel strongly about.
I, for one, hold such values in high regard. You, however, are free to
trash this culture's history, sell its soul, and go for the cash - if
that's what you want.
>> Ok, so multiple precendents have been set. Third-party compilers
>> clearly get abused.
>
>> How can we make sure this never happens to Perl?
Bart Lateur:
> By not making it an ANSI language. There: full circle.
:^) Yeah - that's my Plan A. But like I said above, I was fishing for
a Plan B.
Dan Sugalski:
> I don't much see the point, though, honestly. So someone extends perl with
> new keywords that aren't in the standard. Big deal.
It's a _huge_ deal. Just ask anyone who has to deliver content on the
web. It's an absolutely _ENORMOUS_ deal!
Microsoft's introduction of proprietary extensions has _crippled_ the
web. Internet Exploiter has probably set us back 4 years in the paltry
5 years that it has been in Microsoft's hands. We'd be cruising the web
with 2004 tech if it hadn't been for those bloody extensions.
Gak - how can you dismiss it so lightly!?!
Henry.
------------------------------
Date: Tue, 13 Jun 2000 11:12:38 +0930
From: Henry <htp@mac.com>
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <htp-A98E01.11123813062000@news.metropolis.net.au>
In article <slrn8kantb.fvk.dha@panix6.panix.com>, dha@panix.com (David
H. Adler) wrote:
>>> and by what objective standards have you determined that these
>>> people of yours arent 'doing pretty well' ?
>>
>> By the number and flavour of support questions that come my way.
>> Specifically, the frequency of painful questions such as "What's a
>> POD?", "Where do I type 'perldoc xxx'?" and "Where the $#@! is the
>> manual for this thing?"
>
> I'm sorry, but I cannot in any way find the last two of those even
> vaguely a problem with perl. That's a problem with users being so
> unfamiliar with their operating system and the tools thereof that they
> will not be able to do very much in attempting to program under it.
I've said it before (at least 3 times) and I'll say it again:
NO approachable documentation ships with the standard distribution of
Perl.
If it ain't there, it doesn't matter how good you OS skills are, you
won't find it.
Solution:
Ship approachable documentation with the standard distribution.
It _is_ a Perl problem. Specifically, it's a problem that only those
members of the Perl community who control the content of the standard
distribution can address.
Bart Lateur earlier pointed out a URL to a tutorial in this thread, and
then <http://www.perl.com/> as having links to more. I've had a chance
to check out many of those links and there's some good stuff out there.
"Out there" - that's the problem. It's not "In here" <looks at the
vacant area where a "documentation" folder should exist in his Perl
folder>.
Since the content already exists, why not set aside half a meg or so and
invite the authors of those tutorials to bundle up and pitch in???
Henry.
------------------------------
Date: Mon, 12 Jun 2000 21:51:36 -0400
From: "Dennis M. Parrott" <dparrott@ford.com>
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <394593A8.3BCBAB39@ford.com>
Jeepers, I sure hope that I got the who-said-what correct here...
I really don't wannabe flamebait!
Dan Sugalski wrote:
>
> Henry <htp@mac.com> wrote:
> > In article <Ek605.107069$hT2.427521@news1.rdc1.ct.home.com>, Dan
> > Sugalski <dan@tuatha.sidhe.org> wrote:
>
> doesn't need to get involved.
>
> > all they want to know is whether
> > or not the applications they develop _today_ will continue to work
> > _tomorrow_.
>
> And that's what a standard does. Without it there aren't any guarantees,
> since those of us who work in perl don't have anything besides past
> experience to work with. The closest thing perl's got to a standard is the
> test suite that comes with it, and despite its size there are still a lot
> of things it doesn't catch.
>
Actually Perl (and Open Source programs in general) come with a much
stronger
guarantee of future behavior than anything that is "standardized" --
Perl
comes with the **_SOURCE_**. I can make my application do EXACTLY what I
want
it to do (more or less) based on the version of Perl that I ship out
with my
product/project/program...
I would have to go verify this, but I seem to recall that Matlab ships
with a
version of Perl that gets installed with their programs. The Matlab app
uses
that specific version of Perl to do its thing. By using the particular
version
of Perl that they ship, they get a "guaranteed" behavior.
If the buzzword-spouting managers really had a clue about that which
they are
managing, the power of Open Source (including Perl) would be
crystal-clear and
they would be flocking there in droves... Alas, they are clueless by
definition.
Dennis Parrott
------------------------------
Date: 13 Jun 2000 03:10:27 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <8i48n3$1co$1@towncrier.cc.monash.edu.au>
Dan Sugalski <dan@tuatha.sidhe.org> writes:
>Larry Rosler <lr@hpl.hp.com> wrote:
>> In article <MSY%4.106864$hT2.426465@news1.rdc1.ct.home.com>,
>> dan@tuatha.sidhe.org says...
>>> Larry Rosler <lr@hpl.hp.com> wrote:
>>>
>>> > Perl is defined by a single official open source. It is a deterministic
>>> > computer program. The most arcane DWIMmery is deterministic, hence
>>> > definable. Without looking, I'll bet there isn't a single call to
>>> > rand(3C) anywhere in the perl source.
>>>
>>> And you'd probably be wrong. (Depending on what Configure found, of
>>> course) How else do you think the rand operator generates its data? :)
>> I meant called by the compiler, of course, not made available as a pass-
>> through from user Perl code. But I think you knew what I meant. :-)
>Ah, ya caught me. :) Can't think of a good place to stick in a use of
>rand, alas.
IHAPOT: "Quantum Superpositions and the First Virtue" at YAPC next week.
:-)
Damian
------------------------------
Date: 12 Jun 2000 20:15:23 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Length of an Array
Message-Id: <877lbu755g.fsf@limey.hpcc.uh.edu>
>> On Tue, 13 Jun 2000 00:47:09 GMT,
>> crazyCoder <crazycoder@my-deja.com> said:
> I'm trying to get the length of an array stored in a
> hash, is there a short-cut for this?
> I know that $#array will give the length of @array, I
> have something like this: %my_hash = (1 =>
> ["elem1","elem2","elem3"], 2 =>
> ["elem1","elem2","elem3","elem4","elem5"] );
> since I am creating %my_hash on the fly, I need to know
> the lengths of the array elements contained in it.
Hmmm, are you sure you need to know? You can expect perl
to do the right thing and auto-allocate as you go.
However, if you really want to find out how many entries
there are:
my %hash = (1 => ["elem1","elem2","elem3"],
2 => ["elem1","elem2","elem3","elem4","elem5"] );
my $arr_ref = $hash{2};
print @$arr_ref . "\n";
==> 5
Note the @ occurs in a scalar context.
hth
t
--
"Trying is the first step towards failure"
Homer Simpson
------------------------------
Date: Mon, 12 Jun 2000 18:14:21 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Length of an Array
Message-Id: <8i41rr$3dj$1@brokaw.wa.com>
crazyCoder <crazycoder@my-deja.com> wrote in message
news:8i40aa$vhi$1@nnrp1.deja.com...
> I'm trying to get the length of an array stored in a hash, is there a
> short-cut for this?
>
> I know that $#array will give the length of @array, I have something
> like this:
> %my_hash = (1 => ["elem1","elem2","elem3"],
> 2 => ["elem1","elem2","elem3","elem4","elem5"]
> );
>
> since I am creating %my_hash on the fly, I need to know the lengths of
> the array elements contained in it.
$length = @{$my_hash{$key}};
perldoc perlref
Lauren
------------------------------
Date: Tue, 13 Jun 2000 02:47:24 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Length of an Array
Message-Id: <skb85sc6h5117@corp.supernews.com>
crazyCoder (crazycoder@my-deja.com) wrote:
: I'm trying to get the length of an array stored in a hash, is there a
: short-cut for this?
:
: I know that $#array will give the length of @array,
No it won't.
: I have something like this:
:
: %my_hash = (1 => ["elem1","elem2","elem3"],
: 2 => ["elem1","elem2","elem3","elem4","elem5"]
: );
:
: since I am creating %my_hash on the fly, I need to know the lengths of
: the array elements contained in it.
$len1 = @{$myhash{1}};
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "Beauty and strength, leaping laughter and delicious
| languor, force and fire, are of us." - Liber AL II:20
------------------------------
Date: Mon, 12 Jun 2000 20:18:56 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Need to reload program after a sleep period
Message-Id: <Pine.GSO.4.10.10006122018130.18837-100000@user2.teleport.com>
On Mon, 12 Jun 2000, Jeff Bishop wrote:
> I have put an "if" command into my script saying for the program to
> sleep for 10 minutes if it is triggered to. At the end of that ten
> minutes, I need it to try running the script again from the start, and
> I don't know which command to use.
Are you sure that you don't want to use cron, at, or your system's
implementation of one of those? Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 13 Jun 2000 03:36:07 GMT
From: gelshocker@my-deja.com
Subject: newbie help: how to extract line by column position
Message-Id: <8i4a76$69c$1@nnrp1.deja.com>
Hi all!
I really need help here as I'm new to perl and have an immediate job on
hand:
I have an array where I need to extract bits of information by col no.
i.e.
for each line {
column position 1-30 into one scalar var;
column position 31-40 into another;
etc.
}
I have the whole file in an array, with each line as an element.
All the perl text I have on hand only tell me how to extract by pattern
matching. Currently, my text file has no specific pattern matching
possibilities - but if I can extract by col. position then that would
suffice.
I think the winscript equivalent is the 'mid' function (with use of
'trim')
Please help!
Cheers!
Jason
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 13 Jun 2000 04:00:04 GMT
From: kumar1@home.com (Prasanth A. Kumar)
Subject: Re: newbie help: how to extract line by column position
Message-Id: <m3r9a2s01n.fsf@C654771-a.frmt1.sfba.home.com>
gelshocker@my-deja.com writes:
> Hi all!
>
> I really need help here as I'm new to perl and have an immediate job on
> hand:
>
> I have an array where I need to extract bits of information by col no.
>
> i.e.
>
> for each line {
> column position 1-30 into one scalar var;
> column position 31-40 into another;
> etc.
> }
>
> I have the whole file in an array, with each line as an element.
>
> All the perl text I have on hand only tell me how to extract by pattern
> matching. Currently, my text file has no specific pattern matching
> possibilities - but if I can extract by col. position then that would
> suffice.
>
> I think the winscript equivalent is the 'mid' function (with use of
> 'trim')
<snip>
I think what you need is the 'substr' function by which you can
specify the offset and length into a scalar string to extract.
--
Prasanth Kumar
kumar1@home.com
------------------------------
Date: Tue, 13 Jun 2000 12:15:53 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: Perl is FAST!!!
Message-Id: <39459959.6669@modulus.com.au>
Andy wrote:
>
> In article <x7vgze8wh8.fsf@home.sysarch.com>, Uri Guttman
> <uri@sysarch.com> wrote:
[snip]
> Standby... (stay tuned).
>
While you're implementing Uri's improvements, you might also want to
have a look at "study", which only yields improvement when you apply
many regexes to a string.
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Tue, 13 Jun 2000 02:48:39 GMT
From: Andy <y-o-y@home.com>
Subject: Re: Perl is FAST!!!
Message-Id: <bih15.1107$fE2.18264@news1.rdc2.pa.home.com>
In article <39459959.6669@modulus.com.au>, phill@modulus.com.au wrote:
> Andy wrote:
> >
> > In article <x7vgze8wh8.fsf@home.sysarch.com>, Uri Guttman
> > <uri@sysarch.com> wrote:
> [snip]
> > Standby... (stay tuned).
> >
> While you're implementing Uri's improvements, you might also want to
> have a look at "study", which only yields improvement when you apply
> many regexes to a string.
Agreed.
TMTOWTDI, tho.
All you experts have to settle down somewhat.
I knew when I posted my regex's, they weren't perfect. But WTF??? It
worked.
I didn't post to ask for help. I just wanted to share my "sorry-assed"
success.
:-P
"A diplomat is a person who can tell you
to 'Go To Hell' in such a way that you
actually look forward to the trip."
--Anonymous
------------------------------
Date: Tue, 13 Jun 2000 03:09:00 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl is FAST!!!
Message-Id: <x7og568egl.fsf@home.sysarch.com>
>>>>> "PH" == Peter Hill <phill@modulus.com.au> writes:
PH> While you're implementing Uri's improvements, you might also want to
PH> have a look at "study", which only yields improvement when you apply
PH> many regexes to a string.
study is not what is once was. the newer regex stuff works very fast
without study. and the docs say this:
Takes extra time to study SCALAR (C<$_> if unspecified) in
anticipation of doing many pattern matches on the string before
it is next modified.
note the last word. so study wouldn't help much here as all the ops
were s/// which modifies the text, of course. and doing a study between
each s/// will almost surely lose.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 12 Jun 2000 20:36:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perldebug - jump command?
Message-Id: <Pine.GSO.4.10.10006122033480.18837-100000@user2.teleport.com>
On Mon, 12 Jun 2000 steveeq1@earthlink.net wrote:
> I am using the Perl Debugger. I checked the man pages for this, but
> haven't been able to come up with much. Anyway, if I am at say, line
> 6, is there a way to jump up the execution to line 3?
You want goto? :-)
It's rare that something can be declared to be outright impossible in
Perl, but I'm pretty sure that what you're asking for isn't possible in
general. But if you put a label on line six, you might be able to....
Seriously, you may want to write some lines like this:
if ($DB::Skip_these_lines) {
&whatever;
&do_something(@args);
}
...then you can set or clear that variable from within the debugger. Good
luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 12 Jun 2000 22:43:49 -0400
From: "Dennis M. Parrott" <dparrott@ford.com>
Subject: Re: print pdf
Message-Id: <39459FE5.8635B20F@ford.com>
Todd Anderson wrote:
>
> Dear Sirs,
> Does anybody know the perl command for printing a pdf (portable document
> file) file, the way you might print an html file? Can it even be done?
> Thanks in advance for your help.
>
> SNIP!
The answer is OS-dependant. On Windows, you can do some magic to access
the underlying mechanisms in Adobe Acrobat and make the PDF print.
On Unix, VMS, etc., the answer is "probably not" unless the Adobe SDKs
have a way.
Many of the "freeware" PDF tools allow you to create PDFs or manipulate
them in strange and (possibly) creative ways. I do not recall ever
seeing
one that would print them for you.
------------------------------
Date: Tue, 13 Jun 2000 02:06:00 GMT
From: Howard Jow <ppith@my-deja.com>
Subject: regular expression help (matching exactly n times)
Message-Id: <8i44u1$2mp$1@nnrp1.deja.com>
Okay, I've had the basics of regular expressions down for a while and
it's time to move on to newer frontiers. I am looking into {n} and
{n,n} as well as (?some symbol pattern) regular expressions. I've been
having problems trying to get the following regular expression to print
out the correct answer:
$string = "abddba";
if($string =~ m/([\w]{5}?)/) { # match exactly 5 characters (non-greedy)
print "we matched exactly 5 characters\n";
}
else {
print "we matched less than 5 characters or more than 5
characters\n";
}
It keeps printing "we matched exactly 5 characters". What am I doing
wrong? I am trying to learn from the Perl documentation on regular
expressions. If I make $string only have four characters, then the else
gets executed. I am guessing for some reason the regular expression is
returning true because it's matching at least five characters even
though I have six. Can someone point me in the right direction?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 13 Jun 2000 02:45:20 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: regular expression help (matching exactly n times)
Message-Id: <4fh15.95$xB1.6231@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8i44u1$2mp$1@nnrp1.deja.com>,
Howard Jow <ppith@my-deja.com> writes:
> It keeps printing "we matched exactly 5 characters". What am I doing
> wrong? I am trying to learn from the Perl documentation on regular
> expressions. If I make $string only have four characters, then the else
> gets executed. I am guessing for some reason the regular expression is
> returning true because it's matching at least five characters even
> though I have six.
*boggle* When I learned english and math, anyways, six is considered "at least
five". If you want to match exactly 5 characters in the entire string, then
say so:
$string=~/^\w{5}$/;
This will fail on "abddba" but not on "abbad".
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Tue, 13 Jun 2000 12:49:30 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Re: regular expression help (matching exactly n times)
Message-Id: <3945A13A.58B3@modulus.com.au>
Howard Jow wrote:
>
> Okay, I've had the basics of regular expressions down for a while and
> it's time to move on to newer frontiers. I am looking into {n} and
> {n,n} as well as (?some symbol pattern) regular expressions. I've been
> having problems trying to get the following regular expression to print
> out the correct answer:
>
> $string = "abddba";
>
> if($string =~ m/([\w]{5}?)/) { # match exactly 5 characters (non-greedy)
> print "we matched exactly 5 characters\n";
> }
> else {
> print "we matched less than 5 characters or more than 5
> characters\n";
> }
>
> It keeps printing "we matched exactly 5 characters". What am I doing
> wrong? I am trying to learn from the Perl documentation on regular
> expressions. If I make $string only have four characters, then the else
> gets executed. I am guessing for some reason the regular expression is
> returning true because it's matching at least five characters even
> though I have six. Can someone point me in the right direction?
>
if($string =~ m/([\w]{5}?)/)
can be written as
if($string =~ m/\w{5}/)
Each of these version, in the context you're using, is equivalent.
Where I think you're having difficulty is, however, in getting the right
mental model in your bonce. Insteda of
print "we matched exactly 5 characters\n";
try
print "At some point within the string $string, there is at least one
character sequence which can be characterised by the regular expression
/\w{5}/.\n";
For clarity, put back the capturing quotes:
if($string =~ m/(\w{5})/)
and change the message to:
print "At some point within the string $string, there is at least one
character sequence which can be characterised by the regular expression
/\w{5}/. The first of these is $1\n";
hth
--
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/
------------------------------
Date: Tue, 13 Jun 2000 03:10:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: regular expression help (matching exactly n times)
Message-Id: <3945A522.328875BB@rochester.rr.com>
Howard Jow wrote:
>
> Okay, I've had the basics of regular expressions down for a while and
> it's time to move on to newer frontiers. I am looking into {n} and
> {n,n} as well as (?some symbol pattern) regular expressions. I've been
> having problems trying to get the following regular expression to print
> out the correct answer:
>
> $string = "abddba";
>
> if($string =~ m/([\w]{5}?)/) { # match exactly 5 characters (non-greedy)
> print "we matched exactly 5 characters\n";
> }
> else {
> print "we matched less than 5 characters or more than 5
> characters\n";
> }
>
> It keeps printing "we matched exactly 5 characters". What am I doing
> wrong? I am trying to learn from the Perl documentation on regular
In your re above, there is no point in specifying the ? after the {5},
since it is going to match exactly five characters regardless of whether
it is "greedy" or "non-greedy" -- the ? is needed only for cases where a
variable number of pattern repetitions might be matched, like \w{5,6}?
. The reason your pattern is successfully matching your six-character
string is because you specified nothing to restrict the match to strings
with exactly five characters. So your pattern will match both:
@#$abcde%^&
)sdflkjsdflkj(
and any other string that has at least five word characters in a row
anywhere within it. You could specify anchors for your pattern like:
^\w{5}$
if you want to match only strings that consist of exactly five word
characters. Note that in your example, the parens and the square
brackets are superfluous.
> expressions. If I make $string only have four characters, then the else
> gets executed. I am guessing for some reason the regular expression is
> returning true because it's matching at least five characters even
> though I have six. Can someone point me in the right direction?
...
--
Bob Walton
------------------------------
Date: Tue, 13 Jun 2000 03:28:40 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: regular expression help (matching exactly n times)
Message-Id: <3945aa68.3bc$3e3@news.op.net>
In article <8i44u1$2mp$1@nnrp1.deja.com>,
Howard Jow <ppith@my-deja.com> wrote:
>$string = "abddba";
>if($string =~ m/([\w]{5}?)/) { # match exactly 5 characters (non-greedy)
> print "we matched exactly 5 characters\n";
>}
``Hi, you need to show some ID.''
``Here is my driver's license.''
``I'm sorry, but you have to be 21 to drink.''
``But I'm 35!''
``As I said, you need to be 21 to drink, and you're not 21.''
------------------------------
Date: Tue, 13 Jun 2000 03:36:57 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Strange permission problems with ActivePerl 613
Message-Id: <3945AB4D.F7480AEA@rochester.rr.com>
James Cameron wrote:
>
> OS: Windows NT 4.0 SP 4 or lower
>
> Summary: Receiving permission denied error messages when using 'rmdir'
> after 'opendir' with the latest release.
>
> Code: This code fails with permission denied in version 613 but works
> fine in 522 and every version of Perl I've tried on Unix
> machines.
Well, it is stated that AS Perl Build 613 is only for NT service pack 5
or higher (from Windows install notes):
Requirements
Hardware
recommended 25MB hard disk space for typical install
Operating System
Windows 2000
no extra requirements
Windows NT
service pack 5+
...
That's why we don't use build 613 -- not all our NT systems are at
service pack 5 or above.
...
> -James Cameron
> President, WebEvent, Inc.
> http://www.WebEvent.com/
--
Bob Walton
------------------------------
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 3337
**************************************