Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Efficient way to replace a set of values with another set of values

by Cody Fendant (Hermit)
on Nov 23, 2012 at 10:39 UTC ( [id://1005245]=note: print w/replies, xml ) Need Help??


in reply to Efficient way to replace a set of values with another set of values

How about this:

$str = q{ 1. This is just a sample. 2. This is to check 3. How a set of values 4. can be replaced by another 5. set of values and that too 6. in the most efficient way. }; $str =~ s/^(\d)/chr($1+96)/meg; print $str; ### prints: a. This is just a sample. b. This is to check c. How a set of values d. can be replaced by another e. set of values and that too f. in the most efficient way.
  • Comment on Re: Efficient way to replace a set of values with another set of values
  • Download Code

Replies are listed 'Best First'.
Re^2: Efficient way to replace a set of values with another set of values
by Arunbear (Prior) on Nov 23, 2012 at 10:48 UTC
    Command line version:
    perl -pi -e 's/^(\d)/chr($1+96)/e' myfile
      Parent beat me to the one line solution, but perhaps a minor mod may be needed; I suspect that the OP may have numbers larger than just 1-6, so perhaps:
      perl -pi -e 's/^(\d+)/chr($1+96)/e' myfile
      A Monk aims to give answers to those who have none, and to learn from those who know more.

        space_monk:

        OK, your solution is a bit better .... at least until you get to "27. This is a really long list!".

        ;^D

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found