djwaddel has asked for the wisdom of the Perl Monks concerning the following question:
I am pretty new to perl, and I've been through most of the perl man pages many many times, tried many things but am still stuck!
I want to include something from an external file as data I am passing to a subroutine. What I am trying to do is the following:
Read data from files, print the data to another file after formatting etc. And then dump that data that processed data into a subroutine.
I am reading in numbers from several files, and formatting that data into matrices so that I can pass it to the gnuplot subroutine that is part of the Chart::Graph::Gnuplot module.
So for example, My data file might look like the following:
[{ "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 ],]
and I want to pass that data from the file to my perl script as if it was actually written within the script; like so:
gnuplot({ "title" => "My Trend", "output type" => "png", "output file" => "$TMPDIR/trend-$$.png"}, DATA_FROM_FILE );
Is there a way to do this so that perl thinks that DATA_FROM_FILE points to the contents of the file? Im thinking some sort of reference to a filehandle should work, but I have yet to make it work...
I know in bourne shell you can use back tics to "reference" the output of a command, so for example:
so that whenever I use $DATA it appears to the script that whatever cat /tmp/MY_DATA produces, actually looks like part of the script...DATA=`cat /tmp/MY_DATA`
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file contents as a part of code?
by GrandFather (Saint) on Aug 17, 2005 at 01:42 UTC | |
by davidrw (Prior) on Aug 17, 2005 at 02:04 UTC | |
by halley (Prior) on Aug 17, 2005 at 13:55 UTC | |
by djwaddel (Initiate) on Aug 17, 2005 at 16:03 UTC | |
|
Re: file contents as a part of code?
by xdg (Monsignor) on Aug 17, 2005 at 14:35 UTC |