Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Char replacement

by dakkar (Hermit)
on Apr 02, 2003 at 12:55 UTC ( #247482=note: print w/replies, xml ) Need Help??

in reply to Char replacement

"second string in each row" means exactly what?

You have to perform two steps:

  1. find the beginning of that "second string"
  2. change its first char

For step 2, you can use s///, tr///, or substr. Other have already said how.

For step 1, it depends on how you separate strings. If your strings are separated by spaces (no quoting/escaping), I'd write: $line =~ s/^(\S+\s+)0/${1}2/; meaning:

  • match
    • ^ from the beginning of the line
    • ( remember the content of this
    • \S+ some non-spaces
    • \s+ some spaces
    • ) end remembering
    • 0 a literal zero
  • replace with
    • ${1} what you remembered in the match
    • 2 a literal 2

        dakkar - Mobilis in mobile

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-05-18 12:17 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (70 votes). Check out past polls.