string matching

S

Steffen Müller

kamal said:
I need to remove $b from $a

$a = "abc/\def/ghi" ;
$b = "abc/\def";

Simple, really.

$a = "/ghi";

Or try regexes.

$a =~ s/\Q$b//; # Removes first occurrance.

Steffen
 
B

Brian McCauley

I need to remove $b from $a

$a =~ s/\Q$b//;

(Or you can use a non-Perlish solution using substr() and index()
that'll take longer to write, be difficult to read, look less like
Perl but will probably run a little faster).
$a = "abc/\def/ghi" ;
$b = "abc/\def";

BTW you should always develop with warnings on. The above generates
two "Unrecognized escape \d passed through" warnings.

This looks like a homework question. The s/// operator is usually
covered quite early in any Perl course.

If this is a taught course be aware there's a fair chance your teacher
will be monitoring Usenet so you are not going to fool anyone.

If you are leaning from a book, doesn't it have answers in the back?

If you are not on a Perl course then perhaps you should be. Please do
not take offense when I say if you are at the level where you need to
ask many of this level of question you'd probably beniefit more from
some sort of structured Perl course more than you will from asking odd
isolated questions on Usenet.

(Of course, it could just be you had a mental block, in which case
disregard the above).

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top