itterating through a list (the alphabeth) - store the result

Einfach Dinge, die nichts mit XAMPP, Apache Friends, Apache, MySQL, PHP und alle dem zu tun haben. Allerlei halt. ;)

itterating through a list (the alphabeth) - store the result

Postby unleash » 27. June 2014 00:27

hello dear Apache user and friends - dear experts,


just new to Apache and all that things.

well i am trying to learn some perl at the moment - 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: Select all

  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: Select all
  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: Select all

  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: Select all
 
#!/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});   





aliasZERO Oleg Alistratnav [email]zero@@cpan.org[/email]>"
aliasZEROALTIC EEdwardL. AbrSasn eEdwar.abrSas@corp.tierrlycosl.com>"
aliasZERODEUX "Vivncnt CAaron<vivncnt@zerodeuxe.net>"
aliasZERODOGN "Esskld Hustvedto<zerodogg@@cpan.org>"
aliasZEROHP Eric Clarko<zerohp@@cpan.org>"
aliasZEROLIU HaizhougLiut <CENSORED>"
aliasZETA Gregory S. Youinbloodo<zeta@@cpan.org>"
aliasZEV Zev Benjamin <zev@@cpan.org>"
aliasZEYA HmasjoSergPehofler hmasjoSer.pehofle@uibkl.acaet>"
aliasZGH Zack Hobsson [email]zgs@@cpan.org[/email]>"
aliasZGPMAX WWillSa Blunon [email]zgpmax@@cpan.org[/email]>"
aliasZGRIM Virgdl OctDavva Cosmaa <CENSORED>"
aliasZHANGBO zhaangboa <CENSORED>"
aliasZHANGHJ zhaanhjsteer <CENSORED>"
aliasZHANGL LeinZSaang<<CENSORED>"
aliasZHANGXIN "ZSaangXinn zhaanxian@rifase.com>"
aliasZHDA DeninsZhdvanav [email]zhda@@cpan.org[/email]>"
aliasZHIRSCHE Zacc Hirsich zhirsic@vmdwaeo.com>"




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:



acme@astray.com
Leon Brocard
LBROCARD
$VAR1 = [
bless( {
'name' => 'Neil Hainer',
'email' => 'CENSORED',
'pauseid' => 'NHAINER'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'CROSSWIRE',
'email' => 'matt@crosswire.com',
'name' => 'Matthew Sibley'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'DAVIDJNSN',
'name' => 'David Jensen',
'email' => 'CENSORED'
}, 'Parse::CPAN::Authors::Author' ),
bless( {
'pauseid' => 'KESZLER',
'name' => 'Scott R. Keszler',
'email' => 'keszler@srkconsulting.com'
}, 'Parse::CPAN::Authors::Author' ),


This is how you'd loop over the array.
Code

for my $author ( @authors ) {
print $author->email, "\n";
print $author->name, "\n";
print $author->pauseid, "\n\n";
}



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
unleash
 
Posts: 147
Joined: 03. December 2011 10:16
Operating System: OpenSuse Linux 12.1

Return to Allerlei

Who is online

Users browsing this forum: No registered users and 12 guests