Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Removing digits from a string

by blue_cowdawg (Monsignor)
on Jan 01, 2013 at 16:20 UTC ( #1011160=note: print w/replies, xml ) Need Help??

in reply to Removing digits from a string

      now I need to truncate 20130101 from the file name

As someone else mentioned, I'm not sure the word "truncate" quite fits. Here's a solution that gives you a bit more flexibility:

| hand waving here... my $fname = "20130101Customer100.imp"; # gotta go somewhere.. $fname =~ m@^(\d+)([A-Za-z0-9]+)\.imp$@; # Capture what we are looking + for... my $dateStamp=$1; my $basename=$2; | do something with this.
This will result in the scalar $dateStamp containing "20130101" and $basename containing "Customer100". The presumption I made (you didn't specify otherwise) was that your filenames all have the extension "imp" and as long as they do the regex I supplied you will work. I leave it as an exercise in intellect for you to modify the regex if there are other extensions involved.

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011160]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-05-27 08:18 GMT
Find Nodes?
    Voting Booth?