string matching

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

  1. kamal

    kamal Guest

    I need to remove $b from $a

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

    Regards
    Kamal
     
    kamal, Aug 22, 2003
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. (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
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Seth
    Replies:
    1
    Views:
    1,078
    Ray Andraka
    Aug 1, 2003
  2. Replies:
    1
    Views:
    599
    Craig Deelsnyder
    Oct 25, 2003
  3. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,302
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    237
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    230
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page