문제

I am trying to pipe a gnuplot script in perl to get some plots. My data.dat looks like:

1       5       2
2       3       9
3       9       6
4       -4      8
5       -3      4
6       11      2
7       0       -3
8       -8      -2
9       1       0
10      22      0

I tried this script:

#!/usr/bin/perl -w    
use strict;

my $type="png";

open(my $GP,'| gnuplot');

print {$GP} << "__GNUPLOT__";

set style data lines
#set logscale y
set terminal $type
set output 'pic.$type'
plot "data.dat" u 1:2, "" u 1:3

__GNUPLOT__

close $GP;

My aim is to plot the log scale. Because of the negative data, I wanted to use plot "data.dat" u 1:(abs($2)), "" u 1:(abs($3)). So I want to get access to my perl-script variables and the gnuplot variables $2 $3. Not quoting the heredoc __GNUPLOT__ isn't working for this. I found those posts which treat a similar topic:

I don't know if this issue is the same for bash. I wasn't trying it yet, but would be interested there too. I just want to learn more about the general problem with piping, quoting and different types of variables.

도움이 되었습니까?

해결책

The expression $2 is only a shorthand for column(2). So if you are having problems with escaping, use

plot "data.dat" u 1:(abs(column(2))), "" u 1:(abs(column(3)))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top