Re: a script to create html, populate it with images, and upload it to the net

Discussion in 'Perl Misc' started by Jürgen Exner, Nov 23, 2012.

  1. Cal Dershowitz <> wrote:
    >I come back with a task that I've done before several times with varying
    >degrees of proficiency. Unfortunately, a lot of gains were erased by
    >having a hard drive erased, and I'm left to cobble together stuff I've
    >done successfully before.
    >
    >Q1) Before I make a source posting, can someone tell me how to search
    >clpmisc for stuff that I've posted before?


    By checking DejaNews. Oooops, that was swallowed by Google a few years
    ago.
    Or re-download all the postings that your newsserver is still carrying
    (some have years of history, some only weeks if that much) and then use
    the Search feature of your News client.

    >Q2) How hard would it be to roll my own search engine, given the narrow
    >scope in question?


    That totally depends upon how sophisticated that search engine should
    be.

    >We can assume that it's a usenet post by Cal Dershowitz in the last
    >year. One could download the whole compendium in less than a minute,
    >and stuff it into an array.


    Well, if you Newsprovider still carries that year of history, then what
    is wrong with just searching in your News client?

    jue
    Jürgen Exner, Nov 23, 2012
    #1
    1. Advertising

  2. Jürgen Exner

    Jim Gibson Guest

    Re: using templates effectively act Two scene 1

    In article <>, Cal
    Dershowitz <> wrote:

    > On 11/26/2012 12:49 AM, Ben Morrow wrote:
    > >
    > > Quoth Cal Dershowitz <>:
    > >>


    > > The simplest template system is sprintf. It is rather limited, but
    > > sufficient for what you are doing here. First you create a template
    > > outside the loop, with printf %-codes in it:
    > >
    > > my $template = <<'TEMPLATE';
    > > <img src="/images/%s"/>
    > >
    > > <p>%s</p>
    > > TEMPLATE

    >
    > What would be the filename this is in?


    That would be in your Perl program source file.

    > >
    > > then you open your text file
    > >
    > > open my $CAPTIONS, "<", "captions.txt" or die ...;
    > >
    > > then in the loop you read a line from the file and fill in the template
    > >
    > > my $remote_file = ...;
    > > my $caption = <$CAPTIONS>;
    > >
    > > $ftp->put($name, $remote_file) or ...;
    > >
    > > printf $fh $template, $remote_file, $caption;
    > >
    > > This assumes, of course, that the captions are listed in the file in the
    > > order this script will find the files to be uploaded, and that the
    > > captions in the file are already in HTML. If they might not be in the
    > > right order you will need a more complicated file format than 'one line
    > > per file', so you can read it into a hash and look up the caption you
    > > need. If they aren't in HTML (if they are plain text which might contain
    > > special characters like <) you need to convert them to HTML using
    > > something like HTML::Entities.


    --
    Jim Gibson
    Jim Gibson, Nov 26, 2012
    #2
    1. Advertising

  3. Jürgen Exner

    C.DeRykus Guest

    Re: using templates effectively act Two scene 1

    On Monday, November 26, 2012 7:11:31 PM UTC-8, Cal Dershowitz wrote:
    > On 11/26/2012 12:49 AM, Ben Morrow wrote:
    >
    > >

    >
    > > Quoth Cal Dershowitz <>:

    >
    > >>

    >
    > >> # main control

    >
    > >> for my $name (@files) {

    >
    > >> print "name is $name\n";

    >
    > >> my ($ext) = $name =~ /([^.]*)$/;

    >
    > >> print "ext is $ext\n";

    >
    > >>

    >
    > >> @matching = map /image_(\d+)\.$ext$/, @list;

    >
    > >> print "matching is @matching\n";

    >
    > >> push( @matching, 1 );

    >
    > >> @matching = sort { $a <=> $b } @matching;

    >
    > >> $winner = pop @matching;

    >
    > >> my $newnum = $winner + 1;

    >
    > >

    >
    > > There is no need to redo the search through the list every time. If you

    >
    > > move this code to a sub you can just remember the next number for each

    >
    > > $ext, something like

    >
    > >

    >
    > > my %next_for_ext;

    >
    > > sub next_for_ext {

    >
    > > my ($ext) = @_;

    >
    > >

    >
    > > unless (exists $next_for_ext{$ext}) {

    >
    > > my @matching = map ... @list;

    >
    > > ...;

    >
    > > $next_for_ext{$ext} = pop @matching;

    >
    > > }

    >
    > >

    >
    > > return ++$next_for_ext{$ext};

    >
    > > }

    >
    > >

    >
    > > then in the loop just call the sub

    >
    > >

    >
    > > my $newnum = next_for_ext $ext;

    >
    > >

    >
    > > (and, of course, you don't then have to keep adding the new names to the

    >
    > > list).

    >
    > >

    >
    >
    >
    > $ ./ftp4.pl my_ftp
    >
    > ...
    >
    > name is target4/26-img_0004.jpg
    >
    > ext is jpg
    >
    > Can't locate object method "next_for_ext" via package "jpg" (perhaps you
    >
    > forgot to load "jpg"?) at ./ftp4.pl line 72.
    >
    > ...



    The perl compiler needs some help if
    you don't add the parentheses on that
    next_for_ext call.

    Easiest correction:

    my $newnum = next_for_ext( $ext );

    or just add at the top:

    use subs q/next_for_ext/



    For more info: perldoc subs

    --
    Charles DeRykus
    C.DeRykus, Nov 27, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Stevens
    Replies:
    1
    Views:
    348
    Curt_C [MVP]
    Dec 28, 2004
  2. Guest
    Replies:
    4
    Views:
    984
    Alexey Smirnov
    Jun 23, 2007
  3. Replies:
    0
    Views:
    380
  4. Prakash
    Replies:
    3
    Views:
    452
    Ray at
    Nov 12, 2003
  5. Enjoy Life
    Replies:
    2
    Views:
    272
    Roland Hall
    Feb 23, 2005
Loading...

Share This Page