Re: for loop index question

2017-02-28 Thread Andrew Kirkpatrick
The zip operator in this case takes two sequences and interleaves them
into a single sequence. It might be useful if you have handy or can
generate a list of keys and a list of values you want to put together
in pairs using => to create a hash table.

Your explicit approach makes sense for readability - it can aid
comprehension if a fake address looks like a real one.

On 1 March 2017 at 16:47, Todd Chester  wrote:
>> On Wednesday, March 01, 2017 01:01 PM, Todd Chester wrote:
>>>
>>> Hi All,
>>>
>>> And it even gets more interesting.
>>>
>>> It even works with Associative Arrays (Hashes), which I adore!
>>>
>>> Interesting how associative arrays don't print in order that they
>>> were entered into the array.
>>>
>>> 
>>> #!/usr/bin/perl6
>>>
>>> my @x = ( "a", "b", "c", "d" );
>>>
>>> print "loop of \@x\n";
>>> for @x.kv -> $index, $value {
>>>print " Line no. <" ~ ($index + 1) ~
>>>"> has an index of <$index> and a value of <$value>\n"; }
>>> print "\n";
>>>
>>>
>>> my %y = ( 'aa'=>"AA", 'bb'=> "BB", 'cc'=>"CC", 'dd'=>"DD" );
>>>
>>> print "loop of \%y\n";
>>> for %y.kv -> $key, $value {
>>>print " \%y has an key of <$key> and a value of <$value>\n"; }
>>> print "\n";
>>> 
>>>
>>> ./LoopIndexTest.pl6
>>> loop of @x
>>>  Line no. <1> has an index of <0> and a value of 
>>>  Line no. <2> has an index of <1> and a value of 
>>>  Line no. <3> has an index of <2> and a value of 
>>>  Line no. <4> has an index of <3> and a value of 
>>>
>>> loop of %y
>>>  %y has an key of  and a value of 
>>>  %y has an key of  and a value of 
>>>  %y has an key of  and a value of 
>>>  %y has an key of  and a value of 
>
>
>
> On 02/28/2017 09:27 PM, Richard Hainsworth wrote:
>> Instead of
>> my %y = ( 'aa'=>"AA", 'bb'=> "BB", 'cc'=>"CC", 'dd'=>"DD" );
>>
>> in the code below,
>>
>> I find the following useful for filling an associative array (when
>> testing and I dont care about the contents)
>>
>> my %y =  Z=> 'AA'..*;
>> #{aa => AA, bb => AB, cc => AC, dd => AD}
>>
>> But if the contents matter, how about,
>> my %y =  Z=> ;
>> #{aa => AA, bb => BB, cc => CC, dd => DD}
>>
>> The 'Z' is the zip operator, the '=>' links a key to its value.
>> The ..* uses the power of perl6 to generate sequences from an initial
>> member.
>>
>> Richard
>>
>
> Hi Richard,
>
> I don't understand how the zipper works or
> why I'd want to use it.
>
> my %Location = ( 'City'=>"Carson City",
>  'State'=>"NV",
>  'ZipCode'=>"89701",
>  'Country'=>"USA" );  # just made up place
>
> Make sense to me and is easily maintainable.
> I do not get where the zipper comes in?  Or
> how it would make things easier to read?
>
> By chance is the idea that you don't have to the assign the
> values at the same time you assign the keys?
>
> There is extra time spent on writing the way I did it, but
> I don't care.  I know how to type (high school typing) and
> my main goal it to make the code maintainable. (This is why I
> use Top Down as well.)  I can type almost as fast as I think.
>
> I am confused,
> -T


Re: for loop index question

2017-02-28 Thread Todd Chester

On Wednesday, March 01, 2017 01:01 PM, Todd Chester wrote:

Hi All,

And it even gets more interesting.

It even works with Associative Arrays (Hashes), which I adore!

Interesting how associative arrays don't print in order that they
were entered into the array.


#!/usr/bin/perl6

my @x = ( "a", "b", "c", "d" );

print "loop of \@x\n";
for @x.kv -> $index, $value {
   print " Line no. <" ~ ($index + 1) ~
   "> has an index of <$index> and a value of <$value>\n"; }
print "\n";


my %y = ( 'aa'=>"AA", 'bb'=> "BB", 'cc'=>"CC", 'dd'=>"DD" );

