From mark at purdue.edu Thu Aug 2 05:19:47 2018 From: mark at purdue.edu (Mark Senn) Date: Thu, 02 Aug 2018 08:19:47 -0400 Subject: [Purdue-pm] Perl 6 precompiles modules Message-ID: <5942.1533212387@pier.ecn.purdue.edu> >From https://docs.perl6.org/language/faq What is Precompilation? When you load a module for the first time, Rakudo compiles it into bytecode, and both stores it on disk, and uses the compiled bytecode. On subsequent loads, Rakudo prefers to load the bytecode, because that tends to be significantly faster. >From https://rakudo.org/ "Rakudo" is short for "Rakuda-d?" (with a long 'o'; ???), which is Japanese for "Way of the Camel". "Rakudo" (with a short 'o'; ??) also means "paradise" in Japanese. Rakudo Perl 6 Compiler Production-ready, stable implementation of the Perl 6 language. The _Programming Perl_ book is also known as the "Camel Book" because it has a camel on the cover. Mark Senn, Systems Programmer, Engineering Computer Network, Purdue University From mark at purdue.edu Thu Aug 2 19:31:36 2018 From: mark at purdue.edu (Mark Senn) Date: Thu, 02 Aug 2018 22:31:36 -0400 Subject: [Purdue-pm] an example Perl 6 program Message-ID: <17327.1533263496@pier.ecn.purdue.edu> Below is an example Perl 6 program. Thought you might be interested. -mark #!/home/pier/e/mark/sw/rakudo-star-2018.04/bin/perl6 # Print an error message if we're using Perl 5. use v6; sub MAIN(Bool :$h) { # Was "-h" option given on command line? ($h) and do { # Print "Usage: password" on standard error. $*ERR.say('Usage: password'); exit 1; } # Set @char array to 0...9, A...Z, a...z. my @char = ('0'...'9', 'A'...'Z', 'a'...'z'); # Set @password array to 9 through 16 random elements of @char. my @password = @char.pick xx (9...16).pick; # Print the 9 to 16 character password. say join '', @password; } From jacoby.david at gmail.com Tue Aug 21 08:57:41 2018 From: jacoby.david at gmail.com (Dave Jacoby) Date: Tue, 21 Aug 2018 11:57:41 -0400 Subject: [Purdue-pm] Subroutine Attributes, or it's all my fault. Message-ID: I won't start in on why I started looking at attributes (blame Matt S. Trout), but in looking at them, PerlTricks has a post showing how you can assign to a function like a variable by setting lvalue. I played with it some to get this: package Foo; use Scalar::Util qw(looks_like_number); sub new { bless {}, shift } sub iterate : lvalue { my $self = shift; $self->{iterate} = 0 if !defined $self->{iterate} || !looks_like_number( $self->{iterate} ); $self->{iterate} ++ ; $self->{iterate}; } This allows this: my $i = Foo->new(); $i->iterate = 11; while ( my $ii = $i->iterate ) { say qq{\t$ii} ; last if $ii >= 20; } Which gives us this: 12 13 14 15 16 17 18 19 20 To reiterate, you would expect $i->iterate(11), not $i->iterate = 11 . This is a small change, and I might not ever use this in real life -- esp., if mst said (I think) that there's a problem with signature and attribute order recently, meaning I couldn't write sub function ( $x ) { code } anymore. But... my $i = Foo->new(); $i->iterate = -4; while ( my $ii = $i->iterate ) { say qq{\t$ii} ; last if $ii >= 20; } gives use -3 -2 -1 Something in Foo::iterate stops at 0. Zero should be defined. Zero should look like a number. Can anyone see the "stop iterating at zero" bug in my "toy code; don't use in production" iterator? -- Dave Jacoby jacoby.david at gmail.com Don't panic when the crisis is happening, or you won't enjoy it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacoby.david at gmail.com Tue Aug 21 09:05:02 2018 From: jacoby.david at gmail.com (Dave Jacoby) Date: Tue, 21 Aug 2018 12:05:02 -0400 Subject: [Purdue-pm] Subroutine Attributes, or it's all my fault. In-Reply-To: References: Message-ID: Duh! while ( my $ii = $i->iterate ) {} is judged on $ii, and if $ii == 0, it is based on the value of $ii , not of defined $ii. So while (1) { my $ii = $i->iterate; ... } On Tue, Aug 21, 2018 at 11:57 AM Dave Jacoby wrote: > I won't start in on why I started looking at attributes (blame Matt S. > Trout), but > in looking at them, PerlTricks has a post showing how you can assign to a > function like a variable by setting lvalue. > > I played with it some to get this: > package Foo; > use Scalar::Util qw(looks_like_number); > sub new { bless {}, shift } > sub iterate : lvalue { > my $self = shift; > $self->{iterate} = 0 > if !defined $self->{iterate} > || !looks_like_number( $self->{iterate} ); > $self->{iterate} ++ ; > $self->{iterate}; > } > > This allows this: > > my $i = Foo->new(); > $i->iterate = 11; > while ( my $ii = $i->iterate ) { > say qq{\t$ii} ; > last if $ii >= 20; > } > > Which gives us this: > > 12 > 13 > 14 > 15 > 16 > 17 > 18 > 19 > 20 > > To reiterate, you would expect $i->iterate(11), not $i->iterate = 11 . > > This is a small change, and I might not ever use this in real life -- > esp., if mst said (I think) that there's a problem with signature and > attribute order recently, meaning I couldn't write sub function ( $x ) { > code } anymore. > > But... > > my $i = Foo->new(); > $i->iterate = -4; > while ( my $ii = $i->iterate ) { > say qq{\t$ii} ; > last if $ii >= 20; > } > > gives use > > -3 > -2 > -1 > > Something in Foo::iterate stops at 0. Zero should be defined. Zero should > look like a number. > > Can anyone see the "stop iterating at zero" bug in my "toy code; don't use > in production" iterator? > -- > Dave Jacoby > jacoby.david at gmail.com > > Don't panic when the crisis is happening, or you won't enjoy it. > -- Dave Jacoby jacoby.david at gmail.com Don't panic when the crisis is happening, or you won't enjoy it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacoby.david at gmail.com Fri Aug 31 13:56:47 2018 From: jacoby.david at gmail.com (Dave Jacoby) Date: Fri, 31 Aug 2018 16:56:47 -0400 Subject: [Purdue-pm] This has to be a thing in sed or something that I just didn't know, right? Message-ID: I know grep gives you the lines and line numbers grep jacoby -sil * But what if you wanted to match them and just them? Like, for example, you wanted to pull all the perl scripts out of your crontab? crontab -l | match -r '([\w\.\/]*.pl)' Which you can then sort or sort -u to just see those files. #!/usr/bin/env perl use strict ; use warnings ; use utf8 ; use feature qw{ postderef say signatures state } ; no warnings qw{ experimental::postderef experimental::signatures } ; use Getopt::Long ; my $regex ; GetOptions( 'regex=s' => \$regex ); exit unless defined $regex; my @output; while () { push @output , $_ =~ m{$regex}gmix; } say join "\n", @output; If there's a regular thing and I just never learned the right Unix-fu, I'd love to know. -- Dave Jacoby jacoby.david at gmail.com Don't panic when the crisis is happening, or you won't enjoy it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at ecn.purdue.edu Fri Aug 31 16:15:41 2018 From: mark at ecn.purdue.edu (Mark Senn) Date: Fri, 31 Aug 2018 19:15:41 -0400 Subject: [Purdue-pm] This has to be a thing in sed or something that I just didn't know, right? In-Reply-To: References: Message-ID: <19356.1535757341@pier.ecn.purdue.edu> > crontab -l | match -r '([\w\.\/]*.pl)' Tested using GNU grep 2.20 and 3.1: crontab -l | grep -oP '[\w./]*\.pl' -mark