Help with Perl 6 script
Greetings I have this Perl 6 script from Rosetta, which I wanted to run on Perl 5 (due to the Active Sate Perl and App version that I have). However, several syntax errors appear given the difference (some) in language.Here's the script: --- # Simple Vector implementation multi infix:<+>(@a, @b) { @a Z+ @b } multi infix:<->(@a, @b) { @a Z- @b } multi infix:<*>($r, @a) { $r X* @a } multi infix:(@a, $r) { @a X/ $r } sub norm { sqrt [+] @_ X** 2 } # Runge-Kutta stuff sub runge-kutta(&yp) { return -> \t, \y, \δt { my $a = δt * yp( t, y ); my $b = δt * yp( t + δt/2, y + $a/2 ); my $c = δt * yp( t + δt/2, y + $b/2 ); my $d = δt * yp( t + δt, y + $c ); ($a + 2*($b + $c) + $d) / 6; } } # gravitational constant constant G = 6.674e-11; # astronomical unit constant au = 150e9; # time constants in seconds constant year = 365.25*24*60*60; constant month = 21*24*60*60; # masses in kg constant $ma = 2e30; # Sun constant $mb = 6e24; # Earth constant $mc = 7.34e22; # Moon my &dABC = runge-kutta my &f = sub ( $t, @ABC ) { my @a = @ABC[0..2]; my @b = @ABC[3..5]; my @c = @ABC[6..8]; my $ab = norm(@a - @b); my $ac = norm(@a - @c); my $bc = norm(@b - @c); return [ flat @ABC[@(9..17)], map G * *, $mb/$ab**3 * (@b - @a) + $mc/$ac**3 * (@c - @a), $ma/$ab**3 * (@a - @b) + $mc/$bc**3 * (@c - @b), $ma/$ac**3 * (@a - @c) + $mb/$bc**3 * (@b - @c); ]; } loop ( my ($t, @ABC) = 0, 0, 0, 0, # Sun position au, 0, 0,# Earth position 0.998*au, 0, 0, # Moon position 0, 0, 0, # Sun speed 0, 2*pi*au/year, 0, # Earth speed 0, 2*pi*(au/year + 0.002*au/month), 0# Moon speed ; $t < .2; ($t, @ABC) »+=« (.01, dABC($t, @ABC, .01)) ) { printf "t = %.02f : %s\n", $t, @ABC.fmt("%+.3e"); } --- I'm having problem specially in the "multi infix" and even in the "norm" sub routine. The problem is that I do not understand the construction of these in Perl 5 (otherwise, I would translate this easely, and I wouldn't be asking for help...) Any help is apreciated. Clear skies Rui Fernandes
Re: Open and perl sub
Hi Mike, On Thu, 8 Aug 2019 15:40:42 +0100 Mike Martin via beginners wrote: > Is it possible to have the output of a perl module piped to open (open3 in > my case), so I can use a file handle contains the output passed to sysread > > Odd question I know > you can use https://en.wikipedia.org/wiki/Fork_(system_call) , https://duckduckgo.com/?q=dup+unix&atb=v140-1&ia=web , "open >&" , etc. > Thanks -- - Shlomi Fish http://www.shlomifish.org/ Best Introductory Programming Language - http://shlom.in/intro-lang A person with one watch knows what time it is; a person with two watches is never sure. — Proverb [via fortune-mod] Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Open and perl sub
Is it possible to have the output of a perl module piped to open (open3 in my case), so I can use a file handle contains the output passed to sysread Odd question I know Thanks
Re: Install Problems: Net::Google::Spreadsheets
Hi Mike, Thank you very much for the offer, but somebody over at PerlMonks jumped on it and managed to explain the problem and how to overcome it. I'm all installed now. Just the fun of writing the actual script... Here's a link to the solution/work around for anybody curious or stuck in a similar way: https://www.perlmonks.org/?node_id=11104105 Thanks, James On Thu, Aug 8, 2019 at 5:16 AM Mike wrote: > > I believe somebody else responded to this, but . . . > > I'll help if I can. > If you want me to try to install Net::Google::Spreadsheets > I can. I am on Win7 - Strawberry Perl V 5.26.1 > > > Mike > > > On 8/5/2019 9:47 AM, James Kerwin wrote: > > Hi All, > > > > I'm having some difficulty installing a Perl Module; > > Net::Google::Spreadsheets". Inititally it was installing in to my user > > account home directory and I wasn't certain how to change this, so I > > just added the directory to my @INC (this isn't a live server, it's > > purely for me to test on at the moment). > > > > It appears to do a LOT when installing this module and I won't pretend > > to be an expert, but I really want it to work as it would be the > > perfect addition to a script I wrote recently (provides the user with > > a button to extract data from a database and then ideally pushes the > > data to a google sheet). > > > > Would anybody be kind enough to help me troubleshoot this? Here is > > some output (apologies if it's not correctly displayed, I can't > > remember how you all usually request it to be displayed): > > > > Net::IDN::Encode is up to date (2.500). > > HIROSE/Net-Google-Spreadsheets-V4-0.002.tar.gz > > Has already been unwrapped into directory > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X > > HIROSE/Net-Google-Spreadsheets-V4-0.002.tar.gz > > Has already been prepared > > Running Build for H/HI/HIROSE/Net-Google-Spreadsheets-V4-0.002.tar.gz > > Warning: Prerequisite 'Net::Google::DataAPI::Auth::OAuth2 => 0' for > > 'HIROSE/Net-Google-Spreadsheets-V4-0.002.tar.gz' failed when > > processing 'DANJOU/Net-Google-DataAPI-0.2805.tar.gz' with 'make_test > > => NO one dependency not OK (XML::Atom); additionally test harness > > failed'. Continuing, but chances to succeed are limited. > > cp lib/Net/Google/Spreadsheets/V4.pm > > blib/lib/Net/Google/Spreadsheets/V4.pm > > HIROSE/Net-Google-Spreadsheets-V4-0.002.tar.gz > > ./Build -- OK > > Running Build test > > t/00_compile.t .. 1/? > > # Failed test 'use Net::Google::Spreadsheets::V4;' > > # at t/00_compile.t line 4. > > # Tried to use 'Net::Google::Spreadsheets::V4'. > > # Error: Can't locate Net/Google/DataAPI/Auth/OAuth2.pm in @INC > > (you may need to install the Net::Google::DataAPI::Auth::OAuth2 > > module) (@INC contains: > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/arch > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib > > /home/james/.cpan /etc/perl > > /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 > > /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 > > /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 > > /usr/share/perl/5.22 /usr/local/lib/site_perl > > /usr/lib/x86_64-linux-gnu/perl-base .) at > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib/Net/Google/Spreadsheets/V4.pm > > > line 18. > > # BEGIN failed--compilation aborted at > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib/Net/Google/Spreadsheets/V4.pm > > > line 18. > > # Compilation failed in require at t/00_compile.t line 4. > > # BEGIN failed--compilation aborted at t/00_compile.t line 4. > > # Looks like you failed 1 test of 1. > > t/00_compile.t .. Dubious, test returned 1 (wstat 256, 0x100) > > Failed 1/1 subtests > > t/01_new.t .. Can't locate > > Net/Google/DataAPI/Auth/OAuth2.pm in @INC (you may need to install the > > Net::Google::DataAPI::Auth::OAuth2 module) (@INC contains: > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/arch > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib > > /home/james/.cpan /etc/perl > > /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 > > /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 > > /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 > > /usr/share/perl/5.22 /usr/local/lib/site_perl > > /usr/lib/x86_64-linux-gnu/perl-base .) at > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib/Net/Google/Spreadsheets/V4.pm > > > line 18. > > BEGIN failed--compilation aborted at > > > /home/james/.cpan/build/Net-Google-Spreadsheets-V4-0.002-gyJS1X/blib/lib/Net/Google/Spreadsheets/V4.pm > > > line 18. > > Compilation failed in require at t/01_new.t line 4. > > t/01_new.t .. Dubious, test returned 2 (wstat 512, 0x200) > > No subtests run > > t/author-00_basic.t . skipped: these tests are for testing by > > the author > > t/author-criti
AI::PredictionClient question
Hello, Is this module still be maintained actively? https://metacpan.org/pod/AI::PredictionClient I saw the last version was released on 2017. And there is the Inception client sample there, if I want to request a different CNN model, how to build the client? thanks & regards, Eliza C. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to catch die in a module
Hi, On Thu, 8 Aug 2019 08:21:24 +0530 Chankey Pathak wrote: > You can create a signal handler for die and handle the exception in there. > Refer https://users.cs.cf.ac.uk/Dave.Marshall/PERL/node116.html > Also see block eval - https://perldoc.pl/functions/eval - or one of its wrappers like https://metacpan.org/pod/Try::Tiny . Caveat: I maintain https://metacpan.org/pod/Error and recommend against using the latter. > On Thu, 8 Aug, 2019, 8:15 AM Eliza, wrote: > > > Hello, > > > > I use such a module from other people. > > In this module there is the "die" statement, for example, > > > > connect(...) or die $!; > > > > Then my main program will die follow up this "die". > > But I don't want the caller to die even if "die" was happened in the > > module. > > How to handle with it? > > > > Thank you. > > Eliza > > > > -- > > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > > For additional commands, e-mail: beginners-h...@perl.org > > http://learn.perl.org/ > > > > > > -- - Shlomi Fish http://www.shlomifish.org/ Perl Elems to Avoid - http://perl-begin.org/tutorials/bad-elements/ John: Hey, we are completely non-violent vampires. We don’t suck blood. Selina: I thought all vampires suck blood. John: Bullocks, hen. Vampires come in all shapes and sizes. — http://www.shlomifish.org/humour/Selina-Mandrake/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/