Perl pdl graphics, fails to show image as specified in documentation - perl

For those interested in solution please skip to continuation and solution.
So, I am using Strawberry Perl 5.32.1.1-64, from zip, no msi, under Windows 11. Want to use pdl. The information on the internet over that issue is very poor and the support as well. I've seen others having similar problem, but didn't find a solution.
Problem: According to first steps like specified here https://pdl.perl.org/?page=FirstSteps
Then I did this as specified on the site:
cpan PDL::Graphics::Simple
So, when starting that commands again I get these one for PDL::Graphics::Simple:
pdl> use PDL::Graphics::Simple
PDL::Graphics::Simple::register: PDL::Graphics::Simple::Prima is out of date - winging it at
perlhome/perl/site/lib/PDL/Graphics/Simple.pm line
1397, <DATA> line 209.
How exactly a fresh install from cpan is out of date?... I did not notice any difference with invoking or without invoking use PDL::AutoLoader
Then for img command, failed:
pdl> imag (sin(rvals(200,200)+1))
Trying gnuplot (PDL::Graphics::Gnuplot)...nope
Trying pgplot (PDL::Graphics::PGPLOT::Window)...nope
Trying plplot (PDL::Graphics::PLplot)...nope
Trying prima (PDL::Graphics::Prima)...nope
Sorry, all known plotting engines failed. Install one and try again.
Tried to install install the plots, and every single install failed, even after installing gnuplot itself. I am having NO problems using gnuplot in Julia, all works there exactly as specified in documentation. I literally want to make Perl to work. But could not make Strawberry Perl nor ActiveState Perl working with pdl. Similar topics on stackoverflow did not help much.
The continuation and solution is here

Related

Can I suppress the "Perl API version %s of %s does not match %s" error

I copied a Perl module (DBD::Pg) from one system to another to run some quick checks on a Mojolicious project. On the new system, it all works fine when I run it under morbo (the Mojolicious test web daemon). But when I try to run the tests (via the Module::Build installer), I get the error:
Perl API version v5.16.0 of DBD::Pg does not match v5.20.0 at /usr/local/lib/perl/DynaLoader.pm line 216.
I researched why I am getting this, and read the explanation in the perldoc. But since the project runs under morbo, that seems to imply to me that the version mismatch may be trivial in this case. It looks like PerlXS does make some allowances for disabling VERSIONCHECK, but I don't see how that can be applied when running a Perl script.
You can't copy non-pure Perl modules from one system to the next (or into one group of perl lib directories into another perl's). Generally the code in those modules is compiled against the specific perl binary. That binary could have linked to different libraries, changed how it does things, used a different compiler, and many other things. It may not even work if the perl versions are the same.
Instead, install the DBD::Pg for each perl that needs to use it.

Keep getting error "Can't locate Image/Grab.pm in #INC" after installing the Perl mod

I'm a bit new to programming and I'm having some trouble writing a Perl script that will grab all the images from a webpage and save them in a specified directory.
Here's my code:
use warnings;
use strict;
use lib '/home/User1/strawberry/cpan/build';
use Image::Grab;
$pic = Image::Grab->new(SEARCH_URL=>'http://www.examplesite.com',
REGEXP =>'.*\.gif|.*\.jpg');
my $dir = 'images';
opendir (IMG, ">>$dir") || die "Directory doesn't exist - $!\n";
foreach ($pic) {
print IMG "$_\n";
}
closedir IMG;
This is the error I get when I run the script in PuTTY:
Can't locate Image/Grab.pm in #INC (#INC contains:
/home/User1/strawberry/cpan/build /etc/perl /usr/local/lib/perl/5.10.1
/usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5
/usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at
getimage.pl line 7. BEGIN failed--compilation aborted at getimage.pl
line 7.
Thanks for the help
That's a standard error when you haven't installed the module. Image::Grab does not come with perl. There are lots of perl modules available on something called cpan, for instance:
http://search.cpan.org/~mahex/Image-Grab-1.4.2/lib/Image/Grab.pod.
Modules are libraries of functions that someone has written in perl and made available for your use.
Now, you have to figure out how to install modules. See if this works:
$ perl -MCPAN -e shell
-M => Use the module specified, in this case CPAN(comes with perl)
-e => execute the following perl code, in this case the function shell().
then
cpan> install Image::Grab.
The first time you do that, you'll have to answer a lot of questions.
Once you are done:
cpan> q ('q' is for quit)
Response to comment:
1) Try updating your CPAN module:
cpan> install CPAN
cpan> reload cpan
then:
cpan> install Image::Grab
Installing from source is fine, but if you can get cpan to work, then it takes care of downloading all the dependencies, so it is hassle free. I just used cpan to download Image::Grab, and I got no errors. It has no dependencies that need to be downloaded.
2) What is the output of:
$ perl --version (it looks like you are using perl 5.10.1)
Also, at the bottom of your question add the entire output from your cpan attempt.
3) Try installing another module, like:
http://search.cpan.org/~rehsack/List-MoreUtils-0.402/lib/List/MoreUtils.pm
I noticed you said you installed the module using CPAN. This would lead me to glean that you're running on a linux operating system, and you just kept pressing the 'enter' key every time the installation script asked you a question, optimistically believing everything would work out, just like in the movies.
If you'd read a little closer you probably would have noticed all kinds of issues with the installation.
I did the same thing yesterday, because I didn't want to go through all the trouble of solving dependencies. And incidentally, I was using CPAN. I'm not sure what CPAN stands for, but yesterday it most definitely didn't stand for Certifiably Perfect Automatic NichePerlModuleInstaller.
Way too often there's no Perl::EasyButton. Sometimes you have to roll up your sleeves up and start w-geting tar.gzs and installing them, only to find out you need other tar.gzs, only to find out you need more tar.gzs, until one day you're looking back and wondering where your life went.
Unless you can get CPAN to work. Then you just have to sit in front of your putty terminal like a monkey pressing the enter key every time it asks you a question and suggests an answer. And if you're lucky, after you've pressed 'enter' 1837 times, the module you need to use will be installed and functional.
I might suggest a different module or approach altogether, where you're looking for an easy way to grab images off the internet. If you're into Perl for the longhaul, I say roll your sleeves up and get dirty. If you give me a URL for an image, I can write the code from scratch to have that thing downloaded in a matter of a few minutes. And then I can reuse that code as many times as I want to download more images. And before long I can fill a hard drive up with images I downloaded from that original code.
You need to get yourself to that point. Or you need to look for a canned solution that can be used by the masses, and take your place among them (the masses).
Or, you could google the exact problem you're having when you're running the installation on CPAN and figure out what you're doing wrong. That's an option.
And there are probably a couple more options. Hopefully you'll come up with a good one.
Good luck!

Invoking a HTTP URL from perl script - Perl Version 5.8.4

We have perl version 5.8.4 installed on our servers. I am trying to invoke a HTTP URL from within the perl script and based on the output that the HTTP URL returns I have a logic to be executed.
I am very new to perl and am looking for help to achieve this. The Cpan and other modules seem to be unavailable with the current version we have.
Please let me know how we could achieve this.
Thanks,
Sachin
Take a look at LWP and LWP::simple.
Even older versions of perl will have support for this library, although you may have to install it via cpan.
We have perl version 5.8.4 installed on our servers
Then that should be the first thing that you fix. 5.8.4 is ten years old. It is completely unsupported.
The Cpan and other modules seem to be unavailable with the current version we have.
No. CPAN works fine with versions of Perl back far earlier than 5.8.4. If you are having a problem using them that is a local problem that you should work on getting fixed. Good Perl programming is a case of wiring together the correct CPAN modules. If you can't install CPAN modules then you are missing most of the power of Perl.
The correct answer to your problem is to install LWP::Simple and use its get function. If you don't want to do that, then reading the source code for that module will show you the lower level code that you would need to write.

postgresql autodoc

