PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > minimal nntp client
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
minimal nntp client

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2008, 02h32   #1
Gerry Ford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut minimal nntp client

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::Parse;

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,
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 13/03/2008, 10h45   #2
Anton Bangratz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: minimal nntp client

Gerry Ford wrote:
> 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::Parse;
>
> 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,


Shameless plug:

There's my small library at
http://rubyforge.org/projects/ruby-net-nntp/. Can be installed via
rubygems (gem install ruby-net-nntp) and used according to the
documentation.

It's still not 100% feature complete, so I consider it in beta state,
but covers most ofyour needs, and if you need assistance, just ask me.

tony

  Réponse avec citation
Vieux 13/03/2008, 11h10   #3
Thomas Wieczorek
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: minimal nntp client

On Thu, Mar 13, 2008 at 2:32 AM, Gerry Ford <wade@zaxfuuq.net> wrote:
>
> Q1) What is the ruby analog to the perl use of strict and warnings?
>


I am not really experienced in Perl, but as I understand it. strict
enforces that you have to declare variables, so that when you mistype
something an error occurrs. You get a NameError in Ruby when you use a
variable which hasn't any value assigned:

# irb
# foo has a value
foo = "Hello"
puts foo # "Hello"

# bar is not declared
puts bar

# NameError: undefined local variable or method `bar' for main:Object
# from (irb):6

As far as I know you can't turn warnings on from your code, but you
can run Ruby with the "-w" option which shows warnings.

  Réponse avec citation
Vieux 14/03/2008, 04h58   #4
Gerry Ford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: minimal nntp client

Anton Bangratz wrote:
> Gerry Ford wrote:


>> Q2) What analog does ruby have of net:nntp?
>>
>> Thanks in advance,

>
> Shameless plug:
>
> There's my small library at
> http://rubyforge.org/projects/ruby-net-nntp/. Can be installed via
> rubygems (gem install ruby-net-nntp) and used according to the
> documentation.
>
> It's still not 100% feature complete, so I consider it in beta state,
> but covers most ofyour needs, and if you need assistance, just ask me.

Thanks Anton.

I downloaded your library as well as the nntp gem. My next question is
where I should put it. When I downloaded a perl date::parse module,
what they expect is that it gets put in the site file, and then has a
folder called 'Date' wherein lies Parse.pm

This screenshot shows my gem subdirectory: http://zaxfuuq.net/ruby5.jpg
The directory just keeps sprawling. Where all would ruby.exe look
for something required?

My second question is how to call something from these gems. They seem
inscrutable to me.

Beautiful night here in New Mexico. Cheers.
--



--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 14/03/2008, 05h05   #5
Gerry Ford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: minimal nntp client

Thomas Wieczorek wrote:
> On Thu, Mar 13, 2008 at 2:32 AM, Gerry Ford <wade@zaxfuuq.net> wrote:
>>
>> Q1) What is the ruby analog to the perl use of strict and warnings?
>>

>
> I am not really experienced in Perl, but as I understand it. strict
> enforces that you have to declare variables, so that when you mistype
> something an error occurrs. You get a NameError in Ruby when you use a
> variable which hasn't any value assigned:
>
> # irb
> # foo has a value
> foo = "Hello"
> puts foo # "Hello"
>
> # bar is not declared
> puts bar
>
> # NameError: undefined local variable or method `bar' for main:Object
> # from (irb):6
>
> As far as I know you can't turn warnings on from your code, but you
> can run Ruby with the "-w" option which shows warnings.

Thanks, Thomas. It sounds like ruby is already "strict" in the perl
sense. As for warnings, I'll enable them on the goocher, which is what
I call a dos command that I comment out at the end of a script: Thus

# perl client2.pl >text59.txt 2>text56.txt
__END__
becomes, in ruby, with warnings enabled:

# ruby -w client2.rb >text59.txt 2>text56.txt
__END__

Cheers.
--
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h16.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12765 seconds with 13 queries