#!/usr/bin/perl
use strict;
use warnings;

my $dir='/home/e3/Media Gallery/Camera Pictures';
die "$dir: $!" unless -d $dir;
chdir $dir or die $!;

my $outfile='index.html';
open my $O, ">:encoding(utf8)", $outfile;

my $header=sprintf "<html><title>pics@".$dir."</title><head></head><body>";
printf $O "%s\n", $header;

foreach my $file (`ls *jpg`) {
  chomp $file;
  my $row=sprintf "<a href=\"file://%s/%s\" alt=\"%s\" width=\"100px\" height=\"75px\" />\"%s\"</a><br>", $dir, $file, $file, $file;
#<a href="http://www.yourdomain.com/images/sun.jpg">
#<img src="http://www.yourdomain.com/images/sun.jpg" alt="Sun Thumbnail Image" width="100px" height="75px" /></a>
#</p>
  printf $O "%s\n", $row;
}

my $footer=sprintf "</body></html>";
printf $O "%s\n", $footer;

my $cmd="/bin/cat $outfile";
my @res=`$cmd`;
foreach my $r (@res) {
  printf $O "%s\n", $r;
}

#Use LWP for this:
$cmd=sprintf "scp -p %s sirdavec\@sirdave.com:src", $outfile;
@res=`$cmd`;
foreach my $r (@res) {
  printf $O "%s\n", $r;
}

$cmd="/home/e3/bin/chrome http://sirdave.com/src/$outfile";
@res=`$cmd`;
foreach my $r (@res) {
  printf $O "%s\n", $r;
}

sub doCmd {
  my $c=shift;
  foreach my $r (@res) {
    printf $O "%s\n", $r;
  }
}
