Loading ...
Sorry, an error occurred while loading the content.

Fw: Re: [PBML] Re: Regular Expression Question: Is this syntax legal?

Expand Messages
  • MAJID AGHA AMINI
    excuse i think that you must use this function index string , $thing ... From: MAJID AGHA AMINI Subject: Re: [PBML] Re: Regular Expression
    Message 1 of 1 , Aug 6, 2009
    • 0 Attachment
      excuse
      i think that you must use this function
      index string , $thing

      --- On Fri, 8/7/09, MAJID AGHA AMINI <amini4@...> wrote:


      From: MAJID AGHA AMINI <amini4@...>
      Subject: Re: [PBML] Re: Regular Expression Question: Is this syntax legal?
      To: perl-beginner@yahoogroups.com
      Date: Friday, August 7, 2009, 1:11 AM


       



      #!C:\Perl\bin\ perl.exe
      print "enter your ...","\n";
      $majid=<STDIN> ;
      chomp($majid) ;
      $_="[test]";
      if($majid eq $_) {
      print "yah","\n";
      }
      else {
      print "boooo...\n" ;
      }

      --- On Tue, 7/28/09, call_ashutosh2003 <ashutosh.call@ gmail.com> wrote:

      From: call_ashutosh2003 <ashutosh.call@ gmail.com>
      Subject: [PBML] Re: Regular Expression Question: Is this syntax legal?
      To: perl-beginner@ yahoogroups. com
      Date: Tuesday, July 28, 2009, 7:31 PM

       

      Why are you putting ^ in "/^$thing/" when you assigne $_ to "[test]"
      write (/$thing/) as $_ now begins with [ ;)

      --- In perl-beginner@ yahoogroups. com, "fooguy89" <fooguy89@.. .> wrote:
      >
      > Let's say I have this snippet:
      >
      > $_ = "test";
      > my $thing = "test";
      >
      > if (/^$thing/)
      > {
      > print "Yah!\n";
      > }
      > else
      > {
      > print "booo...\n";
      > }
      >
      > It correctly prints "Yah!". If I change $_ to "xxx" it correctly prints "booo...".
      >
      > However, I'm a bit stumped as to what to do if my string to test has [ and ] characters, i.e.
      >
      > $_="[test]";
      > my $thing = "[test]";
      >
      > This incorrectly prints "booo...". I realize that [ and ] are special regex characters. I tried using "\[test\]" in both $thing and $_, but it still fails.
      >
      > If this is indeed valid syntax (having a variable inside a regex), how would I get it to work?
      >
      > I realize there are probably better ways to do this, but at this point it's become a thorn in my side to find the answer!
      >
      > Thanks.
      >

      [Non-text portions of this message have been removed]



















      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.