On Sat Oct 20 04:54:15 2012, SISYPHUS wrote:
Show quoted text> Otherwise, I guess we should replace the instances of the // operator in
> Gnuplot.pm with code that 5.8.x *does* understand.
If you wish to go down this path, you might like to check that the
attached patch to Gnuplot.pm is satisfactory.
It worked ok for me on 5.8.9 on MS Windows.
Cheers,
Rob
--- Gnuplot.pm_orig 2012-10-21 17:41:23 +1100
+++ Gnuplot.pm 2012-10-21 18:00:29 +1100
@@ -2122,7 +2122,7 @@
for my $i(0..$#$chunks) {
# Allow global binary/ASCII flag to be overridden by per-curve binary/ASCII flag
- $chunks->[$i]->{binaryCurveFlag} = $chunks->[$i]->{binaryWith} // $binary_mode;
+ $chunks->[$i]->{binaryCurveFlag} = _defined_eq($chunks->[$i]->{binaryWith}, $binary_mode);
# Everything else is an image fix
next if( $chunks->[$i]->{cdims} != 2 );
@@ -2232,7 +2232,7 @@
# If we're working with time data, and timefmt isn't set, then default it to '%s'.
$this->{options}->{timefmt} = '%s'
if ( !defined($this->{options}->{timefmt}) and
- grep { ($this->{options}->{$_."data"} // "") =~ m/^time/i } qw/x x2 y y2 z cb/ );
+ grep { _defined_eq($this->{options}->{$_."data"}, "") =~ m/^time/i } qw/x x2 y y2 z cb/ );
##########
# Merge in any temporary options that have been set by the argument parsing.
@@ -2601,7 +2601,7 @@
# Make sure we know our "with" style...
unless($chunk{options}{with}) {
- $chunk{options}{with} = $this->{options}->{'globalwith'} // ["lines"];
+ $chunk{options}{with} = _defined_eq($this->{options}->{'globalwith'}, ["lines"]);
}
# validate "with" and get imgFlag and tupleSizes.
@@ -3301,7 +3301,7 @@
my $mouse_serial = 0;
sub read_mouse {
my $this = shift;
- my $message = shift // "Click mouse in plot to continue...";
+ my $message = _defined_eq(shift, "Click mouse in plot to continue...");
barf "read_mouse: This plot uses the '$this->{terminal}' terminal, which doesn't support mousing\n"
unless($this->{mouse});
@@ -3324,7 +3324,7 @@
$string =~ m/Key: (\-?\d+)( +at xy:([^\s\,]+),([^\s\,]+)? button:(\d+)? shift:(\d+) alt:(\d+) ctrl:(\d+))?/
|| barf "read_mouse: string $string doesn't look right - doesn't match parse regexp.\n";
- my($ch,$x,$y,$b,$sft,$alt,$ctl) = map { $_ // "" } ($1,$3,$4,$5,$6,$7,$8);
+ my($ch,$x,$y,$b,$sft,$alt,$ctl) = map { _defined_eq($_, "") } ($1,$3,$4,$5,$6,$7,$8);
if(wantarray) {
return ($x,$y, ($ch>=32)?chr($ch):undef,
@@ -4056,8 +4056,8 @@
my @numbers = ();
my @v = @$v;
- while( @v && (($v[0]//"") =~ m/^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/ )) {
- push(@numbers, (shift(@v)//""));
+ while( @v && (_defined_eq($v[0], "") =~ m/^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/ )) {
+ push(@numbers, _defined_eq(shift(@v), ""));
}
my $s = "";
$s .= "set view ".join(",",@numbers)."\n" if(@numbers);
@@ -4243,7 +4243,7 @@
# data is here so that it gets sorted properly into each chunk -- but it doesn't get specified this way.
# the output string just specifies STDIN. The magic output string gets replaced post facto with the test and
# real output format specifiers.
- 'cdims' => [sub { my $s = $_[1] // 0; # Number of dimensions in a column
+ 'cdims' => [sub { my $s = _defined_eq($_[1], 0); # Number of dimensions in a column
if($s==0 or $s==1 or $s==2) {
return $s;
} else {
@@ -4716,7 +4716,7 @@
push(@list, "(", join(", ",
map {
barf "<foo>tics: labels list elements must be duals or triples as list refs" unless(ref $_ eq 'ARRAY');
- sprintf('"%s" %s %s', $_->[0]//"", $_->[1]//0, $_->[2]//"");
+ sprintf('"%s" %s %s', _defined_eq($_->[0], ""), _defined_eq($_->[1], 0), _defined_eq($_->[2], ""));
} @{$new->{labels}}
),
@@ -4983,7 +4983,7 @@
#### A boolean or 'time' (for <foo>data plot options)
'bt' => sub { my($k,$v,$h) = @_;
- return "set $k\n" unless ($v // "" and $v=~m/^t/i);
+ return "set $k\n" unless (_defined_eq($v, "") and $v=~m/^t/i);
return "set $k $v\n";rxt hel
},
@@ -5214,17 +5214,17 @@
#looks like 'set <foo>range restore' (only way 'r' can be the first char)
- return "set $k ".join(" ",@$v)."\n" if(($v->[0] // '') =~ m/^\s*r/i);
+ return "set $k ".join(" ",@$v)."\n" if(_defined_eq($v->[0], '') =~ m/^\s*r/i);
# first element is an empty range specifier - emit.
- return "set $k ".join(" ",@$v)."\n" if(($v->[0] // '') =~ m/\s*\[\s*\]/);
+ return "set $k ".join(" ",@$v)."\n" if(_defined_eq($v->[0], '') =~ m/\s*\[\s*\]/);
my $c = substr($k,0,1);
- my $tfmt = ( $h->{$c."data"} // "" ) =~ m/time/;
+ my $tfmt = _defined_eq( $h->{$c."data"}, "" ) =~ m/time/;
# first element has a nonempty range specifier (naked or not).
- if(($v->[0] // '') =~ m/\:/) {
+ if(_defined_eq($v->[0], '') =~ m/\:/) {
$v->[0]=~ s/^\s*((.*[^\s])?)\s*$/$1/; # trim leading and trailing whitespace if present
unless($v->[0] =~ m/^\[/) {
@@ -5247,7 +5247,7 @@
# specifier out of 'em, then emit.
# Here's a little fillip: gnuplot requires quotes around time ranges
# if the corresponding axes are time data. Handle that bizarre case.
- if( ($h->{$c."data"} // "" ) =~ m/time/ ) {
+ if( _defined_eq($h->{$c."data"}, "" ) =~ m/time/ ) {
return sprintf("set %s [%s:%s]\n",$k, ((defined $v->[0])?"\"$v->[0]\"":"*"), ((defined $v->[1])?"\"$v->[1]\"":"*"));
}
@@ -5262,7 +5262,7 @@
# if the corresponding axes are time data. Handle that bizarre case.
my $c = substr($k,0,1);
- if( (($this and $this->{options} and $this->{options}->{$c."data"}) // "" ) =~ m/time/ ) {
+ if( _defined_eq(($this and $this->{options} and $this->{options}->{$c."data"}), "" ) =~ m/time/ ) {
print STDERR "WARNING: gnuplot-4.6.1 date range bug triggered. Check the date scale.\n";
return sprintf(" [%s:%s] ",((defined $v->[0])?"\"$v->[0]\"":""), ((defined $v->[1])?"\"$v->[1]\"":""));
}
@@ -5607,8 +5607,8 @@
$terminalOpt->{"wait"} = [ 's' , sub { return "" }, undef, $i++, "wait time before throwing an error (default 5s)" ];
$termTab->{$k} = { desc => $termTabSource->{$k}->{desc},
unit => $termTabSource->{$k}->{unit},
- mouse => $termTabSource->{$k}->{mouse} // 0,
- int => $termTabSource->{$k}->{int} // 0,
+ mouse => _defined_eq($termTabSource->{$k}->{mouse}, 0),
+ int => _defined_eq($termTabSource->{$k}->{int}, 0),
opt => [ $terminalOpt,
undef, # This gets filled in on first use in the constructor.
"$k terminal options"
@@ -5920,9 +5920,9 @@
sub _checkpoint {
my $this = shift;
my $suffix = shift || "main";
- my $opt = shift // {};
- my $notimeout = $opt->{notimeout} // 0;
- my $printwarnings = (($opt->{printwarnings} // 0) and !($this->{options}->{silent} // 0));
+ my $opt = _defined_eq(shift, {});
+ my $notimeout = _defined_eq($opt->{notimeout}, 0);
+ my $printwarnings = (_defined_eq($opt->{printwarnings}, 0) and !_defined_eq($this->{options}->{silent}, 0));
my $pipeerr = $this->{"err-$suffix"};
@@ -5950,7 +5950,7 @@
_logEvent($this, "Trying to read from gnuplot (suffix $suffix)") if $this->{options}{tee};
my $terminal =$this->{options}->{terminal};
- my $delay = (($this->{'wait'}//0) + 0) || 5;
+ my $delay = (_defined_eq($this->{'wait'}, 0) + 0) || 5;
if($this->{"echobuffer-$suffix"}) {
$fromerr = $this->{"echobuffer-$suffix"};
@@ -6172,7 +6172,7 @@
splice @$with, $i,1; # remove 'resample' from list
$resample_flag = 1;
if( ($with->[$i]) =~ m/(\d+)(\,(\d+))?/ ) {
- @resample_dims = ($1, $3 // $1);
+ @resample_dims = ($1, _defined_eq($3, $1));
splice @$with, $i, 1;
}
$i--;
@@ -6294,6 +6294,11 @@
}
+# The // operator works only with 5.10 and later. This sub does the same,
+# and works with perl-5.8 as well.
+sub _defined_eq {
+ defined($_[0]) ? $_[0] : $_[1];
+}
=head1 COMPATIBILITY