Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Char replacement

by dakkar (Hermit)
on Apr 02, 2003 at 12:55 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (10)
As of 2024-04-18 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found