Re: Perl 5 list assignment idiom
On Mon, Mar 13, 2017 at 11:32:25AM -0700, Sean McAfee wrote: > In Perl 5 ... > 1 == (my ($script) = $page->find('//script')) > or die "Other than exactly one script element found"; > Can a similar expression that avoids an intermediate array variable be > written in Perl 6? This does that: 1 == ( my $script = {1,}() ).elems or die 'Not a 1 element list.'; Rob
Re: Perl 5 list assignment idiom
The == operator coerces to Numeric, so like: > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|93867233982256) ... } > one-thing.Numeric 1 (mentioned in https://docs.perl6.org/routine/$EQUALS_SIGN$EQUALS_SIGN) I think my does indeed do some fancy precidenting with the assignment. --Brock On Mon, Mar 13, 2017 at 3:56 PM, Sean McAfeewrote: > sub one-thing { return ("hi",) }
Re: Perl 5 list assignment idiom
On Mon, Mar 13, 2017 at 12:37 PM, Will Coledawrote: > Works the same in Perl 6, and you can avoid the parens. Using helper > subs that return one or two item lists, here's some sample code: > > $ perl6 > > sub one-thing { return ("hi",) } > sub one-thing () { #`(Sub|140454852043936) ... } > > 1 == my $script = one-thing > True > > $script > (hi) > > But then: > $script.WHAT (List) In the Perl 5 version, $script is assigned the single element of the returned list. In your code, it refers to the list itself. (Also, wait: It looks like "=" has higher precedence than "=="? Or does the "my" affect the parsing somehow?)
Re: Perl 5 list assignment idiom
Works the same in Perl 6, and you can avoid the parens. Using helper subs that return one or two item lists, here's some sample code: $ perl6 > sub one-thing { return ("hi",) } sub one-thing () { #`(Sub|140454852043936) ... } > 1 == my $script = one-thing True > $script (hi) > sub two-things { return } sub two-things () { #`(Sub|140454852044088) ... } > 1 == my $bar = two-things False > $bar (hi there) On Mon, Mar 13, 2017 at 2:32 PM, Sean McAfeewrote: > In Perl 5, list assignment in scalar context evaluates to the number of list > elements on the right-hand side. That enables an idiom that I rather like: > > 1 == (my ($script) = $page->find('//script')) > or die "Other than exactly one script element found"; > > Can a similar expression that avoids an intermediate array variable be > written in Perl 6? > -- Will "Coke" Coleda
Re: perl 5?
On 11/17/2016 05:34 AM, yary wrote: Addning to Jan's answer, PerlMonks is still a great place for answers on Perl5 topics (and even some Perl6) http://perlmonks.org/ > I still do not have perl 6 support on rhel 7.2 Don't know how much of an "early adopter" you want to be- if that's an option, try building Rakudo from source, so you're not waiting on a package- http://rakudo.org/how-to-get-rakudo/#Installing-Rakudo-Star-Linux -y I do this with Wine-staging. But it iwas a pain in the neck to clear out all the stuff from the RPM. I wonder how much damage directly installing would cause when the rpm finally comes out. Different paths an all. Mixed versions, etc.. -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: perl 5?
On 11/16/2016 11:27 PM, Jan Ingvoldstad wrote: On Thu, Nov 17, 2016 at 8:08 AM, ToddAndMargowrote: Hi All, Would you guys tolerate a perl 5 question every so often? Perl 5 questions that relate to Perl 6 would probably be on topic. If what you want is help with Perl 5 for Perl 5's sake, though, I humbly suggest that using one of the Perl 5 mailing lists, or IRC channels, may be more useful to you. See here for more information: https://lists.perl.org/ http://www.irc.perl.org/channels.html You may also find one of your local Perl communities helpful, see here for more info about that: https://www.perl.org/community.html -- Jan And there is always perl monks, but their site required you hand code in html and has a really bizarre thread mechanism. But they can be very helpful at times too. -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: perl 5?
On Thu, Nov 17, 2016 at 2:08 AM, ToddAndMargowrote: > Would you guys tolerate a perl 5 question every so often? Quite a few of the folks who work on Perl 6 don't know Perl 5, or at least know it only incidentally. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: perl 5?
Addning to Jan's answer, PerlMonks is still a great place for answers on Perl5 topics (and even some Perl6) http://perlmonks.org/ > I still do not have perl 6 support on rhel 7.2 Don't know how much of an "early adopter" you want to be- if that's an option, try building Rakudo from source, so you're not waiting on a package- http://rakudo.org/how-to-get-rakudo/#Installing-Rakudo-Star-Linux -y
Re: perl 5?
On Thu, Nov 17, 2016 at 8:08 AM, ToddAndMargowrote: > Hi All, > > Would you guys tolerate a perl 5 question every so often? > > Perl 5 questions that relate to Perl 6 would probably be on topic. If what you want is help with Perl 5 for Perl 5's sake, though, I humbly suggest that using one of the Perl 5 mailing lists, or IRC channels, may be more useful to you. See here for more information: https://lists.perl.org/ http://www.irc.perl.org/channels.html You may also find one of your local Perl communities helpful, see here for more info about that: https://www.perl.org/community.html -- Jan
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
On 30 May 2015 3:00:25 pm GMT+02:00, Tom Browder tom.brow...@gmail.com wrote: I finally found the Perl 6 version of Perl 5's $0 listed in: tablets.perl6.org/appendix-b-grouped.html#special-variables as '$*EXECUTABLE_NAME', and I expected it to act the same as $0 in Perl 6, but I have two problems with it: 1. When used it yields 'perl6' regardless of the script's name (a bug?). $ cat t.pl #!/usr/bin/env perl6 say $*EXECUTABLE_NAME; $ chmod +x t.pl $ ./t.pl perl6 2. It seems very ungainly to go from two characters to 17. Couldn't it be shortened a bit, say, '$*0' or '$*EXE_NAME' or '$*PROG' or something else? Am I doing something wrong or do I have the wrong expectations? $ perl6 --version This is perl6 version 2015.03-48-g9746e88 built on MoarVM version 2015.03 Best regards, -Tom Hi Tom, I believe what you are looking for is called $*PROGRAM_NAME. See also http://doc.perl6.org/language/variables#Special_Variables Cheers, Paul
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
On Sat, May 30, 2015 at 8:30 AM, Tobias Leich em...@froggs.de wrote: Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Tobias, I didn't find $*PROGRAM in the doc listed by Paul: http://doc.perl6.org/language/variables#Special_Variables Also, the following were not in: http://tablets.perl6.org/appendix-a-index.html that I could find. $*EXECUTABLE_NAME $*PROGRAM $*PROGRAM_NAME From a Perl 6 newbie standpoint, it looks like there are too many docs with overlapping purposes referenced on perl.org and which, confusingly, have different pieces missing. Except for the Synopses, I'm not sure what document to go to for the definitive answer. And, as usual, I have no suggestions for an easy fix. Thanks Paul and Tobias. Best, -Tom
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
Hi Tom, On Sat, May 30, 2015 at 09:03:17AM -0500, Tom Browder wrote: On Sat, May 30, 2015 at 8:30 AM, Tobias Leich em...@froggs.de wrote: Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Tobias, I didn't find $*PROGRAM in the doc listed by Paul: http://doc.perl6.org/language/variables#Special_Variables Also, the following were not in: http://tablets.perl6.org/appendix-a-index.html that I could find. $*EXECUTABLE_NAME $*PROGRAM $*PROGRAM_NAME the docs at tablets.perl6.org aren't as up to date as those on doc.perl6.org. The doc.perl6.org docs are currently the reference work for Perl6, however please note that they are very much a work in progress. From a Perl 6 newbie standpoint, it looks like there are too many docs with overlapping purposes referenced on perl.org and which, confusingly, have different pieces missing. Except for the Synopses, I'm not sure what document to go to for the definitive answer. And, as usual, I have no suggestions for an easy fix. This I can understand. We're doing our best to provide current and accurate documentation. Perl6 is a very large language, and thus gaps in the documentation are to be expected; especially considering the volunteer based nature of the project. Thanks for pointing out the $*PROGRAM omission! I've just added it to the list of special variables and it should be available online within the next 10-15 minutes. Kind regards, Paul
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Am 30.05.2015 um 15:00 schrieb Tom Browder: I finally found the Perl 6 version of Perl 5's $0 listed in: tablets.perl6.org/appendix-b-grouped.html#special-variables as '$*EXECUTABLE_NAME', and I expected it to act the same as $0 in Perl 6, but I have two problems with it: 1. When used it yields 'perl6' regardless of the script's name (a bug?). $ cat t.pl #!/usr/bin/env perl6 say $*EXECUTABLE_NAME; $ chmod +x t.pl $ ./t.pl perl6 2. It seems very ungainly to go from two characters to 17. Couldn't it be shortened a bit, say, '$*0' or '$*EXE_NAME' or '$*PROG' or something else? Am I doing something wrong or do I have the wrong expectations? $ perl6 --version This is perl6 version 2015.03-48-g9746e88 built on MoarVM version 2015.03 Best regards, -Tom
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
On Sat, May 30, 2015 at 9:03 AM, Tom Browder tom.brow...@gmail.com wrote: On Sat, May 30, 2015 at 8:30 AM, Tobias Leich em...@froggs.de wrote: Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Tobias, I didn't find $*PROGRAM in the doc listed by Paul: But it is the only one of the group I found in Synopsis 28 (Special names). In S28 I did find the Perl 5 to Perl 6 translation table in which I had overlooked $0 before. -Tom
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
Hi, On 05/30/2015 04:36 PM, Paul Cochrane wrote: Thanks for pointing out the $*PROGRAM omission! I've just added it to the list of special variables and it should be available online within the next 10-15 minutes. Minor nit pick: according to the last log on http://doc.perl6.org/build-log/ building the docs alone takes ~17min; the cron job runs every 5 minutes, so it's more likely 17-22min before it becomes available :-) And thanks for adding $*PROGRAM to the docs! Cheers, Moritz