Quote:
Originally Posted by sayhello_to_the_world
(Post 5195785)
hello dear linux-experts
just new to perl - i want to run this little 16 liner and do some things with it.
|
No, sorry...you've been posting perl questions for over a year now. You're not 'new' to it.
Quote:
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 -
|
Again, as with other threads you've posted about programming/scripting,
if it works, it's the 'correct way'. But in this case, no, it isn't because you (again), didn't read the documentation or show effort of your own, as you've been asked to MANY times, and keep saying you will. If you did read the CPAN documentation, you'd see that the "author" function does what it implies...it returns ONE AUTHOR. If you want to return several, the "author
S" tag does that...which is clearly documented.
Quote:
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;
|
Sorry, that is NOT the 'full script'...it is a PART of a script that you (again), directly lifted from another website...in this case, CPAN. The full script is on this page:
https://metacpan.org/source/LBROCARD...les/authors.pl
...with the snippet that you posted here:
https://metacpan.org/pod/Parse::CPAN::Authors
Quote:
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});
|
The first is only a code snippet, and won't run at all, the way you posted it. The second is returning some data, but you don't actually bother POSTING what it returned. How do you think we can help with anything, when you don't post the relevant details???? Based on what you posted, it would seem to return ALL the authors, since that's exactly what you're asking it to do. If so, then put a conditional check in to look at the first character of the name returned, and if it matches, do something with it.
Quote:
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
|
You examine the output, and act accordingly, just like you would for any other variable.
Quote:
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?
|
However you want...since you've asked many MySQL questions before, as well as several about both Perl and PHP interacting with MySQL, you have THREE methods. Pick one.
Quote:
how to connect to the database from our script?
how to write the insert statement?
|
Go and look at any of your other threads where you asked about this, or any of the many, MANY thousands of examples you can find on Google.
Quote:
well and now i am just reading over the DBI manual
|
You should have already done that, since you said you were going to several times in the past, and you were even going to come back and post your solution:
http://www.linuxquestions.org/questi...db-4175506044/
http://www.linuxquestions.org/questi...db-4175502185/
...which still hasn't happened.
AGAIN...you need to start showing some actual effort of your own, and show that you're learning something. Asking almost identical questions over and over (like how to connect to MySQL, create a database, etc), is pointless. If you can't apply anything that you've learned, then please just hire someone to do this work for you.