Hi Monks,

Happy new year to you all.

I had tried my hand at pearl a few months ago. I was using "Learning Perl" and had managed to write some scripts that helped me automate part of my work at office. Then I had to focus on other things at work, so I forgot all about Perl. This year, on a whim, I decided to get back to it.Here is what I have tried as of now. Not that this is difficult, but still, to truly test myself, I did not search anything on google, just started typing the script, kept modifying it and kept plodding on.

Ex1: Vaguely recalling, "Learning Perl" had an exercise where I had to add elements to a list through a sub routine, and print them out. I modified the exercise so that the script would greet a number and add it to other numbers in the list. If this is the first number, it should be greeted stating something like "Hi, you are the first number". For the other numbers, it should show how many numbers we have in the list, then count them up, and show the sum. Initially I started with just adding the numbers in a list, and it took me some time to recollect how to do it. The other things mentioned above were gradually added, just to test my knowledge retention.

user@linux-mint ~/perl_practice $ more greet_add_sub.pl use strict; use warnings; sub greet_add { my $sum = 0; my @seen; foreach my $num (@_) { $sum += $num; print "Hi $num, you are the first one!!\n" if !@seen; print "Hi $num, Please join (@seen). " if @seen; push @seen, $num; print "You ", scalar @seen , " fine folks add up to: $sum\n" i +f scalar @seen > 1; } print "Total is: $sum\n"; } my @list = (1..10); greet_add(@list); user@linux-mint ~/perl_practice $ perl greet_add_sub.pl Hi 1, you are the first one!! Hi 2, Please join (1). You 2 fine folks add up to: 3 Hi 3, Please join (1 2). You 3 fine folks add up to: 6 Hi 4, Please join (1 2 3). You 4 fine folks add up to: 10 Hi 5, Please join (1 2 3 4). You 5 fine folks add up to: 15 Hi 6, Please join (1 2 3 4 5). You 6 fine folks add up to: 21 Hi 7, Please join (1 2 3 4 5 6). You 7 fine folks add up to: 28 Hi 8, Please join (1 2 3 4 5 6 7). You 8 fine folks add up to: 36 Hi 9, Please join (1 2 3 4 5 6 7 8). You 9 fine folks add up to: 45 Hi 10, Please join (1 2 3 4 5 6 7 8 9). You 10 fine folks add up to: 5 +5 Total is: 55 user@linux-mint ~/perl_practice $

I also tried to recall some basic map and grep stuff:

user@linux-mint ~/perl_practice $ more num_triple_by2.pl use strict; use warnings; my @tripled = map { $_ * 3 } my @list = (1..10); print "\@list = @list\n\@tripled = @tripled\n"; my @div_by_two= grep { $_ % 2 == 0 } @tripled; print "\@div_by_two = @div_by_two\n"; user@linux-mint ~/perl_practice $ perl num_triple_by2.pl @list = 1 2 3 4 5 6 7 8 9 10 @tripled = 3 6 9 12 15 18 21 24 27 30 @div_by_two = 6 12 18 24 30 user@linux-mint ~/perl_practice $

I am not sure if at this point, I am good enough to start with some intermediate perl. I was planning to start right off with the books - "Intermediate Perl" and "Modern Perl". But with what I know, should I study the basics more and then move ahead? Sort of confused here folks, would appreciate your feedback


In reply to Should I go back to basics of keep moving on? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.