Hello Monks,

I've been rather ambitious with perl projects lately, porting my html template from a linux laptop to a windows 8.1 laptop with a cygwin installation. I was stunned with how little resistance I encountered, but I do have a couple problems. First, I'd like to address the main topic of this post, which is creating a sensible control for uploading binary content to my site. Let me show you what I have but preface it by saying that I'm without perltidy at the moment (see question 2).

sub upload { use strict; use warnings; use 5.010; use Net::FTP; use Data::Dumper; my ($rvars, $rftp) = @_; my %vars = %$rvars; # get local files into an array my @filetypes = qw/jpg jpeg png ogv mp4 m4v webm/; my $pattern = join '|', map "($_)", @filetypes; my @matching; opendir my $eh, $vars{"to_vids"} or warn "can't open vids $!\n"; while (defined ($_ = readdir($eh))){ next if m/~$/; next if -d; if ($_ =~ /($pattern)$/i) { push(@matching, $_); } } closedir $eh; # stat local files, create hash #my %stat = map { # lstat($_) or die "Can't lstat $_: $!"; # $_ => { # s => ( -s _ ), # } #} @matching; #my $hashref = \%stat; #print Dumper($hashref); $rftp->cwd("/pages/eh5v.files") or warn "cwd failed in main $!\n"; my $rlist = $rftp->ls(); say "list is @$rlist"; $rftp->binary or warn "binary failed$!\n"; for ( @matching) { #say "matching is @matching"; my $a = file($vars{"to_vids"},$_); my $sa = $a->stringify; #$rftp->put($sa, $_) or warn "put failed $@\n"; } $rftp->ls(); return $rftp; }

The relevant part of the output is:

loading vids list is . .. kitchen.jpg kitchen.m4v kitchen.webm stairs.jpg stairs.m4 +v

What am I trying to do? I want a control to loop through the above files, and first see whether it exists on the remote server. If not, we upload it. If yes, then I'm interested in whether they are either a differing size or creation date. That's what the commented lstat part was to address, but I got errors out of that, because I didn't build the full path. (I think.) If they are different, I want a prompt to overwrite with the default being yes. If they are not different, then I want a prompt to overwrite with the default being no. It would be cool if this could work on a five-second timer. Furthermore, I would like not to create race conditions. And finally, I'd like to have a portion of code to deal with error handling such as time-outs, or directory doesn't exist. The directory, of course "should" exist, but that's one of those words....

So that's very ambitious, and I'm not completely-wed to any part of the spec if it's ill-advised, but I thought I'd throw the whole thing out there in the original post. If I get it right once, it's eminently re-usable.

I have 2 other questions that are unrelated to the above. I don't think they deserve their own threads. To the extent that a subthread lasts more than one level, maybe we can rename it appropriately. How do I get CPAN to kickstart?

$ perl -MCPAN -e shell Set up gcc environment - 3.4.5 (mingw-vista special r3) cpan shell -- CPAN exploration and modules installation (v1.9800) Enter 'h' for help.

This hangs. I'm running the 64-bit cygwin download that is no more than 2 weeks old on a 64-bit windows 8.1 machine. Do I have cpan and not know it? I don't think so:

Fred@Psiborg ~/pages2/krov $ sudo cpan -bash: sudo: command not found Fred@Psiborg ~/pages2/krov $ cpan -bash: cpan: command not found Fred@Psiborg ~/pages2/krov $ cpan My :: Module -bash: cpan: command not found Fred@Psiborg ~/pages2/krov $

Finally, I reached the level of Scribe recently, and I think it would behoove me to have a better brand name. To this end, I'd like to change my username to something cooler and more-identifiable than my current one, which is just an arbitrary 'nym. How do I do that?


In reply to a full-featured control for uploading files and a couple other tidbits by Aldebaran

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.