Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to match characters in different locations within string

1 view
Skip to first unread message

Jack

unread,
May 21, 2006, 1:45:18 AM5/21/06
to
Hello..

I have:
$temp = 'with 855 and 990';

How do I return true or false (ideally through a regular expression)
the existence of both 'with' and 'and' inside the string ? I have
messed around with it for a while and cant figure it out, assistance
would be great. Also how does it change if I test for 3 particular
words as opposed to 2..?

Thank you,

Jack

use...@davidfilmer.com

unread,
May 21, 2006, 2:26:20 AM5/21/06
to
Jack wrote:

> How do I return true or false (ideally through a regular expression)
> the existence of both 'with' and 'and' inside the string ?

Hello, welcome to Perl and to CLPMIsc. As you seem new to both, you
are probably not aware that this particular newsgroup has posting
guidelines; you may find these at
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

> I have messed around with it for a while and cant figure it out

Are you just guessing at a solution, or have you read the docs for
regular expressions (perldoc perlre)?

> assistance would be great.

Sure, we'll be glad to help you fix you code (but you probably won't
find someone here to write it for you). Just show us what you've done
so far. This gives us a frame of reference to what level of
understanding you have so we can adapt our answer accordingly.

--
http://DavidFilmer.com

Gunnar Hjalmarsson

unread,
May 21, 2006, 2:57:48 AM5/21/06
to
Jack wrote:
>
> $temp = 'with 855 and 990';
>
> How do I return true or false (ideally through a regular expression)
> the existence of both 'with' and 'and' inside the string ?

sub isWords {
local $_ = $_[0];
/\bwith\b/ && /\band\b/ ? 1 : 0;
}

print "True\n" if isWords($temp);

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Dr.Ruud

unread,
May 21, 2006, 5:01:51 AM5/21/06
to
Gunnar Hjalmarsson schreef:

> sub isWords {
> local $_ = $_[0];

That is a copy, but I have often wondered why a localized $_ alias of
$_[0] isn't implicit for a sub.

Is there a clear way to make $_ a localized alias of $_[0]?
With "clear" I mean much clearer than an enclosing "for ( $_[0] ){}"
would.

--
Affijn, Ruud

"Gewoon is een tijger."


Brian McCauley

unread,
May 21, 2006, 7:17:51 AM5/21/06
to

Gunnar Hjalmarsson wrote:
> Jack wrote:
> >
> > $temp = 'with 855 and 990';
> >
> > How do I return true or false (ideally through a regular expression)
> > the existence of both 'with' and 'and' inside the string ?
>
> sub isWords {
> local $_ = $_[0];

This is a bug waiting to happen.

If isWords() is called in a contest where $_ happens to be alaised to
an element of a tied aggregate then nasty things happen when you do
local($_).

Always use for() or local(*_) to localise changes to $_.

Brian McCauley

unread,
May 21, 2006, 7:20:33 AM5/21/06
to

Dr.Ruud wrote:
> Is there a clear way to make $_ a localized alias of $_[0]?
> With "clear" I mean much clearer than an enclosing "for ( $_[0] ){}"
> would.

I find that perfectly clear. It's just a mindset thing I guess.

Gunnar Hjalmarsson

unread,
May 21, 2006, 8:07:47 AM5/21/06
to
Brian McCauley wrote:

> Gunnar Hjalmarsson wrote:
>>
>> sub isWords {
>> local $_ = $_[0];
>
> This is a bug waiting to happen.
>
> If isWords() is called in a contest where $_ happens to be alaised to
> an element of a tied aggregate then nasty things happen when you do
> local($_).

I don't understand that. This code:

my $temp = 'with 855 and 990';

sub isWords {
local $_ = $_[0];

/\bwith\b/ && /\band\b/ ? 1 : 0;
}

for ('hello') {


print "True\n" if isWords($temp);

print "$_\n";
}

outputs:
True
hello

as I would have expected.

> Always use for() or local(*_) to localise changes to $_.

If I exchange 'local $_' in the above example for 'local *_', the $_
variable is empty within the isWords() function.

Dr.Ruud

unread,
May 21, 2006, 8:00:50 AM5/21/06
to
Brian McCauley schreef:
> Dr.Ruud:

Other example:

for my $i (0 .. $#subst)
{
for my $s ($_ )
{
for my $a ($subst[$i])
{
for my $f ($a->[0])
{
for my $t ($a->[1])
{
...
} } } } }


which makes me think about

for my $i (0 .. $#subst)
{
alias ($s, $a, $f, $t) ($_, $subst[$i], $a->[0], $a->[1])
{
...

Jack

unread,
May 21, 2006, 10:47:16 AM5/21/06
to

use...@DavidFilmer.com wrote:
> Jack wrote:
>
> > How do I return true or false (ideally through a regular expression)
> > the existence of both 'with' and 'and' inside the string ?
>
> Hello, welcome to Perl and to CLPMIsc. As you seem new to both, you
> are probably not aware that this particular newsgroup has posting
> guidelines; you may find these at
> http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
> > I have messed around with it for a while and cant figure it out
>
> Are you just guessing at a solution, or have you read the docs for
> regular expressions (perldoc perlre)?
>

have I read the docs ? Of course I have - why dont you tell me how with
a reg. expression to accomplish this - obviously you cant, nor could I
for hours. I think maybe you should read the docs and answer the
question. How about it.

Mumia W.

unread,
May 21, 2006, 3:26:23 PM5/21/06
to
Dr.Ruud wrote:
> Gunnar Hjalmarsson schreef:
>
>> sub isWords {
>> local $_ = $_[0];
>
> That is a copy, but I have often wondered why a localized $_ alias of
> $_[0] isn't implicit for a sub.
>
> Is there a clear way to make $_ a localized alias of $_[0]?
> With "clear" I mean much clearer than an enclosing "for ( $_[0] ){}"
> would.
>

There is no way, but you can use a local reference to the array:

local $_ = \@_;
print $_->[0];

That's the closest I can find to what you want.

Ben Morrow

unread,
May 21, 2006, 11:05:53 AM5/21/06
to

Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:

> Brian McCauley wrote:
> > Gunnar Hjalmarsson wrote:
> >>
> >> sub isWords {
> >> local $_ = $_[0];
> >
> > This is a bug waiting to happen.
> >
> > If isWords() is called in a contest where $_ happens to be alaised to
> > an element of a tied aggregate then nasty things happen when you do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> > local($_).
>
> I don't understand that. This code:

doesn't test what Brian was talking about. :) I can't remember the
details, but if you just localize a tied $_ there is some confusion
about the tie magic (IIRC it is not restored correctly at the end of the
scope, but I may be wrong).

> > Always use for() or local(*_) to localise changes to $_.
>
> If I exchange 'local $_' in the above example for 'local *_', the $_
> variable is empty within the isWords() function.

... so you need to replace

local $_ = ...;

with

local *_;
$_ = ...;

or

for (...) {

:)

Ben

--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ benm...@tiscali.co.uk ~ Jorge Luis Borges, 'The Babylon Lottery'

Dr.Ruud

unread,
May 21, 2006, 8:00:38 PM5/21/06
to
Brian McCauley schreef:
> Dr.Ruud:

OK. After "use Data::Alias" one can do:

alias local $_ = $_[0];

or alternatively:

alias local ($_) = @_;

but I haven't investigated "it-tied" yet.

Dr.Ruud

unread,
May 21, 2006, 8:33:35 PM5/21/06
to
Mumia W. schreef:
> Dr.Ruud:
>> Gunnar Hjalmarsson:


Well, I might want a localized $_ as alias of $_[0] for every sub. Are
there any good reasons against it?


But also see the line with the arrow below.

#!/usr/bin/perl
use strict ;
use warnings ;

use Data::Alias ;

sub demo
{
print "demo-0: \$_<$_>, \@_<@_>\n" ;

alias local $_ = $_[0]; # <----

print "demo-1: \$_<$_>, \@_<@_>\n" ;

$_ = '3rd' ;

print "demo-2: \$_<$_>, \@_<@_>\n" ;
}

my $x ;
print "\n" ;

$_ = '1st' ;
$x = '2nd' ;
print "\$_<$_>\n" ;
print "\$x<$x>\n" ;

demo $x, 'y', 'z' ;
print "\$x<$x>\n" ;
print "\$_<$_>\n" ;
print "\n" ;

demo $_, 8, 9 ;
print "\$_<$_>\n" ;
print "\n" ;
__END__


That prints:

$_<1st>
$x<2nd>
demo-0: $_<1st>, @_<2nd y z>
demo-1: $_<2nd>, @_<2nd y z>
demo-2: $_<3rd>, @_<3rd y z>
$x<3rd>
$_<1st>

demo-0: $_<1st>, @_<1st 8 9>
demo-1: $_<1st>, @_<1st 8 9>
demo-2: $_<3rd>, @_<3rd 8 9>
$_<3rd>

Looks to me to behave as should be expected.

Lionel

unread,
May 21, 2006, 8:48:06 PM5/21/06
to
Jack wrote:
> use...@DavidFilmer.com wrote:
>> Jack wrote:
>>
>>> How do I return true or false (ideally through a regular expression)
>>> the existence of both 'with' and 'and' inside the string ?
>> Hello, welcome to Perl and to CLPMIsc. As you seem new to both, you
>> are probably not aware that this particular newsgroup has posting
>> guidelines; you may find these at
>> http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>>
>>> I have messed around with it for a while and cant figure it out
>> Are you just guessing at a solution, or have you read the docs for
>> regular expressions (perldoc perlre)?
>>
>
> have I read the docs ? Of course I have - why dont you tell me how with
> a reg. expression to accomplish this - obviously you cant, nor could I
> for hours. I think maybe you should read the docs and answer the
> question. How about it.

Ahhhh, although I object to posts with the tone of the previous one, as
the OP asking for a solution you should be a little more grateful and
polite. No one HAS to give you a solution, so any answers are a favour
and you should see them that way.

Lionel.

John W. Krahn

unread,
May 21, 2006, 11:00:06 PM5/21/06
to
Jack wrote:
>
> I have:
> $temp = 'with 855 and 990';
>
> How do I return true or false (ideally through a regular expression)
> the existence of both 'with' and 'and' inside the string ? I have
> messed around with it for a while and cant figure it out, assistance
> would be great.

$ perl -le'
$temp = q[with 855 and 990];
print $temp =~ /(?=.*\bwith\b)(?=.*\band\b)/ ? q[TRUE] : q[FALSE];
'
TRUE

> Also how does it change if I test for 3 particular
> words as opposed to 2..?

$ perl -le'
$temp = q[with 855 and 990];
print $temp =~ /(?=.*\bwith\b)(?=.*\band\b)(?=.*\b855\b)/ ? q[TRUE] : q[FALSE];
'
TRUE

John
--
use Perl;
program
fulfillment

Ben Morrow

unread,
May 21, 2006, 9:25:18 PM5/21/06
to

Quoth "Dr.Ruud" <rvtol...@isolution.nl>:

>
> Well, I might want a localized $_ as alias of $_[0] for every sub. Are
> there any good reasons against it?

Subs that want to take $_ as a default value.

--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC benm...@tiscali.co.uk

Gunnar Hjalmarsson

unread,
May 22, 2006, 5:30:45 AM5/22/06
to
Ben Morrow wrote:
> Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:
>>Brian McCauley wrote:
>>>Gunnar Hjalmarsson wrote:
>>>>
>>>> sub isWords {
>>>> local $_ = $_[0];
>>>
>>>This is a bug waiting to happen.
>>>
>>>If isWords() is called in a contest where $_ happens to be alaised to
>>>an element of a tied aggregate then nasty things happen when you do
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>local($_).
>>
>>I don't understand that. This code:
>
> doesn't test what Brian was talking about. :)

I see. Guess it's the expression "tied aggregate" I don't understand, then.

If someone could post an applicable example, it would be much appreciated.

>>>Always use for() or local(*_) to localise changes to $_.
>>
>>If I exchange 'local $_' in the above example for 'local *_', the $_
>>variable is empty within the isWords() function.
>
> ... so you need to replace
>
> local $_ = ...;
>
> with
>
> local *_;
> $_ = ...;

Well, that seems not to be enough in this case. Since I want to copy
$_[0] to $_, I also need a temporary variable:

sub isWords {
my $tmp = $_[0];
local *_;
$_ = $tmp;


/\bwith\b/ && /\band\b/ ? 1 : 0;
}

> or
>
> for (...) {

sub isWords {


for ( $_[0] ) {

return 1 if /\bwith\b/ && /\band\b/;
}
}

Less clumsy, it seems...

Dr.Ruud

unread,
May 22, 2006, 5:42:33 AM5/22/06
to
Ben Morrow schreef:
> Dr.Ruud:

>> Well, I might want a localized $_ as alias of $_[0] for every sub.
>> Are there any good reasons against it?
>
> Subs that want to take $_ as a default value.

An exception is obviously made for a call without arguments, because
then there would not be a $_[0].

That leaves subs where $_ is the default for another argument but the
first. Maybe an attribute could be used for those.

sub my_split : respect_it
{
@_ > 1 and alias local $_ = $_[1] ;
...

Ben Morrow

unread,
May 22, 2006, 10:44:57 AM5/22/06
to

Quoth "Dr.Ruud" <rvtol...@isolution.nl>:

> Ben Morrow schreef:
> > Dr.Ruud:
>
> >> Well, I might want a localized $_ as alias of $_[0] for every sub.
> >> Are there any good reasons against it?
> >
> > Subs that want to take $_ as a default value.
>
> An exception is obviously made for a call without arguments, because
> then there would not be a $_[0].
>
> That leaves subs where $_ is the default for another argument but the
> first. Maybe an attribute could be used for those.

You're not getting it. The calling conventions *can't* be changed now,
because it breaks back-compatibility. c.f. Perl6.

Ben

--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
benm...@tiscali.co.uk

Ben Morrow

unread,
May 22, 2006, 10:50:28 AM5/22/06
to

Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:

> Ben Morrow wrote:
> > Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:
> >>Brian McCauley wrote:
> >>>Gunnar Hjalmarsson wrote:
> >>>>
> >>>> sub isWords {
> >>>> local $_ = $_[0];
> >>>
> >>>This is a bug waiting to happen.
> >>>
> >>>If isWords() is called in a contest where $_ happens to be alaised to
> >>>an element of a tied aggregate then nasty things happen when you do
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>>local($_).
> >>
> >>I don't understand that. This code:
> >
> > doesn't test what Brian was talking about. :)
>
> I see. Guess it's the expression "tied aggregate" I don't understand, then.

Brian means when $_ is aliased (by for, or whatever) to an element of a
tied array or hash.

> >>If I exchange 'local $_' in the above example for 'local *_', the $_
> >>variable is empty within the isWords() function.
> >
> > ... so you need to replace
> >
> > local $_ = ...;
> >
> > with
> >
> > local *_;
> > $_ = ...;
>
> Well, that seems not to be enough in this case. Since I want to copy
> $_[0] to $_, I also need a temporary variable:
>
> sub isWords {
> my $tmp = $_[0];
> local *_;
> $_ = $tmp;
> /\bwith\b/ && /\band\b/ ? 1 : 0;
> }

Whoops! Didn't spot that... try

local *_ = \$_[0];

...although I'd not be certain this actually localises all of *_. Brian,
can you help me here?

Dr.Ruud

unread,
May 22, 2006, 1:25:14 PM5/22/06
to
Ben Morrow schreef:
> Dr.Ruud:
>> Ben Morrow:
>>> Dr.Ruud:

>>>> Well, I might want a localized $_ as alias of $_[0] for every sub.
>>>> Are there any good reasons against it?
>>>
>>> Subs that want to take $_ as a default value.
>>
>> An exception is obviously made for a call without arguments, because
>> then there would not be a $_[0].
>>
>> That leaves subs where $_ is the default for another argument but the
>> first. Maybe an attribute could be used for those.
>
> You're not getting it.

Or bluntly ignoring it.


> The calling conventions *can't* be changed now,
> because it breaks back-compatibility. c.f. Perl6.

Can calling conventions be changed for one file only?
With something like: use subs::localize::it.

Brian McCauley

unread,
May 23, 2006, 7:49:27 AM5/23/06
to
Gunnar Hjalmarsson wrote:
> Brian McCauley wrote:
> > Gunnar Hjalmarsson wrote:
> >>
> >> sub isWords {
> >> local $_ = $_[0];
> >
> > This is a bug waiting to happen.
> >
> > If isWords() is called in a contest where $_ happens to be alaised to
> > an element of a tied aggregate then nasty things happen when you do
> > local($_).
>
> I don't understand that. This code:

[without any tied aggregates]

> [works] as I would have expected.

Yes, but if you try an example _with_ a tied aggregate odd things
happen.

http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/85eb2aa2c9688c56/4ade11e9618f7b14

> > Always use for() or local(*_) to localise changes to $_.
>
> If I exchange 'local $_' in the above example for 'local *_', the $_
> variable is empty within the isWords() function.

Note to assign the scalar slot of *_ you need to have a scalar ref
expression on the RHS of the assignment. So it would read.

local *_=\$_[0];

Or

local *_=\shift;

I still prefer

for (shift) {

Brian McCauley

unread,
May 23, 2006, 7:54:48 AM5/23/06
to

Ben Morrow wrote:

> local *_ = \$_[0];
>
> ...although I'd not be certain this actually localises all of *_. Brian,
> can you help me here?

Experiment show that is does not on 5.8.7.

My recollection is that this may not always have been the case, but I
don't have an earlier Perl to hand to check this.

Ben Morrow

unread,
May 23, 2006, 10:40:17 AM5/23/06
to

Quoth "Dr.Ruud" <rvtol...@isolution.nl>:
> Ben Morrow schreef:
> >
> > You're not getting it.
>
> Or bluntly ignoring it.

:)

> > The calling conventions *can't* be changed now,
> > because it breaks back-compatibility. c.f. Perl6.
>
> Can calling conventions be changed for one file only?
> With something like: use subs::localize::it.

I guess they could. Indeed, if you *really* want to you could write
yourself a source filter to do just that; or set up an attribute
:implicit (or whatever) which wraps the sub...

Ben

--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] benm...@tiscali.co.uk

Gunnar Hjalmarsson

unread,
May 24, 2006, 1:29:51 PM5/24/06
to
Brian McCauley wrote:
> Gunnar Hjalmarsson wrote:
>>Brian McCauley wrote:
>>>Always use for() or local(*_) to localise changes to $_.
>>
>>If I exchange 'local $_' in the above example for 'local *_', the $_
>>variable is empty within the isWords() function.
>
> Note to assign the scalar slot of *_ you need to have a scalar ref
> expression on the RHS of the assignment. So it would read.
>
> local *_=\$_[0];
>
> Or
>
> local *_=\shift;

Aha, the RHS ref made a difference. Thanks both Brian and Ben!

To me, this notation is anything but intuitive. Is is documented anywhere?

Gunnar Hjalmarsson

unread,
May 24, 2006, 4:43:28 PM5/24/06
to
Gunnar Hjalmarsson wrote:
> Brian McCauley wrote:
>> Note to assign the scalar slot of *_ you need to have a scalar ref
>> expression on the RHS of the assignment. So it would read.
>>
>> local *_=\$_[0];
>>
>> Or
>> local *_=\shift;
>
> Aha, the RHS ref made a difference. Thanks both Brian and Ben!
>
> To me, this notation is anything but intuitive. Is is documented anywhere?

Seems as if it can be derived from perldoc perlsub...

Ben Morrow

unread,
May 24, 2006, 4:33:51 PM5/24/06
to

Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:

> Brian McCauley wrote:
> > Gunnar Hjalmarsson wrote:
> >>Brian McCauley wrote:
> >>>Always use for() or local(*_) to localise changes to $_.
> >>
> >>If I exchange 'local $_' in the above example for 'local *_', the $_
> >>variable is empty within the isWords() function.
> >
> > Note to assign the scalar slot of *_ you need to have a scalar ref
> > expression on the RHS of the assignment. So it would read.
> >
> > local *_=\$_[0];
> >
> > Or
> >
> > local *_=\shift;
>
> Aha, the RHS ref made a difference. Thanks both Brian and Ben!
>
> To me, this notation is anything but intuitive. Is is documented anywhere?

"Symbol Tables" in perlmod; which is referred to in "Typeglobs and
Filehandles" in perldata; which is referred to (somewhat obliquely) in
perlref; which is where I started looking :). Not therefore perhaps the
most obvious place...

If you are in a position to, I think it's well worth reading *all* the
Perl documentation, carefully, at least once. There's a lot of stuff
in there in... not-so-obvious places.

Ben

--
All persons, living or dead, are entirely coincidental.
benm...@tiscali.co.uk Kurt Vonnegut

Gunnar Hjalmarsson

unread,
May 24, 2006, 8:20:49 PM5/24/06
to
Ben Morrow wrote:
> Quoth Gunnar Hjalmarsson <nor...@gunnar.cc>:
>>Brian McCauley wrote:
>>>Note to assign the scalar slot of *_ you need to have a scalar ref
>>>expression on the RHS of the assignment. So it would read.
>>>
>>>local *_=\$_[0];
>>>
>>>Or
>>>
>>>local *_=\shift;
>>
>>Aha, the RHS ref made a difference. Thanks both Brian and Ben!
>>
>>To me, this notation is anything but intuitive. Is is documented anywhere?
>
> "Symbol Tables" in perlmod; which is referred to in "Typeglobs and
> Filehandles" in perldata; which is referred to (somewhat obliquely) in
> perlref; which is where I started looking :). Not therefore perhaps the
> most obvious place...

I see. The typeglob stuff. Something I've tried to avoid so far.

> If you are in a position to, I think it's well worth reading *all* the
> Perl documentation, carefully, at least once. There's a lot of stuff
> in there in... not-so-obvious places.

Maybe I will do that some day, when I feel desperate enough. ;-)

Thanks again.

Jack

unread,
May 25, 2006, 11:02:05 PM5/25/06
to
Thank you kindly. What does the \b do in the regular expression ??

Jürgen Exner

unread,
May 25, 2006, 11:14:08 PM5/25/06
to
Jack wrote:
> Thank you kindly.

Whom and for what?
Please quote appropriate context -as has been customary for two decades-
such that people have a chance to know what you are talking about.

> what does the \b do in the regular expression ??

Did you check the documentation? From "perldoc perlre":
Perl defines the following zero-width assertions:
\b Match a word boundary

jue


Tad McClellan

unread,
May 25, 2006, 11:38:50 PM5/25/06
to
Jack <jack_p...@yahoo.com> wrote:

> Thank you kindly.


Thank who for what?

Please quote some context in followups like everybody else does.


> What does the \b do in the regular expression ??


Perl's regular expressions are documented in:

perldoc perlre

Wasn't it you who said this recently:

j> have I read the docs ? Of course I have - why dont you tell me how with
j> a reg. expression to accomplish this - obviously you cant, nor could I
j> for hours. I think maybe you should read the docs and answer the
j> question.

??


Hmmmm.


--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas

Jack

unread,
May 30, 2006, 9:55:34 PM5/30/06
to

Hey Tad, or I should say hey Pal, its not in these docs:
www.troubleshooters.com/codecorn/littperl/perlreg.htm

Why dont you answer the question instead of being a smart ass

Scott Bryce

unread,
May 30, 2006, 10:41:35 PM5/30/06
to
Jack wrote:

> Hey Tad, or I should say hey Pal,

Not if you want to get help here.

That isn't the docs. Try here:

http://perldoc.perl.org/perlre.html


> Why dont you answer the question instead of being a smart ass

Another Perl noob begging to be killfiled. Really, acting in an immature
manner will not get you the kind of help you are looking for. Tad gave
you a perfectly good answer to your question. Insulting him because you
didn't understand the answer will get you nowhere.

Jürgen Exner

unread,
May 30, 2006, 11:40:42 PM5/30/06
to
Jack wrote:

> Tad McClellan wrote:
>> Perl's regular expressions are documented in:
>>
>> perldoc perlre
>
> Hey Tad, or I should say hey Pal, its not in these docs:
> www.troubleshooters.com/codecorn/littperl/perlreg.htm

No idea what those "docs" are, but they are not Perl docs. As the author
claims himself 4 times in the first two paragraphs he is talking about PERL,
not about Perl or perl. Other examples of the author's great wisdom:

Complex string comparisons
$string =~ m/sought_text/;
[...]
Complex string replacements
$string =~ tr/originaltext/newtext/;

Indeed, if the author considers the first example to be complex and uses REs
for textual comparison instead of index() and doesn't know that tr()
operates on neither REs nor text but on lists of characters, then I surmise
that indeed he is talking about something but not about Perl.

> Why dont you answer the question instead of being a smart ass

Why don't you read the Perl docs as suggest instead of looking at some
documentation for some obscure PERL.

jue


Uri Guttman

unread,
May 31, 2006, 1:42:04 AM5/31/06
to
>>>>> "J" == Jack <jack_p...@yahoo.com> writes:


J> Hey Tad, or I should say hey Pal, its not in these docs:
J> www.troubleshooters.com/codecorn/littperl/perlreg.htm

wow, that is one of the worst perl tutes i have seen in a while. i make
a painful hobby of reading them. you are such a winner for thinking that
is a useful web page. more power to you and i hope you get a job coding
in python!

J> Why dont you answer the question instead of being a smart ass

sorry to inform you but tad IS smart and sometimes an ass so you are
correct!! why don't you ask the author of your perl tutorial for help? i
am sure he is not smart and also not an ass as he is so willing to help
newbies with PERL.

have a good coding life,

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

Uri Guttman

unread,
May 31, 2006, 1:48:58 AM5/31/06
to
>>>>> "J" == Jack <jack_p...@yahoo.com> writes:
J> www.troubleshooters.com/codecorn/littperl/perlreg.htm

this snippet says everything i want to say about that tutorial:

my($blankString) = " ";
$blankString = $blankString . $blankString . $blankString . $blankString;
$blankString = $blankString . $blankString . $blankString . $blankString;

you can't get better code than that. yes, this site is so much better
than the perl docs. everyone must read and obey its coding ideas and
style!

Jürgen Exner

unread,
May 31, 2006, 2:11:06 AM5/31/06
to
Uri Guttman wrote:
>>>>>> "J" == Jack <jack_p...@yahoo.com> writes:
>> www.troubleshooters.com/codecorn/littperl/perlreg.htm
[...]

> you can't get better code than that.

Oh yes, you can. The author has many more ideas ;-)

> yes, this site is so much better
> than the perl docs. everyone must read and obey its coding ideas and
> style!

Another highlight:
$string =~ tr/Bill Clinton/Al Gore/; #replace the president with the
vice president
Funny, I've never heard of a vice president named 'Al or leeee' but that's
probably just me. Or maybe it's a Romulan or Klingon VP.

Also worth reading is the section about 'Resolving Doubledots in A
Filepath'.
Obviously the author not only doesn't about the module that does the task
correctly, but he is also oblivious to the fact that /foo/bar/link/.. may
not point to /foo/bar at all.

Or this one:
Many situations can be done either with groups ( ) or character classes
[ ]. Groups are less quirky and they more often yield the results you were
looking for.

Wow, this is like saying many situations can be done with either a wrench or
a screwdriver. What deep insight.

I can only highly recommend that site, that is if you are looking for a good
laugh. But put down you coffee first and don't try to drink while reading or
you will have to clean your keyboard. YOU HAVE BEEN WARNED!

jue


0 new messages