On Wednesday, May 24, 2017 01:20 PM, ToddAndMargo wrote:
On 05/23/2017 09:30 PM, ToddAndMargo wrote:
Hi All,
I have a test code in progress and I haven't figured out
how to get 'next' to work the way I want.
next if $Line.contains( "TASK type" );
works, but
if $Line.contains( "TASK type" ) {
next;
does not.
What am I missing?
Many thanks,
-T
yes I know I still have some things to fix on it.
<code>
#!/usr/bin/env perl6
use strict;
my @Data = '<TASK type="D">Mission D',
' <NAME type="P">Sol Wheat</NAME>',
' <NAME type="P">Ted Moon</NAME>',
'</TASK>';
# for @Data -> $Line { say "$Line"; }
for @Data -> $Line {
# next if $Line.contains( "TASK type" );
if $Line.contains( "TASK type" ) {
next;
my $Name = $Line;
if $Name.contains( "NAME type" ) {
$Name ~~ s/.*?\>//;
$Name ~~ s/\<.*//;
say $Name;
}
}
}
</code>
Follow up.
This is what I came up with. I found that `next` did not serve me
well, so i just used a tag.
Thank you all for the help. I had a bit of a time wrapping
my head around `next` there for a while.
-T
<code>
#!/usr/bin/env perl6
use strict;
my @Data = '<TASK type="D">Mission D',
' <NAME type="P">Sol Wheat</NAME>',
' <NAME type="P">Ted Moon</NAME>',
'</TASK>';
# for @Data -> $Line { say "$Line"; }
my $TaskTag = 0;
for @Data -> $Line {
if $Line.contains( "TASK type" ) { $TaskTag = 1; }
if $Line.contains( "NAME type" ) {
( my $Name = $Line) ~~ s/.*?\>//;
$Name ~~ s/\<.*//;
say $Name;
} else { $TaskTag = 0; }
}
</code>
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
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~