Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use numeric-only strings for legend #100

Closed
d-lamb opened this issue Aug 22, 2023 · 1 comment
Closed

Unable to use numeric-only strings for legend #100

d-lamb opened this issue Aug 22, 2023 · 1 comment

Comments

@d-lamb
Copy link
Member

d-lamb commented Aug 22, 2023

Using PDL::Graphics::Gnuplot version 2.024, PDL 2.080, Perl 5.34.1:

use PDL::Graphics::Gnuplot
$w=gpwin("wxt",size=>6);
$x=xvals(10); $y = $x**2;
$w->plot({with=>'lines',legend=>'parabola'},$x,$y);
$w->plot({with=>'lines',legend=>'123parabola'},$x,$y);
$w->plot({with=>'lines',legend=>'456'},$x,$y);

Can't use string ("456") as an ARRAY ref while "strict refs" in use at /Users/derek/Build/PDL-Graphics-Gnuplot/blib/lib/PDL/Graphics/Gnuplot.pm line 3867.

@sisyphus
Copy link
Collaborator

It's the evaluation of @{$chunk{options}->{legend}} in Gnuplot.pm that's causing the error.
I didn't go digging, but I can only think that, somehow, with 'parabola' and '123parabola' $chunk{options}{legend} is set to something like['parabola'] and (respectively) ['123parabola'], but with '456' it's set to'456'.

Maybe something along the lines of what is accomplished by this silly little script:

use strict;
use warnings;
use Scalar::Util 'looks_like_number';

for ('parabola', '123parabola', '456') {
  my $arg;
  if(!looks_like_number($_)) {$arg = [$_]}
  else {$arg = $_}
  my %h = ('legend', $arg);
  my %chunk = ('options', \%h);
  print "ok: $_\n" if @{$chunk{options}->{legend}};
}

__END__
Outputs:
ok: parabola
ok: 123parabola
Can't use string ("456") as an ARRAY ref while "strict refs" in use at try.pl line 11.

Cheers,
Rob

mohawk2 added a commit that referenced this issue Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants