Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to declare variables per loop

by vagabonding electron (Curate)
on Oct 12, 2011 at 13:16 UTC ( [id://931010]=note: print w/replies, xml ) Need Help??


in reply to How to declare variables per loop

Dear All,
thank you very much for your help! You guys are great.
I used the solution from wfsp with some modification since $number should be able to be changed. Therefore I took the parts of the solutions of tospo and aartist too. However I gave up the loops with $number because I had to print the title for each plot too. It is readable (imho) in the form of:  my $first = build_command('01', %args);.
I put the complete script here including the gnuplot part.
I knew about the module Chart::Gnuplot. Unfortunately I still cannot download modules on my pc at work. Yes I read Yes, even you can use CPAN - none of the solutions works here. The only one were to copy and paste the code but the module has the XS part so it does not work either. I was not able to persuade my manager as proposed in the article. The command structure in the job can be sometimes more tricky as HoH :-)
Thanks again!
VE
use warnings; use strict; my $output = "C:/ .../output.ps"; my $multiplot_title = = qq{set multiplot layout 2, 1 title "The Evalua +tion X" font "Helvetica-Bold,16" set key inside right bottom set xlabel "{/Helvetica=12 Years}" norotate set ylabel "{/Helvetica=12 Results}" rotate by -270 } ; my %args = ( years => q{[2005.5:2011.5]}, yscala => q{[:100]}, sources => [ { source => q{abc}, color => q{#000080}, title => q{"{/Helvetica=10 ABC_Stuff}"}, }, { source => q{def}, color => q{#800080}, title => q{"{/Helvetica=10 DEF_Stuff}"}, }, { source => q{ghi}, color => q{#008000}, title => q{"{/Helvetica=10 GHI_Stuff}"}, }, { source => q{jkl}, color => q{#000000}, title => q{"{/Helvetica=10 JKL_Stuff}"}, }, ], topic => q{this}, abnormality_border => q{mno}, ); my $first = build_command('01', %args); my $second = build_command('02', %args); my $third = build_command('03', %args); my $fourth = build_command('04', %args); my $fifth = build_command('05', %args); my $sixth = build_command('06', %args); sub build_command { my $num = shift; my %args = @_; my $cmd = sprintf( qq{plot %s %s }, $args{years}, $args{yscala} ); for my $source (@{$args{sources}}){ $cmd .= sprintf( qq{"C:/Stuff/%s_%s_%s.csv" title "" with errorbars lt rgb "%s" l +w 2, }, $source->{source}, $args{topic}, $num, $source->{color}, ); $cmd .= sprintf( qq{"C:/Stuff/%s_%s_%s.csv" title %s with lines lt rgb "%s" lw 3, + }, $source->{source}, $args{topic}, $num, $source->{title}, $source->{color}, ); } $cmd .= sprintf( qq{"C:/Stuff/%s_%s_%s.csv" with steps lt 1 lw 5 title "{/Helvetica +=10 Abnormality Border}" \n\n\n}, $args{abnormality_border}, $args{topic}, $num, ); return $cmd; } open my $P, "|-", "C:/.../gnuplot" or die; printflush $P qq[ set terminal postscript color portrait set output "$output" set termoption enhanced set encoding iso_8859_1 ###################################### $multiplot_title set title "The First Indicator" $first set title "The Second Indicator" $second unset multiplot ###################################### $multiplot_title set title "The Third Indicator" $third set title "The Fourth Indicator" $fourth unset multiplot ###################################### $multiplot_title set title "The Fifth Indicator" $fifth set title "The Sixth Indicator" $sixth unset multiplot ###################################### ]; close $P;

Replies are listed 'Best First'.
Re^2: How to declare variables per loop
by wfsp (Abbot) on Oct 13, 2011 at 07:53 UTC
    Looks good. I would leave it at that but, perhaps for future reference, I couldn't resist a further tweak. :-)
    # ... my %titles = ( q{01} => q{First}, q{02} => q{Second}, q{03} => q{Third}, q{04} => q{Fourth}, q{05} => q{Fifth}, q{06} => q{Sixth}, ); my @cmds; for my $number (qw{01 02 03 04 05 06}){ my $cmd = build_command($number, $titles{$number}, %args); push @cmds, $cmd; } # ...
    sub build_command { my $num = shift; my $title = shift; my %args = @_; my $cmd = sprintf( qq{set title "The %s Indicator\n"}, $title, ); # ....
    ... ###################################### $multiplot_title $cmds[0] $cmds[1] unset multiplot ...
      Thank you very much wfsp.
      After overnight I thought even that it were possible to combine the title for the evaluation and the titles for the diagramms in one hash. One should then input a shorthand for the evaluation at the command line.
      This below is just a fragment, I am tinkering now : -)
      Thanks again!
      VE
      use strict; use warnings; if (!defined $ARGV[0]) { die " Please type the shorthand: THIS for This Great Evaluation THAT for That Small Evaluation "; } my $topic = $ARGV[0]; my %module = ( THIS => [ { name => q{This Great Evaluation}, indicator => { '01' => q{The First}, '02' => q{The Second}, }, }, ], ); print ${module}{$topic}[0]->{name}; print ${module}{$topic}[0]->{indicator}{'01'}; print ${module}{$topic}[0]->{indicator}{'02'};
Re^2: How to declare variables per loop
by aartist (Pilgrim) on Oct 16, 2011 at 13:31 UTC
    My comment is about your Perl Module installation. You can use local::lib and install Perl Module in your home directory. Write the appropriate code using GnuPlot module. Show it to your manager to ask the sys-admin to install that for you in the appropriate directory. Your problem can be more general to lot of people and there has to appropriate solution which gives more freedom to developers and hence better CPAN for all of us.
        Can you change your platform to linux?( GNU or Ubuntu) It is easy to install for yourself. You can then put the output anywhere you like via mail/ftp/shared drive etc.. Solution can take extra time and effort but worthwhile in the long run.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://931010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found