# string matching

Discussion in 'Perl Misc' started by kamal, Aug 22, 2003.

1. ### kamalGuest

I need to remove $b from$a

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

Regards
Kamal

kamal, Aug 22, 2003

2. ### Steffen MüllerGuest

kamal wrote:
> 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 -- @n=([283488072,6076],[2105905181,8583184],[1823729722,9282996],[281232, 1312416],[1823790605,791604],[2104676663,884944]);$b=6;@c=' -/\_|'=~/./g
;for(@n){for$n(@$_){map{$h=int$n/$b**$_;$n-=$b**$_*$h;$c[@c]=$h}reverse
0..11;push@p,map{$c[$_]}@c[reverse$b..$#c];$#c=$b-1}$p[@p]="\n"}print@p; Steffen Müller, Aug 22, 2003 1. ### Advertisements 3. ### Brian McCauleyGuest (kamal) writes: > 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\\

Brian McCauley, Aug 22, 2003