except that you do write down all the file names when you assign them to variables. Much better to construct the names of the files on the fly. For example you could do something like
my $storage_dir = "C:/Stuff/";
foreach my $category qw( abc def ghi ) {
foreach my $subcategory qw( this that ){
foreach my $year ( 1..3) {
my $file = sprintf("%s_%s_02d.csv", $category, $subcategory,$yea
+r);
my $path = $storage_dir.$file;
# now do something with the file, i.e. generate your plot comman
+d
do_plot( $path );
}
}
}
sub do_plot {
my $path - shift;
### do the actual plotting here
}
Now you don't have to type all the combinations of categories, years etc but let the script handle that. An alternative approach would be to change the way you store the data by putting it all into a single file and starting each block of data with a string that gives yuo all those categories, as in:
#abc_this_01
-- data goes here ---
#def_this_01
-- more data ---
etc
Now your script doesn't need to kow anything about the categories and takes whatever is in your file, which presumably is the output of another script.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|