print "loop of \%y\n";
for %y.kv -> $key, $value {
   print " \%y has an key of <$key> and a value of <$value>\n"; }
print "\n";


./LoopIndexTest.pl6
loop of @x
 Line no. <1> has an index of <0> and a value of 
 Line no. <2> has an index of <1> and a value of 
 Line no. <3> has an index of <2> and a value of 
 Line no. <4> has an index of <3> and a value of 

loop of %y
 %y has an key of  and a value of 
 %y has an key of  and a value of 
 %y has an key of  and a value of 
 %y has an key of  and a value of 



On 02/28/2017 09:27 PM, Richard Hainsworth wrote:
> Instead of
> my %y = ( 'aa'=>"AA", 'bb'=> "BB", 'cc'=>"CC", 'dd'=>"DD" );
>
> in the code below,
>
> I find the following useful for filling an associative array (when
> testing and I dont care about the contents)
>
> my %y =  Z=> 'AA'..*;
> #{aa => AA, bb => AB, cc => AC, dd => AD}
>
> But if the contents matter, how about,
> my %y =  Z=> ;
> #{aa => AA, bb => BB, cc => CC, dd => DD}
>
> The 'Z' is the zip operator, the '=>' links a key to its value.
> The ..* uses the power of perl6 to generate sequences from an initial
> member.
>
> Richard
>

Hi Richard,

I don't understand how the zipper works or
why I'd want to use it.

my %Location = ( 'City'=>"Carson City",
 'State'=>"NV",
 'ZipCode'=>"89701",
 'Country'=>"USA" );  # just made up place

Make sense to me and is easily maintainable.
I do not get where the zipper comes in?  Or
how it would make things easier to read?

By chance is the idea that you don't have to the assign the
values at the same time you assign the keys?

There is extra time spent on writing the way I did it, but
I don't care.  I know how to type (high school typing) and
my main goal it to make the code maintainable. (This is why I
use Top Down as well.)  I can type almost as fast as I think.

I am confused,
-T


Re: for loop index question

2017-02-28 Thread Todd Chester

Hi All,

And it even gets more interesting.

It even works with Associative Arrays (Hashes), which I adore!

Interesting how associative arrays don't print in order that they
were entered into the array.


#!/usr/bin/perl6

my @x = ( "a", "b", "c", "d" );

print "loop of \@x\n";
for @x.kv -> $index, $value {
   print " Line no. <" ~ ($index + 1) ~
   "> has an index of <$index> and a value of <$value>\n"; }
print "\n";


my %y = ( 'aa'=>"AA", 'bb'=> "BB", 'cc'=>"CC", 'dd'=>"DD" );

print "loop of \%y\n";
for %y.kv -> $key, $value {
   print " \%y has an key of <$key> and a value of <$value>\n"; }
print "\n";


./LoopIndexTest.pl6
loop of @x
 Line no. <1> has an index of <0> and a value of 
 Line no. <2> has an index of <1> and a value of 
 Line no. <3> has an index of <2> and a value of 
 Line no. <4> has an index of <3> and a value of 

loop of %y
 %y has an key of  and a value of 
 %y has an key of  and a value of 
 %y has an key of  and a value of 
 %y has an key of  and a value of 


Re: for loop index question

2017-02-28 Thread Todd Chester



On 02/28/2017 01:30 PM, yary wrote:

Maybe using placeholder variables was a bit too much (those variables
with the ^ twigil)


for @a.kv -> $k, $v { say "Value $v has index $k" }

Value g has index 0
Value h has index 1
Value i has index 2
Value j has index 3
Value k has index 4


Hi Yary,

   Thank you!

-T


Re: for loop index question

2017-02-28 Thread Todd Chester



On 02/28/2017 01:20 PM, ToddAndMargo wrote:

Hi All,

There are times when I want to know th4e index of an array
when I am in a "for @array" loop.  I can do it with a
variable outside the for loop and increment it, but
I would line to know know if there is a way to incorporate
it in the loop command.

This is my long winded way of doing it in Perl 5:

while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }


Many thanks,
-T



Hi All,

Thank you all!

Made me look up "kv":

   https://docs.perl6.org/routine/kv
   Returns an interleaved sequence of indexes and values. For example
   .kv; # (0 a 1 b 2 c)

I will be copying this down in my list of examples.  Note that
I made the point that Perl starts counting at zero not one.

-T



$ cat ./LoopIndexTest.pl6
#!/usr/bin/perl6

my @x = ( "a", "b", "c", "d" );

for @x.kv -> $index, $value {
   print "   Line no. <" ~ ($index + 1) ~
   "> has an index of <$index> and a value of <$value>\n"; }



$ ./LoopIndexTest.pl6
   Line no. <1> has an index of <0> and a value of 
   Line no. <2> has an index of <1> and a value of 
   Line no. <3> has an index of <2> and a value of 
   Line no. <4> has an index of <3> and a value of 


Re: for loop index question

2017-02-28 Thread Todd Chester



On Tue, Feb 28, 2017 at 01:20:47PM -0800, ToddAndMargo wrote:

Hi All,

There are times when I want to know th4e index of an array
when I am in a "for @array" loop.  I can do it with a
variable outside the for loop and increment it, but
I would line to know know if there is a way to incorporate
it in the loop command.

This is my long winded way of doing it in Perl 5:

while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }


Many thanks,
-T



On 02/28/2017 01:23 PM, Patrick R. Michaud wrote:
> I think the canonical Perl 6 answer is:
>
> for @array.kv -> $index, $value { do something }
>
> Pm

Thank you!


Re: debugging and HookGrammar

2017-02-28 Thread Elizabeth Mattijsen
> On 28 Feb 2017, at 22:28, Theo van den Heuvel  wrote:
> Elizabeth Mattijsen schreef op 2017-02-28 20:29:
>> That was the consensus on the #perl6-dev channel:
>> https://irclog.perlgeek.de/perl6-dev/2017-02-28#i_14181744
>> Liz
> 
> I wasn't aware of this. Thanks

You’re welcome.

If you want more direct feedback, the #perl6 channel on irc.freenode.org is a 
good place to try as the first line.  #perl6-dev would be a place to check if 
the people on #perl6 don’t have an answer.



Liz

Re: for loop index question

2017-02-28 Thread yary
Maybe using placeholder variables was a bit too much (those variables with
the ^ twigil)

> for @a.kv -> $k, $v { say "Value $v has index $k" }
Value g has index 0
Value h has index 1
Value i has index 2
Value j has index 3
Value k has index 4


Re: debugging and HookGrammar

2017-02-28 Thread Theo van den Heuvel

Elizabeth Mattijsen schreef op 2017-02-28 20:29:

That was the consensus on the #perl6-dev channel:

https://irclog.perlgeek.de/perl6-dev/2017-02-28#i_14181744


Liz


I wasn't aware of this. Thanks

--
Theo van den Heuvel


Re: for loop index question

2017-02-28 Thread yary
> my @a = ( 'g' .. 'k' )
[g h i j k]
> @a.kv
(0 g 1 h 2 i 3 j 4 k)
> for @a.kv { say "Value $^v has index $^i" }
Value g has index 0
Value h has index 1
Value i has index 2
Value j has index 3
Value k has index 4


Re: for loop index question

2017-02-28 Thread Elizabeth Mattijsen
> On 28 Feb 2017, at 22:20, ToddAndMargo  wrote:
> 
> Hi All,
> 
> There are times when I want to know th4e index of an array
> when I am in a "for @array" loop.  I can do it with a
> variable outside the for loop and increment it, but
> I would line to know know if there is a way to incorporate
> it in the loop command.
> 
> This is my long winded way of doing it in Perl 5:
> 
> while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }

use .kv:

$ 6 'my @a = ; for @a.kv -> $index,$value { dd $index, $value }'
Int $index = 0
Str $value = "a"
Int $index = 1
Str $value = "b"
Int $index = 2
Str $value = “c"

Mind you, you can actually chain that with your sort:

$ 6 'my @a = ; for @a.sort.kv -> $index,$value { dd $index, $value }'
Int $index = 0
Str $value = "a"
Int $index = 1
Str $value = "b"
Int $index = 2
Str $value = “c"

HTH,

Liz

Re: for loop index question

2017-02-28 Thread Patrick R. Michaud
I think the canonical Perl 6 answer is:

for @array.kv -> $index, $value { do something }

Pm

On Tue, Feb 28, 2017 at 01:20:47PM -0800, ToddAndMargo wrote:
> Hi All,
> 
> There are times when I want to know th4e index of an array
> when I am in a "for @array" loop.  I can do it with a
> variable outside the for loop and increment it, but
> I would line to know know if there is a way to incorporate
> it in the loop command.
> 
> This is my long winded way of doing it in Perl 5:
> 
> while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }
> 
> 
> Many thanks,
> -T
> 
> 
> 
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~


