CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
doint a request - and storing the results....a 16 liner

 



dilbert
User

Jun 29, 2014, 3:58 AM

Post #1 of 8 (1344 views)
doint a request - and storing the results....a 16 liner Can't Post

hello dear joomla-experts


today i have a question i struggle with... a perl-question...

just new to perl - i want to run this little 16 liner and do some things with it.

i want to run the script to spit out all the ppl that belong to the name

that begin with an a.
that begin with an b.
that begin with an c.


guess that this can be done with the method authors...()

hmm -do i have to run it like so:


Code
 
my $author = $p->author('A');


is this the correct way - how to itterate through a list ( a 16 liner ) for beginners

see here the full script



Code
  use Parse::CPAN::Authors; 

# must have downloaded
my $p = Parse::CPAN::Authors->new("01mailrc.txt.gz");
# either a filename as above or pass in the contents of the file
my $p = Parse::CPAN::Authors->new($mailrc_contents);

my $author = $p->author('A');
# $a is a Parse::CPAN::Authors::Author object
# ... objects are returned by Parse::CPAN::Authors
print $author->email, "\n"; # leon@astray.com
print $author->name, "\n"; # Leon Brocard
print $author->pauseid, "\n"; # LBROCARD

# all the author objects
my @authors = $p->authors;



love to hear from you




update;





the first gives out nothing


Code
 
use Parse::CPAN::Authors;

# must have downloaded
my $p = Parse::CPAN::Authors->new("01mailrc.txt.gz");
# either a filename as above or pass in the contents of the file
my $p = Parse::CPAN::Authors->new($mailrc_contents);

my $author = $p->author('LBROCARD');
# $a is a Parse::CPAN::Authors::Author object
# ... objects are returned by Parse::CPAN::Authors
print $author->email, "\n"; # leon@astray.com
print $author->name, "\n"; # Leon Brocard
print $author->pauseid, "\n"; # LBROCARD

# all the author objects
my @authors = $p->authors;



the second gives out a bunch of a list:


Code
   
#!/usr/bin/perl

use strict;
use warnings;
use YAML;
use YAML::Dumper;
use Parse::CPAN::Authors;

my $list = '01mailrc.txt.gz';

my $p = Parse::CPAN::Authors->new( $list );
my @authors = $p->authors;

my $dumper = YAML::Dumper->new;
$dumper->indent_width(1);
print $dumper->dump({dump => $p});






well how to change the script that it gives out

a. only the authors which name begin with a
b. only the authors which name begin with b
b. only the authors which name begin with c




by the way - we can store the data - instead of printing


@authors is an array of objects. we need to loop over that array and insert each author's info into the DB.

we could use the Data::Dumper module to inspect/review the structure of the @authors array. For example, if we add a print Dumper \@authors; statement our output would look like this:




But instead of printing the data, we would insert it into the db.

The DB table will need the 3 fields to hold the author's ID, name, and email address.


the questions are:


how to create the database?
how to connect to the database from our script?
how to write the insert statement?


well and now i am just reading over the DBI manual


BillKSmith
Veteran

Jun 29, 2014, 6:53 AM

Post #2 of 8 (1338 views)
Re: [dilbert] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

Use the Authors() method to get all the author objects. Use grep to select the ones of interest. Use name(), etc. on each to get the required data.

I cannot offer much help with the db. I have never installed one or created the tables.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Jun 29, 2014, 8:50 AM

Post #3 of 8 (1329 views)
Re: [dilbert] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

Why would you only want to retrieve authors beginning with a, b, or c?

This is almost an exact duplication of some of your past questions which I answered. What did you learn from those threads and what did you not understand?

Use the authors() method and instead of putting all of the returned objects into an array, simply loop over the objects as they are returned and filter/skip over the ones you don't want.


dilbert
User

Jun 29, 2014, 1:20 PM

Post #4 of 8 (1174 views)
Re: [FishMonger] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

hi there - well i want to get the data in the following mode.

- getting all Authors that

beginn with a

beginn with b

beginn with c

in the manual-pages i see the following:

http://search.cpan.org/~lbrocard/Parse-CPAN-Authors-2.27/lib/Parse/CPAN/Authors.pm


Quote
author()

The author() method returns a Parse::CPAN::Authors::Author object representing a user:


see the method:

Code
  my $author = $p->author('LBROCARD');





Quote
authors()
The authors() method returns a list of Parse::CPAN::Authors::Author objects, for each author on CPAN:




see the method:

Code
   my @authors = $p->authors;


guess that - if i am willing to do it like mentioned above - then i have to enter a

a. A
b. B
c. C
... and so forth in a certain line:




Code
 
use Parse::CPAN::Authors;

# must have downloaded
my $p = Parse::CPAN::Authors->new("01mailrc.txt.gz");
# either a filename as above or pass in the contents of the file
my $p = Parse::CPAN::Authors->new($mailrc_contents);


my @authors = $p->authors ('a');

# my $author = $p->author('LBROCARD');
# $a is a Parse::CPAN::Authors::Author object
# ... objects are returned by Parse::CPAN::Authors
print $author->email, "\n"; # leon@astray.com
print $author->name, "\n"; # Leon Brocard
print $author->pauseid, "\n"; # LBROCARD

# all the author objects
# my @authors = $p->authors;



description:
what i think that i have todo is the following..

comment out the line

Code
 # my $author = $p->author('LBROCARD');


therefore i need /(better say i replace this line )with the
following


Code
my @authors = $p->authors ('a');



you see - the a in the brackets does the magic

what do you say... !?

btw - the db-stuff i will discuss later on. When i get the script up and running - and delivering in the A-to-Z modus

i come back and report all the findings


FishMonger
Veteran / Moderator

Jun 29, 2014, 1:41 PM

Post #5 of 8 (1153 views)
Re: [dilbert] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

Did you test your proposed solution?


Quote
my @authors = $p->authors ('a');

According to the module's documentation and a 5 second review of its source code there is no reason to expect that to accomplish your goal.

The authors() method does not accept any args so it's not going to do anything with the 'a' that you're passing.

This is the source code of that method.

Code
sub authors { 
my ($self) = @_;
return values %{ $self->data };
}



(This post was edited by FishMonger on Jun 29, 2014, 1:43 PM)


dilbert
User

Jun 29, 2014, 2:00 PM

Post #6 of 8 (1138 views)
Re: [FishMonger] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

hi fishmonger

many many thanks - i am not in front of the notebook
i wanted to do the tests tomorrow...

but i see - youre rigth.

years before i have had a solution that did the following

a. - results for a
b. - results for b
c. - results for c

i try to figure out what is needed to get this done

will come back and report all the findings

btw.- this is a great option to learn..
alsor regarding the db.. isn īt it!?


Laurent_R
Veteran / Moderator

Jun 29, 2014, 11:44 PM

Post #7 of 8 (726 views)
Re: [dilbert] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

I don't know the module you are using, but filtering the list you get from the invoked method is really easy. Or do you have difficulty with this?


dilbert
User

Jun 30, 2014, 12:13 AM

Post #8 of 8 (707 views)
Re: [Laurent_R] doint a request - and storing the results....a 16 liner [In reply to] Can't Post

Hello and bon jour . yes i habe some. I usw only the above menioned things.
Only parse cpan authors. Is thisx enough.
Love to hear from you.
Thanks in advance.

Greetings

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives