Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

I'm relatively new to Perl and am having a terribly difficult time figuring this one out. I'm expecting a string in the following format:

 00000001

Essentially, a normal word will be 7 0's followed by a number between 0-9 (8-digits total). However, occasionally there is corruption in the file being processed, causing the format to have something like the following:

 FFFFFFFF or  6C163512

I want to skip these lines of corruption and loop until the corruption has been passed. This is where the tricky part comes in (at least for me). I have tried every combination of matching I can think of, but can't seem to get this one squared away. Below are the lines of code I have tried:

$Disc = get_word(); $D1 = substr($Disc,0,7); $D2 = substr($Disc,7,1); if ($D1 !~ /0+/ and $D2 !~ /([0-9]+)/) ##Catches FFFFFFFF just fine, b +ut not 6C163512 #### $D1 = 6C16351 and $D2 = 2 ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($D1 !~ /0000000/ and $D2 !~ /\D/) ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($Disc =~ /[1-9a-ZA-Z]{7}\D/ ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512

I've been working on this forever and can't seem to figure out how to dynamically catch this corruption in the event that all F's have migrated from the string word. I created the $D1 and $D2 variables to try and see why the regex patterns weren't matching, but I still can't figure it out.

Lastly, it should be noted that occasionally, the line of corruption will show as 01020102. The corruption value will be dynamic. This is why I simply can't use /\D+/ for the majority of the string as the first 7 digits must be 0 for a valid word.


In reply to Match all Non-0 and Letters by arblargan

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 exploiting the Monastery: (4)
As of 2024-03-29 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found