Professional Web Applications Themes

string matching - PERL Miscellaneous

I need to remove $b from $a $a = "abc/\def/ghi" ; $b = "abc/\def"; Regards Kamal...

Sponsored Links
  1. #1

    Default string matching

    I need to remove $b from $a

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

    Regards
    Kamal
    Sponsored Links
    kamal Guest

  2. #2

    Default Re: string matching

    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;pushp,map{$c[$_]}c[reverse$b..$#c];$#c=$b-1}$p[p]="\n"}printp;

    Steffen Müller Guest

  3. #3

    Default Re: string matching

    [email]kamalindia.ti.com[/email] (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 Guest

Similar Threads

  1. Regex for matching a string not in a URL
    By webpointz in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: April 8th, 05:10 PM
  2. Reg. string matching using reg-exp
    By Balaji thoguluva in forum PERL Beginners
    Replies: 7
    Last Post: February 6th, 11:13 PM
  3. Pattern matching for xx-xx-xx string
    By jeff@nospam.com in forum PHP Development
    Replies: 7
    Last Post: January 19th, 06:38 PM
  4. Matching String
    By Pablo Fischer in forum PERL Beginners
    Replies: 1
    Last Post: August 24th, 05:25 PM
  5. String matching not working
    By Dave from Dublin in forum PERL Miscellaneous
    Replies: 2
    Last Post: June 30th, 10:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139