As usual, I have learned a lot from your replies. Thanks.

dragonchild, I never got a chance to test it, only post this question, as I had my son on my lap ;-) He's now in bed, so I can reply.

The reason I posted this, is because I am going back to my old programs after learning more, and trying to make them clean and have less code.

The program in question was written for my wife, as she always asks me how to resize images and upload them to ebay. I wrote this, called ebaypics, which is then saved in ~/.gnome2/nautilus-scripts she then right clicks in the folder she has the photos in, and that's it.

#!/usr/bin/perl use strict; use warnings; use Net::FTP; use Mail::Sendmail; use Image::Magick; use Term::ProgressBar; ################################################# # program: ebaypics # # license: GPL # # author: Gavin Henry # # # # version: v0.1 # # # # first draft : 22-09-04 # # last update : 27-09-04 # ################################################# my @images = <*.jpg>; my $resize = '640x480'; my ($image,$process); my $ftpsite = 'ftp.somewhere.net'; my $website = 'http://www.somewhere.com/ebay'; my $remotedir = '/htdocs/ebay'; my $username = 'user'; my $password = 'pass'; my $to = '"My name" <my.name@me.co.uk>'; my $from = '"ebaypics" <ebaypics@me.com>'; my $sep = '-' x 76 . "\n"; my $time = localtime; my $progress = Term::ProgressBar->new({name => 'Scaling images', count => scalar @images, ETA => 'linear'}); # Messages print "\n", $sep, "Starting....\n", $sep; &resize; my @thumbs = <thumbnail-*.jpg>; # Get pictures and upload my $ftp = Net::FTP->new("$ftpsite", Timeout => 30) or die "Sorry I can't connect: $@\n"; $ftp->login($username, $password) or die "Wrong password. Please call Gavin.\n"; $ftp->cwd("$remotedir"); foreach (@thumbs) { $ftp->put($_) or die "Can't find the resized pictures: $!\n"; } $ftp->quit() or warn "Couldn't quit. Damn.\n"; my @email_links = links($website, @thumbs); my %mails = ( To => "$to", From => "$from", Subject => "Here are the links to your pictures", Message => "Click on any of the links below to check the pictures" + . " are correct, then copy and paste them into your" . " ebay listing.\n\n" . " Weblinks:\n" . " @email_links\n\n" ); sendmail(%mails); print "\n", $sep, "Resizing of images complete at $time. E-mail sent w +ith website links.\n", $sep; # Subroutines sub resize { print "\n", $sep, "Resizing images.....this may take some time.... +.\n", $sep; foreach (@images) { $image = Image::Magick->new(); $process = $image->Read("$_"); $process = $image->Resize(geometry => "$resize"); warn "$process" if "$process"; $process = $image->Write("thumbnail-$_"); warn "$process" if "$process"; $progress->update(); } print "\n", $sep, "Resizing complete, starting upload to webspace. +....\n", $sep; } # Generate weblinks sub links { my ($url, @list) = @_; my @return; foreach (@list) { push @return, "$url/$_\n"; } return @return; }

Needs a bit of work ;-)

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!

In reply to Re^2: Turning foreach into map? by ghenry
in thread Turning foreach into map? by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.