Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: REGEX omit dashes - simple but ...

by toolic (Bishop)
on Apr 04, 2016 at 17:02 UTC ( #1159511=note: print w/replies, xml ) Need Help??

in reply to REGEX omit dashes - simple but ...

One way is to use tr
use warnings; use strict; my $num = '0001144204-09-017358'; print "$num\n"; $num =~ tr/-//d; print "$num\n"; __END__ 0001144204-09-017358 000114420409017358

Replies are listed 'Best First'.
Re^2: REGEX omit dashes - simple but ...
by wrkrbeee (Scribe) on Apr 04, 2016 at 17:09 UTC
    Thanks toolic! Are you defining the variable as a string rather than a numeric? Thanks!
      Not that it really matters, but 0001144204-09-017358 is not a number but a string.


      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

        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!!!

        Examples of the input data: 0001144204-09-017358 0001144204-10-065610 0001042167-15-000175 0000053669-16-000051 Thanks!

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159511]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2023-09-23 17:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found