R – How to set multiple timefmt in gnuplot with perl

gnuplotperl

I have created a tool to plot graphs using Perl and gnuplot. This is working fine but I just have an issue with the timefmt. I have many input data files with date and some are with time. So, I have created two separate tools with the below difference only.

For the input files which have time I used

set timefmt "%H:%M:%S"
set format x "%H:%M"

For the input files with date I used

set timefmt "%Y-%m-%d"
set format x "%Y-%m"

Is there any way to put the different timefmt at single option.

Best Answer

It will depend on how you use your scripts. Are these command-line scripts, CGI scripts, or something else?

If your scripts are invoked on the command line, you can use a module like GetOpt::Long to work with command-line options, and use control logic in your script to change the format depending on these options.

Alternatively, you could attempt to detect something in the data file which can clue your script as to which format to use.

Unfortunately, I don't have enough information in your question to make more than these very general recommendations. If you'd like more specifics, update your question to tell us how your scripts are invoked, and how you are reading and processing your data files.