in reply to Grabbing specific string from a line

Untested:
my ($number) = $str =~ m{<customer_id>([0-9]{7})</customer_id>};

Replies are listed 'Best First'.
Re^2: Grabbing specific string from a line
by CountZero (Bishop) on Mar 01, 2012 at 19:32 UTC
    It will work until someone decides to add some whitespace and linebreaks and then your regex solution doesn't work anymore. Caution is advised!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Hmmm, is it possible to give a solution for any problem that will still hold if someone modifies the requirement? Considering that it's a given the length of the number is fixed, I wouldn't worry too much about it.

      I'm also assuming the OP isn't a drooling idiot, and has the ability to add \s* to a pattern when required.

        Given that whitespace has a low significance in XML, it is indeed a good idea to add some optional whitespace.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics