Zasinger wrote:
> Hello beginners,
>

Welcome...

> I'm  a  bit lost: I just installed perl yesterday and so far
> it  seems  to  have  massive  and appealing potential, I can
> hardly belive what I am seeing.
> 
> I'm  very, very rusty in any sort of coding having been away
> from it for over 15 years. I've been working at learning all
> about 3d model making in that time.
> 
> I  want to use Blitz3D to display some 3d representations of
> weather.  It can't get the data I seek as far as I can tell,
> but  perl  can it seems, and from what I've seen in 48 hours
> it's very good at it indeed.
> 
> I'm now stuck:
> 
> I've so far got perl to use Net::FTP
> 

Ok. Good choice of modules it is the defacto standard for doing FTP from
Perl.  I assume you have read the documentation for the module,
available at:

http://search.cpan.org/~gbarr/libnet-1.19/Net/FTP.pm

> I  can get perl to log in to weather.noaa.gov and drill down
> to /data/observations/metar/decoded
> 

Nice start.

> I can get single files from there if I know their names, but
> I'd  like  to  write  a  bit  of  code  (which  I am calling
> freshen.plx at this point)
> 
> The  idea  is  that  it  would freshen my local copy of that
> directory,  but  only  for  files  starting  with  "EG"  for
> example.
> 
> I'm thinking I need some way to do the equivalent of mget (I
> think  that is the regular ftp type command) and I'd like to
> mget "EG*.TXT" as far as I can figure out.
> 

To my knowledge 'mget' is usually just a command implemented by the
client and has no true FTP relation. Which is likely why you need to
emulate it directly with your own code.

> I've  no idea how I'd do the wild card bit, so far it hasn't
> worked out as I'd hoped it might.
> 
> It  seems that mget isn't implemented so I next thought that
> a  directory  listing of that directory as a file might be a
> good way to try next.
> 
> How might I do that?
> 
> I  guess I could then pick lines off that file one line at a
> time  to  get these files one at a time? Although I'm not at
> all clear how I'd manage that bit just yet! ;O)
> 

This sounds like a pretty good approach, so we need a directory listing
and way to loop over it checking filenames.... from the Net::FTP docs we
learn that the way to get a directory listing is,

my @file_list = $ftp->ls;

Now we need to loop over those checking for needed files,

foreach my $file (@file_list) {
  if ($file =~ /^EG.*\.TXT$/) {
     # found an EG file, get it
  }
}

In the above example I use a Regular Expression to test each filename to
see if the filename starts with 'EG' followed by zero or more
characters, and ending with '.TXT'. For more reading on regular expressions,

perldoc perlretut
perldoc perlre

That is the verbose way to do it. Some might suggest,

foreach my $file (grep /^EG.*\.TXT$/, $ftp->ls) {
  # found an EG file, get it
}

'grep' is a built-in that allows us to loop over a list pulling out
those items we want.

perldoc -f grep

Based on these examples and the docs I leave it as an exercise to make
this more efficient by pulling only those files that need to be updated.
The 'dir' method, or some combination of 'mdtm' and/or 'size' should
help, along with 'stat' on the local side.

perldoc -f stat

> If anyone can help me figure this out I'd be really glad.
> 
> I've  been working through some examples in "Beginning Perl"
> and  it's fairly slow going and rather dry reading in places
> and  some  of  it  is a bit out of date too it would seem. I
> think  this  is  as  a  result  of me having .8 and it being
> written  with  .6  as the latest and greatest at the time, I
> get  the  feeling  some  stuff  has  changed  to  this books
> detriment  perhaps.  Mostly by scanning through some remarks
> in  the  latest  release notes (I think that was where I saw
> them).  I've  no  idea yet if it's trivial to patch up older
> code so it would work once again.
> 

Haven't read it. If you find it unsatisfactory I (and most others here)
would recommend "Learning Perl, 4th Edition" from O'Reilly (aka "The
Llama"). The 4th is a brand new release.  There should be very few
things in a beginner's book that would have changed from 5.6 to 5.8
(really *any* release in the 5 series).

> Also I got that impatience thing going on too as I've waited
> a  couple of years to get at this thing, I'd started to feel
> it  was  never going to happen but then perl happened to me,
> making my weekend into a minor bedlam!! ;O)
> 

The archives of this list are also an excellent resource, be sure to
Google them before asking a question, there is a *good* chance it will
have already been answered (more than once).

Good luck, welcome to the world of Perl,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to