in reply to Re: 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
Lets see the @cleared (Dump):my @result; foreach my $x (@cleared) { if ($x =~ /JOB::(.*)/){ print $x, "\n"; } else { unless ($x =~ m/^Something/){ print "~~Something~~", $x, "\n"; } else { unless ($x =~ m/^Something Else/){ print "~~Something Else~~", $x, "\n"; } } } }
Output:$VAR1 = 'JOB::HEREISASTRING'; $VAR2 = 'Something'; $VAR3 = 'StringA'; $VAR4 = 'StringB'; $VAR5 = 'StringC'; $VAR6 = 'StringD'; $VAR7 = 'Something Else'; $VAR8 = 'StringE'; $VAR9 = 'StringF'; $VAR10 = 'StringG'; $VAR11 = 'StringH '; $VAR12 = 'JOB::HEREISANOTHERSTRING'; $VAR13 = 'Something'; $VAR14 = 'StringI'; $VAR15 = 'StringJ'; $VAR16 = 'StringK'; $VAR17 = 'StringL'; $VAR18 = 'Something Else'; $VAR19 = 'StringM'; $VAR20 = 'StringN'; $VAR21 = 'StringO'; $VAR22 = 'StringP ';
I wish output:JOB::HEREISASTRING ~~Something Else~~Something ~~Something~~StringA ~~Something~~StringB ~~Something~~StringC ~~Something~~StringD ~~Something~~Something Else ~~Something~~StringE ~~Something~~StringF ~~Something~~StringG ~~Something~~StringH JOB::HEREISANOTHERSTRING ~~Something Else~~Something ~~Something~~StringI ~~Something~~StringJ ~~Something~~StringK ~~Something~~StringL ~~Something~~Something Else ~~Something~~StringM ~~Something~~StringN ~~Something~~StringO ~~Something~~StringP
In fact i want to tag my values from a start until a match occurs and tag it different and so on.... What comes to my mind is that with foreach loop variable $x changes and in the loop is again "Something"!?JOB::HEREISASTRING ~~Something Else~~Something Else (could be removed) ~~Something~~StringA ~~Something~~StringB ~~Something~~StringC ~~Something~~StringD ~~Something Else~~Something Else (could be removed) ~~Something Else~~StringE ~~Something Else~~StringF ~~Something Else~~StringG ~~Something Else~~StringH JOB::HEREISANOTHERSTRING ~~Something Else~~Something Else (could be removed) ~~Something~~StringI ~~Something~~StringJ ~~Something~~StringK ~~Something~~StringL ~~Something Else~~Something Else (could be removed) ~~Something Else~~StringM ~~Something Else~~StringN ~~Something Else~~StringO ~~Something Else~~StringP
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
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 |