Perl strchr? 
Author Message
 Perl strchr?

Is there a standard perl function that'll let me match a certain specific
character in a give nstring of text? I've tried quotemeta but it matches
every special character, I only want to match one specific character (').
I also looked into s/ but I couldn't get it to act right either. I know
this is a pretty lame question but I've looked through all the man pages
and not come up with any good results. A pointer in the right direction
would help a lot. Thanks.

Ben
--
******************************************************************************
Benjamin R. Dixon, jr.                          "It was an age of Empires.
UCNS Student Consultant                          So is this one, not all
http://www.*-*-*.com/ ~beatle          that well disguised."

------------------------------------------------------------------------------



Fri, 22 Dec 2000 03:00:00 GMT  
 Perl strchr?

Quote:

> Is there a standard perl function that'll let me match a certain specific
> character in a give nstring of text?

I am not sure what the problem is, but this works:

$_= "Don't yooouu forget about me, don't, don't, don't, don't, dooon't you...";
s/n'/ no/g;
print $_;

Gives:
Do not yooouu forget about me, do not, do not, do not, do not, dooo not you...

Just to {*filter*} up a great song :)
--
____________________________________________________________
Frank Quednau              
http://www.*-*-*.com/ ~me51fq
________________________________________________



Fri, 22 Dec 2000 03:00:00 GMT  
 Perl strchr?

In general, if you're not using pattern-matching then there's a good
chance that you're not using the correct approach in PERL.

However, the "index" function may do what you want.  Note that for many
Unix C libraries, index() and strchr() are interchangable, where the
former name is still supported for historical reasons.  Looks like PERL
got stuck with the older naming convention.

- Jonathan

Quote:

> Is there a standard perl function that'll let me match a certain specific
> character in a give nstring of text? I've tried quotemeta but it matches
> every special character, I only want to match one specific character (').
> I also looked into s/ but I couldn't get it to act right either. I know
> this is a pretty lame question but I've looked through all the man pages
> and not come up with any good results. A pointer in the right direction
> would help a lot. Thanks.

> Ben
> --
> ******************************************************************************
> Benjamin R. Dixon, jr.                          "It was an age of Empires.
> UCNS Student Consultant                          So is this one, not all
> http://www.arches.uga.edu/~beatle                that well disguised."

> ------------------------------------------------------------------------------



Fri, 22 Dec 2000 03:00:00 GMT  
 Perl strchr?

Quote:

> In general, if you're not using pattern-matching then there's a good
> chance that you're not using the correct approach in PERL.

Right on.

Quote:
> However, the "index" function may do what you want.  Note that for many
> Unix C libraries, index() and strchr() are interchangable, where the
> former name is still supported for historical reasons.  Looks like PERL
> got stuck with the older naming convention.

Nope.  Whereas C's index() is functionally equivalent to strchr(),
Perl's index() is more like C's strstr().  Check it out.

--
John Porter



Fri, 22 Dec 2000 03:00:00 GMT  
 Perl strchr?

You want regular expressions and the match ( m// ) operator. I think perlre
is the man page you want, i.e:

$string = 'something with something you want to match in';

if( $string =~ m/match/ ) {
  print "Found a match\n";

Quote:
} else {

  print "No match found\n";

Quote:
}

This is a very simplistic example but if all you want to do is match a bit
of text then this will do the job, if you want proper strchr() emulation
 i.e. the exact position of the match ) you probably want to use the pos()
function ( see perlfunc ). Essentially it all hinges on what you want to do,
processes any string which matches, extract the necesary bit from strings
based on some fancy regular expression or just get the position in the
string where the match occurs.

Simon

Quote:

>Is there a standard perl function that'll let me match a certain specific
>character in a give nstring of text? I've tried quotemeta but it matches
>every special character, I only want to match one specific character (').
>I also looked into s/ but I couldn't get it to act right either. I know
>this is a pretty lame question but I've looked through all the man pages
>and not come up with any good results. A pointer in the right direction
>would help a lot. Thanks.

>Ben
>--
>***************************************************************************
***
>Benjamin R. Dixon, jr. "It was an age of Empires.
>UCNS Student Consultant So is this one, not all
>http://www.arches.uga.edu/~beatle that well disguised."

>---------------------------------------------------------------------------

---


Fri, 22 Dec 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. strchr

2. NYC: PERL PERL PERL PERL PERL PERL PERL

3. Perl, perl or PERL debate

4. Perl Golf mailing list - perl.golf on nntp.perl.org

5. Perl, Perl, Perl, don't give your love to URL

6. RFD - comp.lang.perl.db, comp.lang.perl.network, comp.lang.perl.regex

7. \c@ in Perl, perl & perl + modules

8. New dialect of perl: xperl (or reinventing perl, or perl-izing jpython)

9. Perl/Swing (Perl/AWT) as an eventual alternative to Perl/Tk

10. Perl *is* strongly typed (was Re: Perl description)

11. Perl syntax and beyond (was: Re: Perl style and module searches)

12. Perl 6, llya, and lisp as a replacement for Perl

 

 
Powered by phpBB® Forum Software