Re: IO::Socket::Multicast::mcast_send
A I managed to find the problem thanks to somebody else finding it late last year. With the particular verison of Perl on the Pi (I think I said 5.28) there is a bug for the IO::Socket::Multicast module: https://rt.cpan.org/Public/Bug/Display.html?id=130581 To fix it I went in to where the Multicast.pm file lives and implemented the suggested changes. I know the correct thing to do was probably to make a local copy of the file and point to it, or switch to a younger version of Perl, but it's a personal project on a Pi that I'm likely to wipe in a few months. Script(s) work now! Thanks for the help. James On Sun, Apr 5, 2020 at 4:03 PM Shlomi Fish wrote: > Hi James, > > On Sun, 5 Apr 2020 14:58:26 +0100 > James Kerwin wrote: > > > Hi All, > > > > I'm trying to connect to a smart bulb on my home WIFI using mcast_send > > in IO::Socket::Multicast. > > > > It works on my main Linux Mint laptop. The same script does not work on > my > > Raspberry PI. > > > > Despite the script running as expected on one laptop I've checked that > this > > is all set up correctly: > > > > sub new { > > #my $class = shift; > > my $data = { > > address => '239.255.255.250', > > port=> 1982, > > timeout => 3, > > devices => [], > > }; > > return bless( $data ); > > } > > > > It is a good idea to use bless with an explicit package name or just use > https://metacpan.org/pod/Moo or Moose or similar. > > > my $socket = IO::Socket::Multicast->new( > > PeerAddr => $self->{address}, > > PeerPort => $self->{port}, > > Proto => "udp", > > ReuseAddr => 1, > > ) or croak $!; > > > > But it's this part that fails on the PI: > > > > A few things to check: > > 1. Which OS/distro/version and perl version on both machines? > > 2. Does it happen with the latest stable perl installed from source? > > 3. Did you try using https://en.wikipedia.org/wiki/GDB and/or perl -d: > https://perl-begin.org/topics/debugging/ ? > > 4. Is there anything in the rpi's firewall config? > > For more advice, see > https://github.com/shlomif/writing-the-perfect-question . > > > $socket->mcast_send( $query, "$self->{address}:$self->{port}" ) or croak > $!; > > > > I've checked that $socket, $query and $self->{address}:$self->{port} > > contain the info I expect and they do. > > > > On my Linux laptop I can use tcpdump and see the communication between > > laptop and bulb. Doing this on the Pi shows no communication. I've > replaced > > the "croak" with "die "" so I can be certain it's failing at > > that point. I get the output "" (makes it easier to spot). > > > > I've just used a command recently that allows me to access the specific > ip > > and port of the lamp and it indicates the connection is successful. I'm > out > > of ideas and if anyone can advise I'd appreciate it. > > > > Slightly (very) out of my depth when it comes to ports and IPs etc. > > > > Thanks, > > James > > > > -- > > Shlomi Fish https://www.shlomifish.org/ > https://github.com/shlomif/validate-your-html - Validate Your HTML >
Re: IO::Socket::Multicast::mcast_send
Hi thanks for the response. Before I continue, at the top of the script I first borrowed for this it had "use 5.026;". When I remove this and then alter any "say" or "break" etc that appear the scripts continue to work as before; Mint laptop works, Pi does not. 1) For PI: Pi Raspbian GNU/Linux 10 (buster). Perl Version: v5.28.1 (installed with OS). ufw is not installed. I don't THINK any other firewalls are installed. I haven't installed any and I don't think there's one by default. This was a fresh install of Rasbpian done just this week. Looking at iptables: $ sudo iptables -L -nv Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination For Linux: Linux Mint 18 (Sarah) Perl: v5.26.0 (switched using perlbrew if memory serves me correctly. Some modules wouldn't install due to the Perl version that came with the OS). ufw is disabled. When I activate it the script does not work, but it doesn't give an error pointing at the line where $socket->mcast_send is called, as it does on the pi. iptables gives a massive output. 2) I have not tried it with the latest stable version of Perl, partly because I have several different versions of Perl where it does/doesn't work and I'd mentally ruled out the Perl version. For example it doesn't work with the Perl on my Windows laptop, but doesn't give an error so my suspicion there is it's something firewall related. 3) I will check out those links. I've just quickly looked through the script on the laptop with the debugger. I'll go check with the pi when I can get back on it (plugged in to TV, Tv in use). 4) Mentioned this in 1. I'll keep at it for now, and keep trying things. I am able to identify the bulb when I log into the router and can directly ping the ip from the laptop and pi. Thanks, James On Sun, Apr 5, 2020 at 4:03 PM Shlomi Fish wrote: > Hi James, > > On Sun, 5 Apr 2020 14:58:26 +0100 > James Kerwin wrote: > > > Hi All, > > > > I'm trying to connect to a smart bulb on my home WIFI using mcast_send > > in IO::Socket::Multicast. > > > > It works on my main Linux Mint laptop. The same script does not work on > my > > Raspberry PI. > > > > Despite the script running as expected on one laptop I've checked that > this > > is all set up correctly: > > > > sub new { > > #my $class = shift; > > my $data = { > > address => '239.255.255.250', > > port=> 1982, > > timeout => 3, > > devices => [], > > }; > > return bless( $data ); > > } > > > > It is a good idea to use bless with an explicit package name or just use > https://metacpan.org/pod/Moo or Moose or similar. > > > my $socket = IO::Socket::Multicast->new( > > PeerAddr => $self->{address}, > > PeerPort => $self->{port}, > > Proto => "udp", > > ReuseAddr => 1, > > ) or croak $!; > > > > But it's this part that fails on the PI: > > > > A few things to check: > > 1. Which OS/distro/version and perl version on both machines? > > 2. Does it happen with the latest stable perl installed from source? > > 3. Did you try using https://en.wikipedia.org/wiki/GDB and/or perl -d: > https://perl-begin.org/topics/debugging/ ? > > 4. Is there anything in the rpi's firewall config? > > For more advice, see > https://github.com/shlomif/writing-the-perfect-question . > > > $socket->mcast_send( $query, "$self->{address}:$self->{port}" ) or croak > $!; > > > > I've checked that $socket, $query and $self->{address}:$self->{port} > > contain the info I expect and they do. > > > > On my Linux laptop I can use tcpdump and see the communication between > > laptop and bulb. Doing this on the Pi shows no communication. I've > replaced > > the "croak" with "die "" so I can be certain it's failing at > > that point. I get the output "" (makes it easier to spot). > > > > I've just used a command recently that allows me to access the specific > ip > > and port of the lamp and it indicates the connection is successful. I'm > out > > of ideas and if anyone can advise I'd appreciate it. > > > > Slightly (very) out of my depth when it comes to ports and IPs etc. > > > > Thanks, > > James > > > > -- > > Shlomi Fish https://www.shlomifish.org/ > https://github.com/shlomif/validate-your-html - Validate Your HTML >
IO::Socket::Multicast::mcast_send
Hi All, I'm trying to connect to a smart bulb on my home WIFI using mcast_send in IO::Socket::Multicast. It works on my main Linux Mint laptop. The same script does not work on my Raspberry PI. Despite the script running as expected on one laptop I've checked that this is all set up correctly: sub new { #my $class = shift; my $data = { address => '239.255.255.250', port=> 1982, timeout => 3, devices => [], }; return bless( $data ); } my $socket = IO::Socket::Multicast->new( PeerAddr => $self->{address}, PeerPort => $self->{port}, Proto => "udp", ReuseAddr => 1, ) or croak $!; But it's this part that fails on the PI: $socket->mcast_send( $query, "$self->{address}:$self->{port}" ) or croak $!; I've checked that $socket, $query and $self->{address}:$self->{port} contain the info I expect and they do. On my Linux laptop I can use tcpdump and see the communication between laptop and bulb. Doing this on the Pi shows no communication. I've replaced the "croak" with "die "" so I can be certain it's failing at that point. I get the output "" (makes it easier to spot). I've just used a command recently that allows me to access the specific ip and port of the lamp and it indicates the connection is successful. I'm out of ideas and if anyone can advise I'd appreciate it. Slightly (very) out of my depth when it comes to ports and IPs etc. Thanks, James
Re: Google Sheets API Data Structure
Thanks Dave and Mike, I am using Net::Google::Spreadsheets and all the associated modules and yeah there I slept on this and then managed to see what could be seen this morning: print Dumper($ws[0]{atom}); print Dumper($ws[0]{container}); I should have been a bit clearer on what I was hoping to do (although I think it can't be easily done) by digging around for what was there and you're right that I should use the methods provided. I did start with a method that allowed me to grab a list of the worksheet names, so I thought if I looked around I might find a list of worksheet "gid's" It's just that the methods provided don't seem to do what I want. Each worksheet within a spreadsheet has its own "gid" in the URL of that particular worksheet. I was trying to find either the URL or gid value in order to provide a link directly to a newly created worksheet. At the moment I've used a link to the spreadsheet and the user must navigate to the new worksheet. It's not a huge issue, but it would have been a nice finish for what I was doing. It's already better than it was. Previously a user had to log on via the command line. Run a series of scripts, mv/cp files around, then download a csv file from the server and then copy the content to the Google Sheet. Now a user goes to the website, clicks a button and then a few seconds later receives a link to the spreadsheet. I'm currently looking around Worksheet.pm to see if there's any module/function I could create that could get help me, but I think I may need to admit that it's quite a bit beyond me. Thanks, James
Google Sheets API Data Structure
Hi All, I managed to get the Google Sheets API Perl module working. I'm currently investigating a data structure that it gives me to see what values I can get from it. Through random experimentation I've managed to find that it had "title" and "id". I wrote this to get the data structure containing the worksheets: my @ws = $spreadsheet->worksheets; Now if I do: print $ws[1]->id; print $ws[1]->title; I get the value in the id and the title for the specific item in the array. I want to know what other information is in there. If I do this: for my $href (@ws) { print "{ "; for my $role (keys %{ $href }) { print "$role=$href->{$role} "; } print "}\n"; } I get: { atom=XML::Atom::Entry=HASH(0x1b81928) container=Net::Google::Spreadsheets::Spreadsheet=HASH(0x1bbdb80) } { atom=XML::Atom::Entry=HASH(0x1bbbe98) container=Net::Google::Spreadsheets::Spreadsheet=HASH(0x1bbdb80) } { container=Net::Google::Spreadsheets::Spreadsheet=HASH(0x1bbdb80) atom=XML::Atom::Entry=HASH(0x1b86ca0) } { container=Net::Google::Spreadsheets::Spreadsheet=HASH(0x1bbdb80) atom=XML::Atom::Entry=HASH(0x1b86988) } { container=Net::Google::Spreadsheets::Spreadsheet=HASH(0x1bbdb80) atom=XML::Atom::Entry=HASH(0x1b8c958) } If I use Dumper it just seems to output SO MUCH information that I can't see the wood for the trees. Maybe I'm just tired after a dramatic day in Perl land. Can anyone help me untangle this? My spreadsheet has five worksheets and there are five lines in my output so my assumption is that each line represents a sheet. Any advice/help/guidance would be greatly appreciated. Thanks, James
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-Spr
Re: Install Problems: Net::Google::Spreadsheets
Thanks Shlomi, That was helpful. It transpires that I added nothing to my @INC, not permanently. A complete misunderstanding on my part. I went through the CPAN set-up again and paid slightly more attention. I managed to get some things installed, but one dependency keeps on failing tests: Net::Google::DataAPI::Auth::OAuth2 At least one other person has experienced the same issues as myself, but there do not appear to be any solutions to it. Each failed test appears to start with what I think is a test function named "is_deeply" that I think tests the data structure returned: https://rt.cpan.org/Public/Bug/Display.html?id=124866 (copied and pasted the failed tests below). Is anybody able to suggest if this is a "me" problem or a problem with the module? If it's something I'm doing I can feel as though it's worthwhile persevering, else it might just be a waste of time. Thanks, James # Failed test at t/04_auth/04_oauth2.t line 72. # Structures begin differing at: # $got->{hd} = '' # $expected->{hd} = Does not exist # Failed test at t/04_auth/04_oauth2.t line 101. # Structures begin differing at: # $got->{hd} = '' # $expected->{hd} = Does not exist # Failed test at t/04_auth/04_oauth2.t line 124. # Structures begin differing at: # $got->{hd} = '' # $expected->{hd} = Does not exist # Looks like you failed 3 tests of 28. t/04_auth/04_oauth2.t .. Dubious, test returned 3 (wstat 768, 0x300) Failed 3/28 subtests t/05_types.t ... Any::Moose is deprecated. Please use Moo instead at t/05_types.t line 6. t/05_types.t ... ok Test Summary Report --- t/04_auth/04_oauth2.t(Wstat: 768 Tests: 28 Failed: 3) Failed tests: 9, 22, 28 Non-zero exit status: 3 Files=24, Tests=423, 6 wallclock secs ( 0.11 usr 0.02 sys + 4.28 cusr 0.37 csys = 4.78 CPU) Result: FAIL Failed 1/24 test programs. 3/423 subtests failed. Makefile:801: recipe for target 'test_dynamic' failed make: *** [test_dynamic] Error 255 DANJOU/Net-Google-DataAPI-0.2805.tar.gz /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, try: reports DANJOU/Net-Google-DataAPI-0.2805.tar.gz Failed during this command: DANJOU/Net-Google-DataAPI-0.2805.tar.gz : make_test NO On Mon, Aug 5, 2019 at 5:56 PM Shlomi Fish wrote: > hi James, > > On Mon, 5 Aug 2019 15:47:45 +0100 > 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). > > > > Please see https://perl-begin.org/topics/cpan/ and esp. > https://metacpan.org/release/local-lib and try again from a clean slate. > > > 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
Install Problems: Net::Google::Spreadsheets
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-critic.t ... skipped: these tests are for testing by the author t/author-dependencies.t . skipped: these tests are for testing by the author t/author-pod-spell.t skipped: these tests are for testing by the author t/release-fixme.t ... skipped: these tests are for release candidate testing t/release-kwalitee-extra.t .. skipped: these tests are for release candidate testing t/release-kwalitee.t skipped: these tests are for release candidate testing t/release-pod-syntax.t .. skipped: these tests are for release candidate testing t/release-unused-vars.t . skipped: these tests are for release candidate testing Test Summary Report --- t/00_compile.t(Wstat: 256 Tests: 1 Failed: 1) Failed test: 1 Non-zero exit status: 1 t/01_new.t(Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: No plan found in TAP output Files=11, Tests=1, 1 wallclock secs ( 0.03 usr 0.01 sys + 0.98 cusr 0.07 csys
Website Files Preview as Thumbnail
Hi All, I promise this question is about Perl. I've googled this a lot and still can't find where to start. I run a publications repository/website that uses Perl on its back end. On each page I have a series of files. At the moment they display a thumbnail as the file icon (different for file type such as .doc, .jpg, .pdf etc.). I have seen some similar websites that appear to have the file content as the icon, admittedly with PDFs usually. For example the thumbnail would be the title page of the document. Does anybody know what I would search for for this functionality and is there a helpful Perl module/library that I can use? Thanks, James
Data::Dumper Output
Hi All, I needed to slightly alter the behaviour of a module I use in Perl. In order to see the data structure I used Data:Dumper to get an output so I could find the piece that I required for the change of logic. To my shock and horror it gave me this: $VAR1 = bless( do{\(my $o = '139790129395632')} I was expecting a series of hashes/arrays of hashes/arrays which I've previously been able to navigate through. This is totally foreign to me. Could anybody shed some light on it please and possibly suggesthow I can get to the "stuff"? My suspicion is that it contains some sort of XML that I'm going to have to "crawl" along to get to what I want. Thanks, James
Re: Syntax "||" before sub
Hi Sebastian, Thanks for that info! It's much more thorough than what I discovered about this. I'll keep it in mind as I delve deeper... Thanks, James On Thu, Nov 22, 2018 at 1:58 PM James Kerwin wrote: > Ahhh sorrry to reply to my own post but I found this: > > https://stackoverflow.com/questions/29302181/what-is-in-perl-for > > I assume then that if " guess_doc_type" evaluates to false it moves on to > the defined subroutine. My problem is that I can't find where " > guess_doc_type" is defined... which is not a problem for this list to solve! > > Thanks, > James > > On Thu, Nov 22, 2018 at 1:48 PM James Kerwin > wrote: > >> Hi All, >> >> I'm looking through some Perl files for software we use and I noticed >> this in one of the config files: >> >> $c->{guess_doc_type} ||= sub { >> >> All other similar config files show a similar structure, but without the >> "||" before the equals sign: >> >> $c->{validate_document} = sub { >> >> My question is, what is the "||" doing in the first example? >> >> It would be useful to know before I go changing anything. My instinct is >> that it's an "or" but that really doesn't make sense in this context. >> >> I've attempted to Google this, but found no solid answer. >> >> Thanks, >> James >> >
Re: Syntax "||" before sub
Ahhh sorrry to reply to my own post but I found this: https://stackoverflow.com/questions/29302181/what-is-in-perl-for I assume then that if " guess_doc_type" evaluates to false it moves on to the defined subroutine. My problem is that I can't find where " guess_doc_type" is defined... which is not a problem for this list to solve! Thanks, James On Thu, Nov 22, 2018 at 1:48 PM James Kerwin wrote: > Hi All, > > I'm looking through some Perl files for software we use and I noticed this > in one of the config files: > > $c->{guess_doc_type} ||= sub { > > All other similar config files show a similar structure, but without the > "||" before the equals sign: > > $c->{validate_document} = sub { > > My question is, what is the "||" doing in the first example? > > It would be useful to know before I go changing anything. My instinct is > that it's an "or" but that really doesn't make sense in this context. > > I've attempted to Google this, but found no solid answer. > > Thanks, > James >
Syntax "||" before sub
Hi All, I'm looking through some Perl files for software we use and I noticed this in one of the config files: $c->{guess_doc_type} ||= sub { All other similar config files show a similar structure, but without the "||" before the equals sign: $c->{validate_document} = sub { My question is, what is the "||" doing in the first example? It would be useful to know before I go changing anything. My instinct is that it's an "or" but that really doesn't make sense in this context. I've attempted to Google this, but found no solid answer. Thanks, James
Perl Email and WuFoo Forms.
Hi All, I have a Perl script that pulls in some information, generates an email, sends the email to a person and provides a URL to a WuFoo form. This URL contains the information to populate most fields in the form and could populate all of the fields. What I don't know is how to submit the form. WuFoo uses POST to submit forms so I'm quietly confident I can't trigger that via the URL (happy to be surprised!). The email generated by Perl is plain text so far as I can tell, using the JavaScript API that WuFoo has is out of the question (again, very happy to be told otherwise). Does anybody have any idea how I could go about this? I have access to a server in which to host scripts on etc. and I'm not necessarily looking for a hand-holding solution, just a nudge in the right direction would be brilliant. Thanks, James
Eclipse/Epic/PadWalker for Perl
Hi all, I appreciate this isn't a place for the Eclipse IDE, but maybe some of you may have an answer. I installed Eclipse Photon, EPIC and then PadWalker. Unfortunately I can't seem to see variables and their values in eclipse. I can't seem to find a diagnosis or solution. Would anybody be able to shed some light onto this? I should add that my scripts run in eclipse as expected. The debugging just doesn't seem to be behaving itself. Thanks, James
Re: Unfamiliar syntax
Morning All, Thank you for the help, it's really useful and gives me plenty to look at. When you know what something is called (e.g. anonymous subroutines) it becomes much easier to look it up. Thanks, James On Fri, Jul 20, 2018 at 5:47 PM, Octavian Rasnita wrote: > *From:* James Kerwin > > Afternoon all, > > I have been asked to take a look at a .pl file which is part of a set-up > called "EPrints". The particular file controls who can access documents on > a server. > > Excluding some comments, the file starts like: > > $c->{can_request_view_document} = sub > { > my( $doc, $r ) = @_; > > It then goes on to complete the subroutine and return a value. > > I understand that $doc and $r are populated via @_ but I have never before > seen the structure of the first line starting with "$c". Additionally, the > file doesn't look like a typical Perl file (eg.#!/usr/bin/perl -w at the > top and some use statements). > > I know it's very vague, but could anybody explain this syntax to me? My > suspicion is that something else is calling the subroutines in this file? > Am I at least on the right track? > > Thanks, > James > > > Hi, James > > Yes, you are on the right track. > > This is an annonymous subroutine which is probably used as a callback > subroutine somewhere else. > > You can define such subroutines using a code like: > > my $my_sub = sub { ... } > > Then you can use the $my_sub variable as any other scalar variables, for > example as a parameter in another subroutine call, like: > > do_something( $my_sub ); > ...then the sub do_something could use this sub like: > > sub do_something { > my ( $sub ) = @_; > $sub->(); #execute the callback subroutine here > } > > If this subroutine accepts parameters, you can call it like: > > $my_sub->( $doc, $r ); > > Now, in your case, you don't have a scalar variable $my_sub to store this > subroutine, but you have another scalar value of a hashref $c, stored in > the key can_request_view_document, which is $c->{can_request_view_ > document},. > > So in order to execute this sub, you do: > > $c->{can_request_view_document}->( $doc, $r ); > > The code is common Perl code. It doesn't matter that the file doesn't > start with #!/usr/bin/perl > The shebang line is not needed if the program is executed with a command > like: > perl program.pl > --Octavian > > >
Unfamiliar syntax
Afternoon all, I have been asked to take a look at a .pl file which is part of a set-up called "EPrints". The particular file controls who can access documents on a server. Excluding some comments, the file starts like: $c->{can_request_view_document} = sub { my( $doc, $r ) = @_; It then goes on to complete the subroutine and return a value. I understand that $doc and $r are populated via @_ but I have never before seen the structure of the first line starting with "$c". Additionally, the file doesn't look like a typical Perl file (eg.#!/usr/bin/perl -w at the top and some use statements). I know it's very vague, but could anybody explain this syntax to me? My suspicion is that something else is calling the subroutines in this file? Am I at least on the right track? Thanks, James
File Size Limit
Good morning/afternoon all (depending on where you are), This should be a quick one: When creating files in a perl script is there a way to limit the size of the file created? If somebody could give me a term to search for that should be enough. I have googled this but I can't find an answer. I'm probably not using the right search terms because this seems very do-able and I'm surprised to have not found anything. My situation is as follows: I perform some text manipulation on files that are 30 MB in size. The newly formatted files get pushed to another script that can only handle files of 5MB maximum. So I would like to be able to limit the file size and start a new one when it reaches (or comes close to) this limit. This would allow me to automate it rather than having to manually break the big files up before continuing. Thanks! James.
Re: Counter Help
Thank you all for your help; all suggestions were welcome and helpful. I didn't give the full details but Jim's solution did what I wanted the best and after reading around I think I get it. I've sat here trying to "break" it for the past half an hour and so far so good. I solemnly swear to properly learn hashes and use them (and to stop thinking of them as "weird"). Again, thank you for the help! It's very appreciated. James. On Tue, Feb 9, 2016 at 6:37 PM, Jim Gibson <jimsgib...@gmail.com> wrote: > > > On Feb 9, 2016, at 6:46 AM, James Kerwin <jkerwin2...@gmail.com> wrote: > > > > Thank you both very much for your help. I'll investigate this way when I > get home later (I'm a bit wary of hashes because they're weird). > > Here is a solution using a hash: > > #!/usr/bin/perl > use strict; > use warnings; > > my @array = qw{ >11_ >22_ >22_ >33_ >33_ >33_ >44_ >44_ >55_ > }; > > my %count; > for my $element ( @array ) { > $element .= ++$count{$element}; > } > > print "Array:\n\n ". join("\n ",@array) . "\n”; > > __END__ > > Note that the array needn’t be sorted for this method to work. > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: Counter Help
Thank you both very much for your help. I'll investigate this way when I get home later (I'm a bit wary of hashes because they're weird). As my files are sorted numerically I managed to do the following (it's ugly, please don't shout at me): my $length = (scalar @New)-1; #print $length; push (my @other, @New[0]); foreach (@New){ chop ($_); #print "$_\n"; } my $i = 0; my $ii = 1; foreach (@New[1 .. $length]) { #foreach (@New){ if ($_ ne $New[$i]){ push (@other, (join "", $_,"1")); $i++; } elsif ($_ eq $New[$i]){ $i++; $ii++; push (@other, (join "", $_,$ii)); }} foreach (@other){ print "$_\n"; } This gave me the desired output. Like I said, I'll investigate the other way later... Thanks, James. On Tue, Feb 9, 2016 at 2:22 PM, Jim Gibson <j...@gibson.org> wrote: > > > On Feb 9, 2016, at 6:08 AM, James Kerwin <jkerwin2...@gmail.com> wrote: > > > > Afternoon all, > > > > I have the following problem: > > > > I have an array containing a list of non-unique strings. eg: > > > > @array Contains: > > > > 11_ > > 22_ > > 33_ > > 33_ > > 33_ > > 44_ > > 44_ > > 55_ > > > > What I would like to do is number each element of the array to look as > follows: > > > > 11_1 > > 22_1 > > 33_1 > > 33_2 > > 33_3 > > 44_1 > > 44_2 > > 55_1 > > > > I have so far tried to use "exists", while loops and all the usual stuff > as it seemed very simple at first. My attempts have mostly focused on > equating the current element of the array with the previous one and asking > if they are equal and then taking action. I just can't get the logic right > though. I keep getting them all numbered sequentially from 1 to 10 or they > all end in "_2" or alternating "_1" and "_2" If anybody could shed even the > smallest glimmer of light on how to solve this I'd be really grateful. > > You should define a hash with the strings as keys and the number of > strings encountered in the array so far as the hash value. You can then add > the number to each string as you iterate over the array and increment the > hash value count. > > > Jim Gibson > j...@gibson.org > > > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Counter Help
Afternoon all, I have the following problem: I have an array containing a list of non-unique strings. eg: @array Contains: 11_ 22_ 33_ 33_ 33_ 44_ 44_ 55_ What I would like to do is number each element of the array to look as follows: 11_1 22_1 33_1 33_2 33_3 44_1 44_2 55_1 I have so far tried to use "exists", while loops and all the usual stuff as it seemed very simple at first. My attempts have mostly focused on equating the current element of the array with the previous one and asking if they are equal and then taking action. I just can't get the logic right though. I keep getting them all numbered sequentially from 1 to 10 or they all end in "_2" or alternating "_1" and "_2" If anybody could shed even the smallest glimmer of light on how to solve this I'd be really grateful. Thanks, James.
Re: Perl CGI-html quotation marks
Hello again, Apologies for the delay. I shut my laptop in frustration for the night yesterday. Here is a chunk of the code: my $html2 = '/Results.tar.gz div style=text-align: center;button type=submitDownload Files/button/div p style=text-align: center;Click the button below to View your alignment in JBrowse Viewer/p input type=button value=Open Window onclick=window.open(\' bioinf6.bioc.le.ac.uk/~srpgrp3/JBrowse-1.11.4/index.html?data=http://bioinf6.bioc.le.ac.uk/~srpgrp3/UserFiles '; my $html4 = '/datatracks=DNA,transcript_with_no_features,Geneshighlight=\') /body /html'; print $html1; print $directory; print $html3; print $directory; print $html2; print $directory; print $html4; Another person in my group had a look at it today and let me know that I hadn't closed the button THING with a . Apparently with that it's able to handle the single quotation marks. What a fool! Thanks, James. On Thu, Jul 3, 2014 at 5:23 PM, Uri Guttman u...@stemsystems.com wrote: On 07/03/2014 12:16 PM, James Kerwin wrote: Hello all, I'm currently using Perl CGI to generate a Results webpage. This results webpage specifies unique directories generated within the script and print these in between the blocks of html so various download and display buttons work. My problem is that I'm using a button to open a file in a new tab and the new tab URL uses single quotes and won't work using double or none. This then messes up the printing of the html in the Perl script. Can anybody help me? (Example provided below). input type=button value=Open Window onclick=window.open('THE URL OF THE FILE I WANT TO OPEN IN A NEW TAB UPON CLICKING THE BUTTON') it would be most helpful if you posted your relevant perl code. if you say it messes up printing html i sense you are not creating your html strings in the best way. uri -- Uri Guttman - The Perl Hunter The Best Perl Jobs, The Best Perl Hackers http://PerlHunter.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Perl CGI-html quotation marks
Hello all, I'm currently using Perl CGI to generate a Results webpage. This results webpage specifies unique directories generated within the script and print these in between the blocks of html so various download and display buttons work. My problem is that I'm using a button to open a file in a new tab and the new tab URL uses single quotes and won't work using double or none. This then messes up the printing of the html in the Perl script. Can anybody help me? (Example provided below). input type=button value=Open Window onclick=window.open('THE URL OF THE FILE I WANT TO OPEN IN A NEW TAB UPON CLICKING THE BUTTON') If this isn't clear or it's a total sin to post html in an email to the list then I apologise. Any help is greatly appreciated! Thanks, James.
Brackets in scalar and array
Hello all, long time lurker, first time requester... I have a Perl exam tomorrow and came across a question that I just cannot find an answer to (past paper, this isn't cheating or homework etc.). Explain the difference between: ($test)=(@test); And $test=@test; If anybody could shed any light on this I'd be very grateful. Thanks, James.
Re: Brackets in scalar and array
It seems so obvious now. Should possibly have just tested it myself before asking... Thank you all for the explanations! On 29 May 2014 21:36, Jim Gibson jimsgib...@gmail.com wrote: On May 29, 2014, at 1:20 PM, James Kerwin wrote: Hello all, long time lurker, first time requester... I have a Perl exam tomorrow and came across a question that I just cannot find an answer to (past paper, this isn't cheating or homework etc.). Explain the difference between: ($test)=(@test); And $test=@test; If anybody could shed any light on this I'd be very grateful. The difference is the context of the assignment: scalar or list, and how @test (or (@test)) is evaluated in that context. In the first statement ($test) = (@test), the parentheses around $test in the left-hand side (LHS) of the assignment places the evaluation of the right-hand side (RHS) in list context. In list context, with two lists on either side of the assignment operator (=), assignment is made from each element on the RHS to the corresponding element on the LHS. Therefore, the one and only element on the LHS ($test) gets assigned the value of the first element of the RHS, and $test ends up with the value of $test[0]. In the second statement, the assignment is done in scalar context, and the RHS is evaluated in scalar context. A list evaluated in scalar context returns the number of elements in the list, and $test is assigned the value ($#test+1). Note that the parentheses around @test in the first statement are irrelevant. The context is list with or without them. Try it yourself: % perl -e '@t=qw(1 2 3);$t=@t;print qq($t\n);' 3 % perl -e '@t=qw(1 2 3);($t)=@t;print qq($t\n);' 1 % perl -e '@t=qw(1 2 3);($t)=(@t);print qq($t\n);' 1