Hey Guys,

I am a real beginner so at the risk of being slammed by some, I wanted to
get some input.

I was trying to do exercise 5 of the 5th edition of learning perl:

It is based on exercise 4, so I will paste both here:

4. [10] Write a subroutine, named greet, that welcomes the person you name
by

telling them the name of the last person it greeted:


greet( "Fred" );

greet( "Barney" );

This sequence of statements should print:

Hi Fred! You are the first one here!

Hi Barney! Fred is also here!

5. [10] Modify the previous program to tell each new person the names of all
of the

people it has previously greeted:

greet( "Fred" );

greet( "Barney" );

greet( "Wilma" );

greet( "Betty" );

This sequence of statements should print:

Hi Fred! You are the first one here!

Hi Barney! I've seen: Fred

Hi Wilma! I've seen: Fred Barney

Hi Betty! I've seen: Fred Barney Wilma



So I worked on it for a while and got something really close to what is in
the answers, but what you get as an output is grammatically incorrect, it is
missing the commas and such. I figured that in reality, eventually in the
real world, I would want the output to be correct or at least tab delimited.
So I went about trying to get commas in and I came up with this:


! /usr/bin/perl


use strict;

use 5.010;


sub greet {

    state @people;

    my $name = shift @_;

    print "Hi $name! ";

    if (@people){

my @peoplec = @people;

my $lastperson = shift @peoplec;

my $beforelast = shift @peoplec;

print "I've seen: ";

    foreach (@peoplec){

       print "$_, ";}

               print "$beforelast and ";

       print"$lastperson!\n";

                 }

                  else {

                print "You are the first here!\n";

                        }

             push @people, $name;

           }



&greet ("Fred");

&greet ("Barney");

&greet ("Wilma");

&greet ("Betty");

&greet ("Bamm-Bamm");


exit;

I am no perl expert, but this code looks really clunky to me, so I was just
looking for some input. If your input is your code sucks without any
constructive suggestion, please keep it for yourself, since I already know
that my code sucks! :P I am beginner, that's what newbies do, they suck (in
general, some people are brilliant and don't, not my case).

And since I got writing I thought I would chip in the discussion as a real
newbie, from a newcomer perspective. I am a scientist, brutal criticism is
part of my job (both giving it and receiving it), and I personally find it
never gets easier. I agree with many people that if you want to be great,
there is no other way, you have to, as Randall said, get a thick skin.
However, some people are not learning perl to be great, they just want to be
OK. I am one of those. I have been using rudimentary Bio perl scripts to
deal with Genomic data for a while, but never really learned the language,
so I decided to go back to the beginning and learn it from there, from the
ground. I have to say this list is a bit daunting  and does not look like a
beginners list at all. I think it, as Cat Stevens would say, a wild world
out there, but some of us are just trying to get by.

That's my view from outside, really outside.

Cheers,

Tiago


-- 
"Education is not to be used to promote obscurantism." - Theodonius
Dobzhansky.

"Gracias a la vida que me ha dado tanto
Me ha dado el sonido y el abecedario
Con él, las palabras que pienso y declaro
Madre, amigo, hermano
Y luz alumbrando la ruta del alma del que estoy amando

Gracias a la vida que me ha dado tanto
Me ha dado la marcha de mis pies cansados
Con ellos anduve ciudades y charcos
Playas y desiertos, montañas y llanos
Y la casa tuya, tu calle y tu patio"

Violeta Parra - Gracias a la Vida

Tiago S. F. Hori
PhD Candidate - Ocean Science Center-Memorial University of Newfoundland

Reply via email to