G
Gerry Ford
I'm relatively new to ruby, having had one thread regarding commenting.
I'd like to move on to a more authentic task. I would like to write an
analogous script in ruby as this perl script:
## minimal nntp client
#!/usr/bin/perl -1
use strict;
use warnings;
use Net::NNTP;
use Date:arse;
my $nsrv='news.newsgroups.com';
my $grp='alt.religion.mormon';
my $USER = '';
my $PASS = '';
my $nntp=Net::NNTP->new($nsrv) or die "Can't login to `$nsrv'$!\n";
$nntp->authinfo($USER,$PASS) or die $!;
my (undef, $first, $last, undef)=$nntp->group($grp)
or die "Can't access $grp\n";
my ($since, @arts)=time-5*60*60;
for (reverse $first..$last) {
my %hdr=map /^(\S[^:]+):\s(.*)$/g, @{$nntp->head($_)};
defined(my $date=$hdr{'NNTP-Posting-Date'}) or next;
defined(my $time=str2time $date)
or warn "Couldn't parse date for article $_ ($date)\n"
and next;
last if $time < $since;
unshift @arts, $_;
}
$nntp->article($_,\*STDOUT) for @arts;
# perl client2.pl >text59.txt 2>text56.txt
__END__
This script retrieves the messages of the last five hours in the
specified ng.
Q1) What is the ruby analog to the perl use of strict and warnings?
Q2) What analog does ruby have of net:nntp?
Thanks in advance,
I'd like to move on to a more authentic task. I would like to write an
analogous script in ruby as this perl script:
## minimal nntp client
#!/usr/bin/perl -1
use strict;
use warnings;
use Net::NNTP;
use Date:arse;
my $nsrv='news.newsgroups.com';
my $grp='alt.religion.mormon';
my $USER = '';
my $PASS = '';
my $nntp=Net::NNTP->new($nsrv) or die "Can't login to `$nsrv'$!\n";
$nntp->authinfo($USER,$PASS) or die $!;
my (undef, $first, $last, undef)=$nntp->group($grp)
or die "Can't access $grp\n";
my ($since, @arts)=time-5*60*60;
for (reverse $first..$last) {
my %hdr=map /^(\S[^:]+):\s(.*)$/g, @{$nntp->head($_)};
defined(my $date=$hdr{'NNTP-Posting-Date'}) or next;
defined(my $time=str2time $date)
or warn "Couldn't parse date for article $_ ($date)\n"
and next;
last if $time < $since;
unshift @arts, $_;
}
$nntp->article($_,\*STDOUT) for @arts;
# perl client2.pl >text59.txt 2>text56.txt
__END__
This script retrieves the messages of the last five hours in the
specified ng.
Q1) What is the ruby analog to the perl use of strict and warnings?
Q2) What analog does ruby have of net:nntp?
Thanks in advance,