## This perl script creates a "gallery" HTML file, # Input is a list of images and their titles and associated URLs. # Output is an HTML file, which displays the images with links to the URLs # Optionally, the output can be just the titles with links. # # Usage example: # perl -w mk-gallery2.pl --url_prefix http:// --title "A Title" list.txt # $debug = 1; # 1 means print debug statements # Flag to determine the style of the output # Can be set to 1 with "--dialup" # $dialup = 0; # 1 means don't display the images on the webpage, use text # Prefix to be added to the URLs supplied in the input # Can be modified with "--url_prefix xxx" # $url_prefix = 'http://'; # Title of the HTML document # Can be modified with "--title xxx" $title = 'gallery'; # the title of the HTML file # get the command-line parameter(s) # @args = @ARGV; print STDERR "# args = ", @args+0, "\n" if ($debug>0); while (0+@args > 0) { $a0 = $args[0]; last if $a0 !~ /^--/; if ($a0 eq "--dialup") { $dialup = 1; shift @args; } elsif (0+@args > 1 && $a0 =~ /--url_prefix/g) { $url_prefix = $args[1]; shift @args; shift @args; } elsif (0+@args > 1 && $a0 =~ /--title/g) { $title = $args[1]; shift @args; shift @args; } } ## Not sure if this works @ARGV = @args; ## read entire file from STDIN # $sav = $/; $/ = undef; $list = <>; #print "file contains: '" , $list, "'\n"; $/ = $sav; ## Convert the file to a list of lines @lines = split "\n", $list; # Create the start and end of the HTML file # $head = <$title END ; $tail = < END2 ; # Print the start of the HTML file print $head; print '

' . $title . '

' . "\n"; # Process the input lines # foreach (@lines) { # Skip comment and blank lines next if /^\s*#/; next if ! /\w/; # Each line has at least 3 comma-separated fields @fields = (); @fields = split /\s*,\s*/ ; next if (0+@fields < 3); ($title, $url, $img_path) = @fields; # Add prefix to the URL $url = $url_prefix . $url; # Create and print the HTML link # print ''; if ($dialup) { print $title . ' ' . '  ', "\n"; } else { print ''; print ''; print ' ', "\n"; } } print $tail;