On 05/23/2017 10:31 PM, Richard Hainsworth wrote:
> The code below seems unnecessarily complex.
>
> How about:
>
> my @Data = q:to/SAMPLE/;
>
> <TASK type="D">Mission D',
> <NAME type="P">Sol Wheat</NAME>,
> <NAME type="P">Ted Moon</NAME>,
> </TASK>;
>
> SAMPLE
>
> for @Data {
> next unless m/ 'NAME' .*? '>' $<Name>=( .*? ) '<' /;
> say $<Name>; # say implicitly stringifies $<Name>
> }
>
>
>
Hi Richard.
The idea is that the names can not be extracted unless
they are embedded inside a task field. I found the `next` did
not differentiate that.
If I only wanted to extract the names, regardless of what
field they were in, that would be a lot easier!
-T
Tod,
The original question was about the logic of using 'next'. A 'next'
statement does not itself differentiate data.
Then you suggested some code, which doesn't really feel as if you are
using the power of perl6.
If you want to separate out chunks of data separated by <TASK> tags, and
then operate on data within that, then I suggest you look at using rules
to parse the data.
If you look at the documentation on regexen, see
https://docs.perl6.org/language/regexes#Subrules , you will find a way
of parsing .ini files. This seems close to what you are wanting.
Richard