I wrote a script that takes a large data set (~30k points) and pulls out meaningful info to graph with GNUPlot. It works really well when I want to graph one file at a time. Below is the striped down version of the code.

I need to do this for a bunch of files. I would like to designate each file path at the top and then have the code run through for each file. I tried using a matrix but it didn't seem to work with the 'foreach' command.

So, What is the best way to run the same script on multiple files?

# Columns to be written to the output file and Plotted. $c1 = 4; # X-Axis $c2 = 16; # Y-Axis $c3 = 11; # Z-Axis # Single file to be Opened $file1 = '../filename.asc'; open(Read, $file1); @Read = <Read>; # Read file into an array # Visit each text line in turn and write data in specific column to ar +ray foreach $part (@Read) { $part =~ s/ /:/g; @Row = split(/:+/, $part); push(@Write, "$Row[$c1]\t"); push(@Write, "$Row[$c2]\t"); push(@Write, "$Row[$c3]\n"); } # Creates the plotted data file writeFile_ref ("PlottedData.txt", \@Write); close(Read); # Opens GNUPlot and Creates Plots open(G, "|/usr/local/bin/gnuplot") or die "/usr/local/bin/gnuplot"; print G <<ENDOFHERE set term x11 splot 'PlottedData.txt' ENDOFHERE

Please and Thank You!


In reply to Reading Multiple Input Files by BoulderBuff64

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.