Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PERL; input string has a $ sign...what to do?

Options
  • 06-03-2007 9:45pm
    #1
    Registered Users Posts: 2,364 ✭✭✭


    I'm trying to extract the number '2' in the line "Blinds are now $1/$2" using regular expressions in perl. I'm running into problems because of the $ sign, it being the symbol used to denote variables in perl.

    Anyone know how I can get around this problem?

    edit: think I've got it. Stick extra quotes around it.


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    You can always backslash the $ symbol to tell the regex engine that you mean it literally.
    if ( /Blinds are now \$1/\$(\d)/ ) {
      $TheNumberTwo = $1;  # == 2.
    }
    


  • Registered Users Posts: 2,364 ✭✭✭Mr. Flibble


    The string is not generated by me, its passed externally - so I can't add the slashes without it knowing where the $s are.


Advertisement