Page 1 of 1

PerlMagick users: BEWARE single-quote vs. double-quote

Posted: 2019-09-24T11:21:32-07:00
by E. Fudd Wabbitwy
The following may be a result of my Perl installation.

Or, it might be a result of the PerlMagick implementation, but after I finally, recognized the error-checking I'd seen in examples:

Code: Select all

$x=$image->Crop(someparameters);
warn "$x" if "$x";
$image->Crop(geometry=>'100x100+10+20');
$image->[$x]->Frame("100x200");
and added the same to my code, I started seeing the warning messages that in some cases, the single-quote/apostrophe/' character had been causing method calls to fail silently when used for the "geometry=>" string.

For example, in my case,

Code: Select all

#$err=$croppingrow->Crop(geometry=>'${xwidsrc}x1+0+0'); # FAILS and no crop is performed
$err=$croppingrow->Crop(geometry=>"${xwidsrc}x1+0+0"); # SUCCEEDS
warn "$err" if "$err";
This has been killing me from the get-go because where I found explicit examples of Methods in the PerlMagick documentation that used a geometry parameter, its string was invariably listed with single quotes.

However, taking a look at the Manipulate An Image section in the same place, it would take a sharp eye to notice that single and double quotes are used in different contexts (and in any event my latest experience is that the single-quoted geometry string is actually wrong on my system. :(

Code: Select all

$image->Crop(geometry=>'100x100+10+20');
$image->[$x]->Frame("100x200");

Re: PerlMagick users: BEWARE single-quote vs. double-quote

Posted: 2019-09-24T11:34:17-07:00
by snibgo
Have you read any perl language documentation, rather than just copying examples? For example https://perlmaven.com/quoted-interpolat ... gs-in-perl explains that ${xwidsrc} will be expanded (or "interpolated") when within double quotes, but not when within single quotes.

Re: PerlMagick users: BEWARE single-quote vs. double-quote

Posted: 2019-09-24T19:12:42-07:00
by E. Fudd Wabbitwy
Yes I've read loads of Perl documentation over the 20+ years I've been using it. I still have almost none of it memorized, and if I see an example that's represented as working, I'll typically adapt it into my project as the quicker path.

Taking the Crop() example, I was MUCH more troubled by my limited knowledge of PerlMagick syntax than I was about my less-limited knowledge of Perl's. After all, the example was taken right out of PerlMagick documentation.

I pointed out that the example as posted in PerlMagick documentation might actually work on others' installations, so I wasn't criticizing the documentation, but I posted the topic for anyone else who might happen along with a history similar to mine.

It should be clear to the reader that I'm recommending using the exception-throwing approach to using PerlMagick methods.

Thank you.