Hey Wise ones,

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:

DATA=`cat /tmp/MY_DATA`
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...
Any Ideas? I am beyond stuck!
TIA!
Dave

In reply to file contents as a part of code? by djwaddel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.