Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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


Comment on Re: Removing digits from a string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2015-07-05 04:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls