Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

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

  • 06-03-2007 08:45PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,683 ✭✭✭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, Registered Users 2 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