[Chester LUG] Happy new year and broken perl

Stuart Burns stuart.james.burns at gmail.com
Fri Jan 2 20:57:54 UTC 2009


Hi Everyone,

Hope everyone had a good holiday and a good new year. I'm glad to be back,
having suffered extreme internet withdrawl. (Ok so internet was there, but I
wasn't paying £8 an hour to surf the internet!!!

So I also have a little problem with my perl code. It's almost there.
Basically, there is an issue with it is not rotating through multiple pages
as it should. It seems to read the first one, and then not increment, if
that makes sense. So I post it here, in the hope that someone can help me, a
perl wannabe.

Cheers

Stu

#!/usr/bin/perl

# variables

$sites_file="sitefile.txt";  # File that holds the config
$use_descriptors=1; # If this is enabled, the 3rd column alt tags will be
included to enhance SEO.

# Read in the details of sites that are going to be generated.

open(sites, $sites_file) || die("Could not open file");
@site_array=<sites>;
close(sites);

    foreach $site_line (@site_array){
             chomp($site_line),
                 ($site_description,
                 $site_domain,
                $site_img_file_src,
                 $site_txt_file_src,
                 $site_html_output_dir,
                 $site_html_output_file,
                 $site_html_generate_meta,
                 $site_html_style,
                 $site_html_rows,
                 $site_html_cols)=split(/\|/,$site_line);

             push(@site_desc, $site_description);
            push(@site_tld, $site_domain);
            push(@site_html_or_img_array, $site_html_style);
            push(@site_img_input_folder, $site_img_file_src);
            push(@site_link_input_array, $site_txt_file_src);
            push(@site_html_output_folder_array, $site_html_output_dir);
            push(@site_html_output_file_array, $site_html_output_file);
            push(@site_html_input_generate_meta_array,
$site_html_generate_meta);
            push(@site_html_txt_or_img_array, $site_html_style);
            push(@site_html_rows, $site_html_rows);
            push(@site_html_cols, $site_html_cols);

            $site_inputs_count++;
    }

 print "\n\n\n" . 'Site creation tool' . "\n\n\n";
 print  'Site input file: ' . $site_txt_file_src ."\n";

    for ($current_site_counter = 0; $current_site_counter <
$site_inputs_count; $current_site_counter++) {
                        $data_file =
@site_link_input_array[$current_site_counter];

                        open(DAT, $data_file) || die("Could not open
file!");
                            @raw_data=<DAT>;
                        close(DAT);

    # Read in data for the page to be generated

        foreach $data_line (@raw_data){
                 chomp($data_line);
                 ($c_jpg,$c_url,$c_descriptor)=split(/\|/,$data_line);
                push(@images, $c_jpg);
                push(@urls, $c_url);
                push(@descriptors, $c_descriptor);
                $total_input_lines++;
    }

        $site_desc_out = @site_dec[$current_site_counter];
        $site_tld_out = @site_tld[$current_site_counter];
        $site_html_style_out =
@site_html_or_img_array[$current_site_counter];
        $fulloutputpath = @site_link_input_array[$current_site_counter];
        $fullimginputpath = @site_img_input_folder[$current_site_counter];
        $fulloutputpath=
@site_html_output_folder_array[$current_site_counter] .
            @site_html_output_file_array[$current_site_counter];
        $rows=@site_html_rows[$current_site_counter];
        $cols=@site_html_cols[$current_site_counter];

        open (outputfile, ">$fulloutputpath");

        print "\n\n\n" . "Running Input for: " .
$site_desc[$current_site_counter] . "\n";
        print
"---------------------------------------------------------------------------";
        print "\nImage Input folder is" . ': ' . $fullimginputpath ."\n";

        print "Output file is" . ': ' . $fulloutputpath . "\n";

      print outputfile '<html>' . "\n";
        print outputfile '<table border="0">' . "\n";

        print 'Type detected as: ';

        if ($site_html_style_out eq 'I') {
            print "Images\n";
        } else {
            print "Text\n";
                }

        $total_images_required = $rows * $cols;

                for ($x = 0; $x < $rows; $x++) {
                                print outputfile "\t" . '<tr>' . "\n";

                        if ($site_html_style_out eq 'I')  {


                        for ($i = 0; $i < $cols; $i++) {

$random_img=int(rand($total_input_lines));
                        print outputfile "\t\t" . '<td>' . '<a href=' .
                                "\"" . @urls[$random_img] . "\"\>"     .
                                '<img src=' . "\"" . $site_tld_out .
@images[$random_img] . '"' . "\>" .
                                '</td>' . "\n";
                            }
                                } else {

                                         for ($i = 0; $i < $cols; $i++) {

$random_img=int(rand($total_input_lines));
                                            print outputfile "\t\t" .
                                                '<td><a href=' . "\"" .
                                                    @urls[$random_img] .
'">'     .
                                                 @images[$random_img]  .
'</a>' .
                                             '</td>' . "\n";

                                         }
                                }
                          print outputfile "\t" . '</tr>' . "\n";
                                }

    print outputfile '</table>' . "\n";
    print outputfile '</html>' . "\n\n";
    }
    print "\n\n\n" . 'Run Completed ' . "\n\n";
    close (outputfile);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/chester/attachments/20090102/f8c73169/attachment.html>


More information about the Chester mailing list