Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: how to remove a string from end of a line

by graff (Chancellor)
on Oct 09, 2015 at 22:10 UTC ( [id://1144340]=note: print w/replies, xml ) Need Help??


in reply to how to remove a string from end of a line

The information you provided isn't much to go on. I'm sure you have more than just the one example string to deal with, so the question is: in what ways are all the other strings similar and not similar to the one example you've given?

Any of the following might serve as the strategy that solves not only the one example you gave, but all the other cases:

  • Delete all characters after the last "|" character in the string
  • Delete all characters from the 10th "|" character to the end of the line
  • Delete all characters after the 10th "|" character, but before the 11th one (if there is an 11th one)
  • Delete any contiguous string of non-"|" characters that happens to resemble an email address (or contain "@")

The point is that the solution depends on what you know about the input data - and how consistent the input is and what kinds of consistency it has (or doesn't have) - as well as how the output should differ.

I tend to do a lot of "defensive programming" whenever it comes to applying this sort of filter to text data - a lot of data diagnosis (where possible) before writing the code, and enough tests in the code to make sure that the filter does what it's supposed to do, and reports when the input doesn't meet the necessary expectations.

  • Comment on Re: how to remove a string from end of a line

Log In?
Username:
Password:

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

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

    No recent polls found