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

Re^3: Loop Array - If $var is something write values until $var is something else

by BillKSmith (Monsignor)
on Sep 30, 2018 at 00:58 UTC ( [id://1223301]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Loop Array - If $var is something write values until $var is something else
in thread Loop Array - If $var is something write values until $var is something else

You seem to want the flip-flop operator. Ref: Range Operators in perlop. A "state variable" is not needed because the state is stored in the operator.
?type 1223291.pl use strict; use warnings; my @cleared = ( 'JOB::HEREISASTRING', 'Something', 'StringA', 'StringB', 'StringC', 'StringD', 'Something Else', 'StringE', 'StringF', 'StringG', 'StringH ', 'JOB::HEREISANOTHERSTRING', 'Something', 'StringI', 'StringJ', 'StringK', 'StringL', 'Something Else', 'StringM', 'StringN', 'StringO', 'StringP ', ); foreach (@cleared) { if (/JOB::(.*)/){ print $_, "\n"; next; } print '~~Something'; if ( !(/Something$/ ... /Something Else$/) or /Else/) { print ' Else'; } print "~~$_\n"; } ?perl 1223291.pl JOB::HEREISASTRING ~~Something~~Something ~~Something~~StringA ~~Something~~StringB ~~Something~~StringC ~~Something~~StringD ~~Something Else~~Something Else ~~Something Else~~StringE ~~Something Else~~StringF ~~Something Else~~StringG ~~Something Else~~StringH JOB::HEREISANOTHERSTRING ~~Something~~Something ~~Something~~StringI ~~Something~~StringJ ~~Something~~StringK ~~Something~~StringL ~~Something Else~~Something Else ~~Something Else~~StringM ~~Something Else~~StringN ~~Something Else~~StringO ~~Something Else~~StringP ?

UPDATE: Added reference

Bill
  • Comment on Re^3: Loop Array - If $var is something write values until $var is something else
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-24 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found