Net::SMTP attachments?

2017-02-28 Thread ToddAndMargo

Hi All,

Anyone know how to do an attachment with Net::SMTP.
I need to attach a tar ball.

I see this is Thunderbird's message source, but ..



--0__=0ABB0A53DFD693F18f9e8a93df938690918c0ABB0A53DFD693F1
Content-type: image/gif;
name="pic15602.gif"
Content-Disposition: attachment; filename="pic15602.gif"
Content-transfer-encoding: base64



Many thanks,
-T

--
~~~
Having been erased,
The document you're seeking
Must now be retyped.
~~~


Re: Terminal::ANSIColor problem

2017-02-28 Thread ToddAndMargo

On 02/28/2017 12:53 PM, Brandon Allbery wrote:

On Tue, Feb 28, 2017 at 3:46 PM, ToddAndMargo > wrote:

On 02/28/2017 04:11 AM, yary wrote:


On Tue, Feb 28, 2017 at 12:53 AM, ToddAndMargo

>>
wrote:

sub PrintRed   ( $Str ) { print color('bold'), color('red'),
 "$Str", color('reset'); }
sub PrintGreen ( $Str ) { print color('bold'), color('green'),
"$Str", color('reset'); }
sub PrintBlue  ( $Str ) { print color('bold'), color('blue'),
"$Str", color('reset'); }


You don't need the double quotes around $Str- not even in Perl5!


I think I am blind, but I am not finding the extra ()


Doublequotes are " " not ( ). (language... bracket confusion is far too
common) It's the `, "$Str",`, that can just be `, $Str,`.



Oh I get it now.  I was confused () with "".
The guys over on the chat line keep telling me "death to parenthesis!",
so I was in the mode!

:-)

Thank you both for the help!

-T


Re: Terminal::ANSIColor problem

2017-02-28 Thread ToddAndMargo

On 02/28/2017 04:11 AM, yary wrote:


On Tue, Feb 28, 2017 at 12:53 AM, ToddAndMargo > wrote:

sub PrintRed   ( $Str ) { print color('bold'), color('red'),
 "$Str", color('reset'); }
sub PrintGreen ( $Str ) { print color('bold'), color('green'),
"$Str", color('reset'); }
sub PrintBlue  ( $Str ) { print color('bold'), color('blue'),
"$Str", color('reset'); }


You don't need the double quotes around $Str- not even in Perl5!


I think I am blind, but I am not finding the extra ()

:'(



sub PrintRed   ( $Str ) { print color('bold'), color('red'),  $Str,
color('reset'); }

The module examples imply that you can combine color strings, does this
work?

sub PrintRed   ( $Str ) { print color('bold red'),  $Str, color('reset'); }

And there's a helper routine "colored" that combines the color, string,
and reset (I think, I don't have the module installed to test, again
this is from reading the examples)

sub PrintRed   ( $Str ) { print colored($Str, 'bold red'); }


say colored("IM IN UR MODULE MESSING WITH UR COLOURS",
"bold green on_blue");


-y



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


Re: debugging and HookGrammar

2017-02-28 Thread Elizabeth Mattijsen
That was the consensus on the #perl6-dev channel:

https://irclog.perlgeek.de/perl6-dev/2017-02-28#i_14181744


Liz

> On 28 Feb 2017, at 15:24, Theo van den Heuvel  wrote:
> 
> Hi Will,
> 
> I reinstalled without rakudobrew. It helped. I will probably never know what 
> I did wrong with rakudobrew (possible traces of an older install).
> 
> thanks,
> 
> Theo
> 
> Will Coleda schreef op 2017-02-28 14:37:
>> FYI, rakudobrew is not recommend for users.
>> You could try "rakudobrew rehash", though I'm not sure if that will
>> help in this case.
>> On Tue, Feb 28, 2017 at 7:55 AM, Theo van den Heuvel
>>  wrote:
>>> hi everyone,
>>> last week I used rakudobrew to update my Perl6 installation on Ubuntu.
>>>  This is Rakudo version 2017.02-106-gdd4dfb1 built on MoarVM version
>>> 2017.02-7-g3d85900
>>>  implementing Perl 6.c.
>>> Now, whenever I try perl6-debug-m I get
>>>  Cannot find method 'setlang' on object of type Perl6::HookGrammar
>>>   at gen/moar/perl6-debug.nqp:407
>>> (/home/theo/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6-debug.moarvm:comp_unit)
>>> followed by a slew of other nqp stuff. Is there something wrong with my
>>> installation? Suggestions for repair?
>>> Thanks,
>>> --
>>> Theo van den Heuvel
>>> Malden, The Netherlands
> 
> -- 
> Theo van den Heuvel
> Van den Heuvel HLT Consultancy
> Malden, The Netherlands
> +31 24 3736356
> +31 625492788