I want to generate a ER Diagram sort of, of my spatial database i created inside of Postgresql. As i am also new to Postgresql, i am not too sure if the diagramming functionality can be done using whats offered by the PgAdmin (not referring to the Graphical Query Builder). However, it seems to me there is none. I read around that there is a perl based tool called postgresql_autodoc that can run through PostgreSQL system tables and return HTML, Dot, Dia and DocBook XML which describes the database. Now this is not exactly what i wanted but its the closest option i have. So i have successfully installed, ActivePerl 5.8 and DBD-Pg 2.10.0 for Perl 5.8 (DBD PG is a Perl DBI driver for the PostgreSQL database) and i have also downloaded the postgresql_autodoc.pl file. I have also added the path for Perl. But when i try to run the postgresql_autodoc.pl via the command prompt, i was getting this error: Possible Unintended Interpolation of #TEMPLATE in string at C:/Perl/bin/postgresql_autodoc.pl line 1831. Global symbol "#TEMPLATE" requires explicit package name at C:/Perl/bin/postgresql_autodoc.pl line 1831. Execution of C:/Perl/bin/postgresql_autodoc.pl aborted due to compilation errors.
I tried to view the postgresql_autodoc.pl using notepad++ however i have no experience with the perl language and so i cant figure out what is really wrong. All i could do is locate line 1831 but i dont know what i should do to fix this problem.
The postgresql_autodoc.pl file was downloaded from: http://www.rbt.ca/autodoc/
I would appreciate if anyone can help me here!
Thanks in advance
Barbara
That thingy, ##TEMPLATE-DIR##, is a string that is replaced when you build and install the module -- meaning you're not supposed to run it directly from the unpacked archive.
Most Perl modules are installed with a more or less simple three-step installation process, something like perl Makefile.PL ; make ; make install. However, this package is slightly different, you seem only to need make install.
Note that I have no experience with installing Perl modules on Windows with ActiveState. So the above may not work (e.g. if there's no make utility which is usually not part of Perl -- though it might be part of the ActiveState Perl distribution).
But there's a workaround. You can simply do what the install script does and replace the ##TEMPLATE-DIR## string yourself. It can be done easily with any text editor by replacing the two occurrences of ##TEMPLATE-DIR## with the path to where the postgresql_autodoc.pl script has been unpacked to -- meaning it's the path the script will look for the *.tmpl files in.
Note that Windows path names can be written with forward slashes in Perl, meaning C:/Temp/postgresql_autodoc should be OK.

Compiling WWW::Curl on ActivePerl

I'm trying (desperately) to build / install the newest version of WWW::Curl onto my activeperl box (I'll explain in a moment why I don't use the PPM)
I had to make some modifications as per the instructions found here:
http://cpansearch.perl.org/src/SZBALINT/WWW-Curl-4.15/README.Win32
I also had to change the following line:
From:
open(H_IN, "-|" "gcc", "$curl_h") and $has_cpp++;
To:
open(H_IN, "gcc $curl_h") and $has_cpp++;
I finally got perl Makefile.PL to work but now, when I run nmake, I get the following:
Missing right curly or square bracket at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
NMAKE: fatal error U1077: 'C;|windows\system32\cmd.exe' : return code '0xff'
Stop.
Now, the reason I'm trying to compile this rather than using the PPM supplied by u.winnipeg is because the that PPM doesn't seem to support SSL transaction (I get "libcurl: ssl disabled") Now, if anyone can show me how to get ssl to run on this PPM, I'm more than happy to use it.
Thank you very much in advance
I presume the original was
open(H_IN, "-|", "gcc", "$curl_h")
The reason you have to change that in because noone got around to implementing feature in Windows. Change it to
open(H_IN, qq{gcc "$curl_h" |})
Use the right name and syntax for your compiler.
Well, I finally figured it out, thanks to everyone who responded. There were a bunch of things I had to change.
Using http://cpansearch.perl.org/src/SZBALINT/WWW-Curl-4.15/README.Win32 as a guide:
The open cmd as I did above worked fine. However, I did use the advice returned by ikegami, reinierpost, and mob.
Using nmake /n (as advised by socket puppet), it printed out all of the perl statements which were being executed. I took this output and placed it into a .bat file and corrected the perl syntax.
I changed all instances of
pm_to_blib({{#ARGV}
to
pm_to_blib({#ARGV}
(it is disturbing these were returned)
Then, I had to link the libcurl libraries to each line instantiating g++, which were not linked correctly. After I added these references, everything else went smoothly.
These were added:
C:\lc\curl\lib\libcurl.a C:\lc\curl\lib\libcurldll.a
Now, WWW::Curl is happily running on my system.
As for using the PPM version, it is exactly because of SSL I had to upgrade. The newest version of WWW::Curl is 4.15 the ppm version is (I believe) 3.02.
First, many people don't know that you can use ppm to install MinGW to use cpan to install modules.
Second, if the libcurl provided by your module doesn't do SSL, you can try and replace it with a suitable SSL version from the download page. This might well fail, but you might also be lucky.