Re: need help with "next"

2017-05-24 Thread ToddAndMargo

On 05/24/2017 01:04 AM, Richard Hainsworth wrote:

see https://docs.perl6.org/language/regexes#Subrules


Fascinating and way over my head.  Give me a year or two
to catch up.


Re: need help with "next"

2017-05-24 Thread ToddAndMargo

On 05/24/2017 01:04 AM, Richard Hainsworth wrote:

On 05/23/2017 10:31 PM, Richard Hainsworth wrote:

> The code below seems unnecessarily complex.
>
> How about:
>
> my @Data = q:to/SAMPLE/;
>
>  Mission D',
>  Sol Wheat,
>  Ted Moon,
>  ;
>
> SAMPLE
>
> for @Data {
>  next unless m/ 'NAME' .*? '>' $=( .*? ) '<' /;
>  say $; # say implicitly stringifies $
> }
>
>
>

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  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


I was just playing around.  The more of these little programs
I write, the more comfortable I get with Perl 6


Re: need help with "next"

2017-05-24 Thread Richard Hainsworth

On 05/23/2017 10:31 PM, Richard Hainsworth wrote:

> The code below seems unnecessarily complex.
>
> How about:
>
> my @Data = q:to/SAMPLE/;
>
>  Mission D',
>  Sol Wheat,
>  Ted Moon,
>  ;
>
> SAMPLE
>
> for @Data {
>  next unless m/ 'NAME' .*? '>' $=( .*? ) '<' /;
>  say $; # say implicitly stringifies $
> }
>
>
>

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  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


Re: need help with "next"

2017-05-24 Thread ToddAndMargo

On 05/24/2017 12:02 AM, Norman Gaywood wrote:
On 24 May 2017 at 16:40, Norman Gaywood > wrote:



However, your code does not look like it will do what you want
if you have multiple TASKs


Yes it does. Sorry ignore me :-)


Oh it had issues.  They showed up when I
mixed in negative case data.


Re: need help with "next"

2017-05-24 Thread ToddAndMargo

On 05/23/2017 11:40 PM, Norman Gaywood wrote:

I'm a rank beginner p6 programmer so


You are further along than me!


Re: need help with "next"

2017-05-24 Thread ToddAndMargo

On 05/23/2017 11:40 PM, Norman Gaywood wrote:
However, your code does not look like it will do what you want if you 
have multiple TASKs


I improved it.  See my other follow post #3


Re: need help with "next"

2017-05-24 Thread ToddAndMargo

Oh, you know what, I thought it might be a good idea
to throw some negative case data into the mix.  This
is what I came up with:


#!/usr/bin/env perl6

use strict;

my @Data = 'Mission A',
   '   Peter Meter',
   '   John Deer',
   '   Sam Horse',
   '',
   '',
   'Mission A',
   '   Tom',
   '   Dick',
   '   Harry',
   '',
   '',
   'Mission D',
   '   Sol Wheat',
   '   Micky Mouse',
   '   Ted Moon',
   '';
# for @Data -> $Line { say "$Line"; }

my $TaskTag = 0;
for @Data -> $Line {
   if $Line.contains( "\//;
  $Name ~~ s/\<.*//;
  say $Name;
   }
}


$ ./XMLSub.pl6
Peter Meter
John Deer
Sam Horse
Sol Wheat
Ted Moon


--
~
I am Windows
I am the Blue Screen of Death
No one hears your screams
~


Re: need help with "next"

2017-05-24 Thread Norman Gaywood
On 24 May 2017 at 16:40, Norman Gaywood  wrote:

>
> However, your code does not look like it will do what you want if you have
>> multiple TASKs
>>
>
>
Yes it does. Sorry ignore me :-)


-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


Re: need help with "next"

2017-05-24 Thread Norman Gaywood
On 24 May 2017 at 15:20, ToddAndMargo  wrote:
>
>
> 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
>
> 
> #!/usr/bin/env perl6
>
> use strict;
>
> my @Data = 'Mission D',
>'   Sol Wheat',
>'   Ted Moon',
>'';
> # 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; }
>
> }
> 
>

I'm a rank beginner p6 programmer so I'm sure my code can be improved.

However, your code does not look like it will do what you want if you have
multiple TASKs

What about something like:
my @Data =
 'Mission D',
   '   Sol Wheat',
   '   Ted Moon',
 '',
 'Mission C',
   '   Jim Kirk',
   '   Mr Spock',
 '',
;

my $in-TASK = "";

