in reply to Re^3: REGEX omit dashes - simple but ...
in thread REGEX omit dashes - simple but ...

Thanks guys, here's the revised statement, along with the result: if($line=~m/^\s*ACCESSION\s*NUMBER:\s*/m){$access_num=$1; $access_num =~ tr/-//d;} Result is the error message stating "Use of uninitialized value ...." ?? Thanks!!!

  • Comment on Re^4: REGEX omit dashes - simple but ...

Replies are listed 'Best First'.
Re^5: REGEX omit dashes - simple but ...
by stevieb (Canon) on Apr 04, 2016 at 17:23 UTC

    You forgot to add your capture group of (\d*). However, that won't really help, as that won't capture your - (dashes), or any numbers after it.

    Why don't you show us a few lines of example data you're trying to match?

    Also, Use of uninitialized... is not an error, it's a warning. It's most likely saying that $1 is uninitialized (because you didn't capture anything).

Re^5: REGEX omit dashes - simple but ...
by kennethk (Abbot) on Apr 04, 2016 at 17:28 UTC
    You are getting an uninitialized error because you are trying to change the content of $access_num, to which you've assigned $1, but there were no parentheses in your first regular expression. Maybe you mean something like:
    if ($line =~ s/^\s*ACCESSION\s*NUMBER:\s*/) { $line =~ tr/-//; }
    or possibly
    if ($line =~ s/^\s*ACCESSION\s*NUMBER:\s*([-\d]+)$/m) { $access_num = $1; $access_num =~ tr/-//; }

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.