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
Something is wrong here. I am hoping that a full runnable code example with use strict; use warnings; will be very helpful.my $jobprofil = $x->{JobProfil}; ...later this... unless ($x =~ m/^Something Else/){
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Loop Array - If $var is something write values until $var is something else
by Anonymous Monk on Sep 29, 2018 at 20:02 UTC | |
Lets see the @cleared (Dump): Output: I wish output: 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"!? | [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Sep 29, 2018 at 22:36 UTC | |
(BTW: This format is something like what I'd have liked to have seen for your SSCCE.) Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by Marshall (Canon) on Sep 29, 2018 at 20:53 UTC | |
| [reply] [d/l] |
by johngg (Canon) on Sep 29, 2018 at 23:02 UTC | |
Here's my take on what I think you are after, I have omitted the "(could be removed)" items. The code:-
The output:-
I hope this is helpful. Cheers, JohnGG | [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Sep 30, 2018 at 02:01 UTC | |
elsif ( $item !~ m{^String} ) { ... } My interpretation is that the StringA etc. input items are supposed to represent any input strings at all rather than strings that all start with 'String'. I think that only the 'JOB::...', 'Something' and 'Something Else' strings are supposed to be constants. Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by Marshall (Canon) on Sep 30, 2018 at 03:00 UTC | |
Update: I did the following code rather quickly. I changed my mind during the middle of coding and didn't revise the previously written code. process_record() could be shortened by calling process_sub_record() a couple of times instead of just once. This is a small detail and should be obvious how to do. The OP is still not completely clear as to whether these "Something" and "Something Else" strings are standard invariant sub-headers or whether they can vary. Also not spec'd is whether the number of lines in the record can vary or not. Well, Ok, another update... The change to call process_sub_record() twice was so extremely trivial, that I did it and put original code in a readmore block. Perhaps it is not obvious but this implementation allows blank and comment lines at the beginning or end of the file - I have often found that feature useful in my work.
Read more... (2 kB) | [reply] [d/l] [select] |
by Marshall (Canon) on Oct 03, 2018 at 22:08 UTC | |
I've given other solutions as have others in this thread. You have an overly complex "if" code block. Your "else" layer is not needed. In this code version, there is something to be done with a JOB line, a SOMETHING line or a SOMETHING ELSE line. Otherwise the current line is printed with the current header prepended. Somewhere else in this thread I gave a solution where these sub-header tags were not fixed in advance but has the limitation that each sub-section must have exactly 4 lines of "other strings". In general the better your specify the problem, the better the answers tend to be.
| [reply] [d/l] |