for @Data -> $Line {
if $Line.contains( "TASK type" ) {
$Line ~~ m/ 'TASK' .*? '>' $=( .* ) /;
$in-TASK = $;
next;
}
if $Line.contains( "/TASK" ) {
$in-TASK = "";
next;
}
if $in-TASK ne "" && $Line.contains( "NAME type" ) {
$Line ~~ m/ 'NAME' .*? '>' $=( .*? ) '<' /;
say $in-TASK, $;
}
}


-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


Re: need help with "next"

2017-05-24 Thread ToddAndMargo



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.



#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
'   Sol Wheat',
'   Ted Moon',
'';
# 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;
   }
}
}







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


#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
   '   Sol Wheat',
   '   Ted Moon',
   '';
# 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; }
}





On 05/23/2017 10:31 PM, Richard Hainsworth wrote:
> The code below seems unnecessarily complex.
>
> How about:
>
> my @Data = q:to/SAMPLE/;
>
>  Mission D',
>  Sol Wheat,
>  Ted Moon,
>  ;
>
> SAMPLE
>
> for @Data {
>  next unless m/ 'NAME' .*? '>' $=( .*? ) '<' /;
>  say $; # say implicitly stringifies $
> }
>
>
>

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
~~


Re: need help with "next"

2017-05-23 Thread Richard Hainsworth

The code below seems unnecessarily complex.

How about:

my @Data = q:to/SAMPLE/;

Mission D',
Sol Wheat,
Ted Moon,
;

SAMPLE

for @Data {
next unless m/ 'NAME' .*? '>' $=( .*? ) '<' /;
say $; # say implicitly stringifies $
}



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.



#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
'   Sol Wheat',
'   Ted Moon',
'';
# 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;
   }
}
}







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


#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
   '   Sol Wheat',
   '   Ted Moon',
   '';
# 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; }
}




Re: need help with "next"

2017-05-23 Thread ToddAndMargo

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.



#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
'   Sol Wheat',
'   Ted Moon',
'';
# 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;
   }
}
}







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


#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
   '   Sol Wheat',
   '   Ted Moon',
   '';
# 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; }
}


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


Re: need help with "next"

2017-05-23 Thread Richard Hainsworth

On Wednesday, May 24, 2017 12:46 PM, ToddAndMargo wrote:


On Tue, May 23, 2017 at 11: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.



#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
'   Sol Wheat',
'   Ted Moon',
'';
# for @Data -> $Line { say "$Line"; }

for @Data -> $Line {
# next if $Line.contains( "TASK type" );
if $Line.contains( "TASK type" ) {
   next;
Any data fulfilling the 'if' condition, and thus entering this block 
will be 'next'ed. Nothing will pass the 'next'.
But no data not fulfilling the condition will 'see' the code below, 
which is not what you intend.

Perhaps you omitted an 'else' clause after the 'next' statement?

   my $Name = $Line;
   if $Name.contains( "NAME type" ) {
  $Name ~~ s/.*?\>//;
  $Name ~~ s/\<.*//;
  say $Name;
   }
}
}






On 05/23/2017 09:39 PM, Brad Gilbert wrote:
> You do realize that `next` immediately stops the current iteration and
> goes onto the *next* one right?
> That is, there is no point putting any code after it because it will
> never be run.
>

That is what I want.  If the current $line has "Task type" in
it, I want to jump to the next line in the array.  What am
I missing?


Re: need help with "next"

2017-05-23 Thread ToddAndMargo



On Tue, May 23, 2017 at 11: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.



#!/usr/bin/env perl6

use strict;

my @Data = 'Mission D',
'   Sol Wheat',
'   Ted Moon',
'';
# 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;
   }
}
}




On 05/23/2017 09:39 PM, Brad Gilbert wrote:
> You do realize that `next` immediately stops the current iteration and
> goes onto the *next* one right?
> That is, there is no point putting any code after it because it will
> never be run.
>

That is what I want.  If the current $line has "Task type" in
it, I want to jump to the next line in the array.  What am
I missing?


Re: need help with "next"

2017-05-23 Thread Brad Gilbert
You do realize that `next` immediately stops the current iteration and
goes onto the *next* one right?
That is, there is no point putting any code after it because it will
never be run.

On Tue, May 23, 2017 at 11: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.
>
>
> 
> #!/usr/bin/env perl6
>
> use strict;
>
> my @Data = 'Mission D',
>'   Sol Wheat',
>'   Ted Moon',
>'';
> # 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;
>   }
>}
> }
>
> 
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~