Re: debugging and HookGrammar

2017-02-28 Thread Brandon Allbery
On Tue, Feb 28, 2017 at 9:24 AM, Theo van den Heuvel 
wrote:

> I reinstalled without rakudobrew. It helped. I will probably never know
> what I did wrong with rakudobrew (possible traces of an older install).


One thing it does wrong is it doesn't fetch tags for its repos, with the
result that upgrades sometimes get "stuck" using mismatched revisions of
moar/nqp/rakudo because it never realizes there's an upgrade out there.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: debugging and HookGrammar

2017-02-28 Thread Theo van den Heuvel

Hi Will,

I reinstalled without rakudobrew. It helped. I will probably never know 
what I did wrong with rakudobrew (possible traces of an older install).


thanks,

Theo

Will Coleda schreef op 2017-02-28 14:37:

FYI, rakudobrew is not recommend for users.

You could try "rakudobrew rehash", though I'm not sure if that will
help in this case.

On Tue, Feb 28, 2017 at 7:55 AM, Theo van den Heuvel
 wrote:

hi everyone,

last week I used rakudobrew to update my Perl6 installation on Ubuntu.

  This is Rakudo version 2017.02-106-gdd4dfb1 built on MoarVM version
2017.02-7-g3d85900
  implementing Perl 6.c.

Now, whenever I try perl6-debug-m I get

  Cannot find method 'setlang' on object of type Perl6::HookGrammar
   at gen/moar/perl6-debug.nqp:407
(/home/theo/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6-debug.moarvm:comp_unit)

followed by a slew of other nqp stuff. Is there something wrong with 
my

installation? Suggestions for repair?

Thanks,


--
Theo van den Heuvel
Malden, The Netherlands


--
Theo van den Heuvel
Van den Heuvel HLT Consultancy
Malden, The Netherlands
 +31 24 3736356
 +31 625492788


Re: debugging and HookGrammar

2017-02-28 Thread Will Coleda
FYI, rakudobrew is not recommend for users.

You could try "rakudobrew rehash", though I'm not sure if that will
help in this case.

On Tue, Feb 28, 2017 at 7:55 AM, Theo van den Heuvel
 wrote:
> hi everyone,
>
> last week I used rakudobrew to update my Perl6 installation on Ubuntu.
>
>   This is Rakudo version 2017.02-106-gdd4dfb1 built on MoarVM version
> 2017.02-7-g3d85900
>   implementing Perl 6.c.
>
> Now, whenever I try perl6-debug-m I get
>
>   Cannot find method 'setlang' on object of type Perl6::HookGrammar
>at gen/moar/perl6-debug.nqp:407
> (/home/theo/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6-debug.moarvm:comp_unit)
>
> followed by a slew of other nqp stuff. Is there something wrong with my
> installation? Suggestions for repair?
>
> Thanks,
>
>
> --
> Theo van den Heuvel
> Malden, The Netherlands



-- 
Will "Coke" Coleda


debugging and HookGrammar

2017-02-28 Thread Theo van den Heuvel

hi everyone,

last week I used rakudobrew to update my Perl6 installation on Ubuntu.

  This is Rakudo version 2017.02-106-gdd4dfb1 built on MoarVM version 
2017.02-7-g3d85900

  implementing Perl 6.c.

Now, whenever I try perl6-debug-m I get

  Cannot find method 'setlang' on object of type Perl6::HookGrammar
   at gen/moar/perl6-debug.nqp:407  
(/home/theo/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6-debug.moarvm:comp_unit)


followed by a slew of other nqp stuff. Is there something wrong with my 
installation? Suggestions for repair?


Thanks,


--
Theo van den Heuvel
Malden, The Netherlands