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>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to