in reply to Problem with creating Files

Let me see if I understand this correctly. You have two arrays, let's say @array1 and @array2. Each contains a list of file prefixes, and you're creating HTML files that are called ${prefix1}LAY.html, with $prefix1 ranging over all elements of @array1, and (similarly) ${prefix2}DFT.html, with $prefix2 ranging over all elements of @array2.

Furthermore, while the elements of @array1 and @array2 come from the same pool of potential values, any given such value might or might not appear in either array: @array1 might have elements that are not in @array2, and @array2 might have elements that are not in @array1. So in those cases, there'll only be a ${prefix}LAY.html or a ${prefix}DFT.html file, not both, and (naturally) you don't want to the one that exists to link to the one that does not.

Is that right?

If so, without seeing more of your code, I'd say you should simply pass the information on whether a given prefix appears in either array to your createButtons sub.

Replies are listed 'Best First'.
Re^2: Problem with creating Files
by David92 (Sexton) on Jul 25, 2014 at 09:53 UTC
    Wow @AppleFilter, you describe my problem that myself! Do you have any suggestion how I might do that? Keep in mind that everything is generalized, meaning:

    I have only 3 files for PERL:

    run.pl mainModule.pm (here I get the statistics info) and htmlModule.pm

    RUN.PL:

    It consists of calls to sub routines.

    1. Are the calls to subroutines in mainModule.pm to get the numbers (for statistic) for each file (html) -> this is stored in hash. After having values, I store also the elements that have this values inside @array1

    2. Back to .pl I loop the Array to store the numbers inside variables, these variables will be then put inside HTML to as values for the chart. I use something like:

    foreach $element (@array1){ $var1 = $hash{value1}; $var2 $hash{value2} createBarchart(....); }

    I use 2 different run.PL, because there are two different database's that I get the values from (for e.g. database1 and database2 -> they differ with unique ID which I provide as an INPUT when I call subs that get me the values)

      I'm not sure I fully understand your problem but try this
      #!perl use strict; # test for ('file1LAY.html','file1DFT.html','file2DFT.html'){ open OUT,'>',$_; createButtons(undef,$_); } sub createButtons{ my ($outfile,$filename) = @_; my %file=(); if ($filename =~ m/(.+)(?:LAY|DFT)\.html/){ for my $s ('LAY','DFT'){ $file{$s} = './'.$1.$s.'.html'; $file{$s} = '#' unless (-e $file{$s}); } } print qq! <a href="$file{'LAY'}" class="button_lay">Layout</a> <a href="$file{'DFT'}" class="button_dft">DfT</a>\n </div>\n!; }
      poj
      I'd like to help you, but it would really help to see a bit more actual code there; based on general descriptions, I'm afraid I can only give general suggestions.