in reply to file contents as a part of code?

Sounds like what you're trying to do is use one script to generate your data and another to plot it, and you want to be able to save your data to a file in-between. Is that it? If you're manually generating a "Perl-format" data structure and dumping that to a file, you're probably better off using various CPAN modules that help you serialize a Perl data structure and save it to a file. For example, Data::Dumper (and variants like Data::Dump) or YAML. Let's consider an example with YAML;

use YAML qw( DumpFile ); my @data = ( [ { "title" => "line 1", "style" => "lines" , "type" => "matrix" }, [ 1, 6318 ], [ 2, 7903 ], [ 3, 25617 ], ], [ { "title" => "line 2", "style" => "lines" , "type" => "matrix" }, [ 1, 6215 ], [ 2, 7831 ], [ 3, 25782 ], ], ); DumpFile( "output.txt", @data )

This produces an output file that looks like this:

--- #YAML:1.0 - style: lines title: line 1 type: matrix - - 1 - 6318 - - 2 - 7903 - - 3 - 25617 --- #YAML:1.0 - style: lines title: line 2 type: matrix - - 1 - 6215 - - 2 - 7831 - - 3 - 25782

Loading it back in from inside your other file is just the reverse, and then you can use it however you want:

use YAML qw( LoadFile ); my @data = LoadFile( "output.txt" ); gnuplot({ "title" => "My Trend", "output type" => "png", "output file" => "$TMPDIR/trend-$$.png"}, @data );

One advantage of YAML is that it's not Perl code, so you don't run the same "danger" in loading Perl code from a file and running "eval" or just running "do" on the file. (If it's just you using it, it's not much of a risk, but it's a bad habit to get into.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.