Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Removing digits from a string

by blue_cowdawg (Prior)
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 lurking in the Monastery: (5)
As of 2014-08-30 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls