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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

My team was debating the idea of writing a large file using pipe characters to delimit the fields, and I pointed out that our data includes pipe characters. So the tilde was suggested, but I found some of those too.

So the obvious question arises, can I find a printable ASCII character that never appears in our big file?

I'd like to do this with just a single pass through the file. For locating a pipe character, all I had to say was

while (<>) {last if /\|/} printf "| seen at index %d in %s\n", index($_, '|'), $_;

Update: Should have mentioned that I'm going to run any executable solutions against a 2 GB file. So efficiency may be an issue.

Later: Thanks for the insights! I applaud almut's choice of an indicator array @seen, updated with $seen[ord $chr]++, which should be more efficient than the hash version $seen{$chr}++.

I think I will try kennethk's solution using \Q, both as written and then with the indicator array, as soon as my daughters are in bed and I can connect to my server again.

(Just a minute, sweetie, Daddy will be right with you ...)

It's true the indicator array doesn't offer a builtin keys function to list the seen items, but a grep should do just fine.


In reply to Find what characters never appear by Narveson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found