Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Inherited a perl script...need help (s///)

by blindluke (Hermit)
on Nov 11, 2015 at 21:08 UTC ( [id://1147502]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Inherited a perl script...need help (s///)
in thread Inherited a perl script...need help

If I remove that coding, how do I accomplish the same result?

If you remove something, and want the same result back, you can just put the code back in. Same result as before is practically guaranteed.

I could guess that your real problem is a bit different: you removed lines that should have done X, but replaced 0030 with 9999 instead. You want to know, what code should be put in the place of those lines, so it does what you want - X.

This would be my guess of your problem, which brings us to a problem of mine: I want to help you, yet I don't know what X stands for.

- Luke

Replies are listed 'Best First'.
Re^4: Inherited a perl script...need help (s///)
by iceotron (Initiate) on Nov 11, 2015 at 21:39 UTC

    I tried the code Stevie gave me, but it did the same thing my original code was doing. It found any match of 4 digits and replaced it with 9999. This led me to a way of patching the issue and fixing it in a text editor using block selection. Replacing 0030 with AAAA, replacing 0031 with BBBB ect ect. Basically I need the code to match the 4 character number and replace with a 4 character number. Any numbers of more or less character in a field should be ignored. I hope this helps clarify. My code that I used to clunk my way through the issue.

    $line =~ s/0030/AAAA/g; $line =~ s/0031/BBBB/g; $line =~ s/0884/CCCC/g; $line =~ s/0716/DDDD/g; $line =~ s/0528/EEEE/g;

      It's still hard to guess what you need, but try this:

      s/(?<![0-9])\d{4}(?![0-9])/9999/g

      It replaces all numbers that are exactly four digits long with 9999.

      - Luke

      Bear in mind that a sed style pattern replace like that is a substring match. So it will _also_ match longer numbers of which that's a substring. You need to anchor it - either with lookaround (which restricts a pattern from matching based on what happens before/after it) - or you can match on something like \b which is a word boundary.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found