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??
Is there a way to reset a flip-flop operator? For example, I have the following text that I am searching for, in which I am scanning for processes which have a ':D' appended to the back of the :\d:\d (i.e. :0:0:D). There are a number of lines above the lines that I show, however there are no lines below.
. <snip> . ClientSystemName (clisysname): 'SPIFF', Client LongId: '0008027E1180,/ +epic/tst/cachesys/mgr/' PIDTAB for 128 jobs: (Job:PID:reswake:sflg[:D if dead] Job: PID:resw:SF:D 1: 5382 :0:0 2: 5384 :0:0 3: 5385 :0:0 4: 5386 :0:0 5: 5394 :0:0 6: 5387 :0:0 7: 5388 :0:0 8: 5389 :0:0 9: 5390 :0:0 10: 5391 :0:0 11: 5392 :0:0 12: 5393 :0:0 13: 5456 :0:0 14: 5444 :0:0 15: 5445 :0:0 16: 14682 :1:0:D 17: 5450 :0:0 19: 5453 :0:0 20: 14626 :0:0:D

Here's my code,
sub mySub { foreach ( @arr ) { if ( /^PIDTAB/ ... /^\n/ ) { next if ( /^(PIDTAB|\n)/ ); while ( /\s+(\d+):\s+(\d+)\s*:\S+:\S+:D\s+/g ) { # do something } } } }
This works fine the first time through. However, sometimes my flop never evaluates to true, because there is not a blank line at the end of my output. Since the flop will never evaluate to true, the next time I run mySub the operator will be in the true state.

Of course, I can just keep track of the state in a scalar rather than using the flip-flop operator, or I could do some kind of @arr manipulation. But I'm figuring that there is a Perl way of solving this problem that I'm not aware of. Any input is appreciated.

Some further clarification on the text I'm processing:
-sometimes there will be a final line with a newline, sometimes the last line shown there is the last line of input
-The number of lines of processes is unknown, and does not have any "keyword" that I'm aware of.

Update: The match is looking for :\d:\d, not :0:0, thanks to aartisesha for pointing out the error in my question.

In reply to Flip-flop reset? by swkronenfeld

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 avoiding work at the Monastery: (3)
As of 2024-04-25 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found