swkronenfeld has asked for the wisdom of the Perl Monks concerning the following question:
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.
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.
Here's my code,. <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
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.sub mySub { foreach ( @arr ) { if ( /^PIDTAB/ ... /^\n/ ) { next if ( /^(PIDTAB|\n)/ ); while ( /\s+(\d+):\s+(\d+)\s*:\S+:\S+:D\s+/g ) { # do something } } } }
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Flip-flop reset?
by sgifford (Prior) on Aug 30, 2006 at 01:37 UTC | |
by swkronenfeld (Hermit) on Aug 30, 2006 at 14:47 UTC | |
by ysth (Canon) on Aug 30, 2006 at 20:55 UTC | |
Re: Flip-flop reset?
by cdarke (Prior) on Aug 29, 2006 at 20:01 UTC | |
by swkronenfeld (Hermit) on Aug 29, 2006 at 20:14 UTC | |
Re: Flip-flop reset?
by Dietz (Curate) on Aug 30, 2006 at 06:02 UTC | |
Re: Flip-flop reset?
by aartisesha (Novice) on Aug 30, 2006 at 06:54 UTC | |
Re: Flip-flop reset?
by ysth (Canon) on Aug 30, 2006 at 21:56 UTC | |
by runrig (Abbot) on May 31, 2007 at 23:12 UTC | |
by ysth (Canon) on Aug 31, 2006 at 21:07 UTC |
Back to
Seekers of Perl Wisdom