Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Should I go back to basics of keep moving on?

by Anonymous Monk
on Jan 14, 2018 at 21:28 UTC ( [id://1207233]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Should I go back to basics of keep moving on?
by Laurent_R (Canon) on Jan 14, 2018 at 21:49 UTC
    I think you can definitely go for Modern Perl. While this is not in my opinion a book for pure beginners, or let me rather say that you will better benefit from it if you have some basic knowledge of Perl (BTW, the name of the language is Perl, nor pearl), but a basic knowledge of Perl will be sufficient to start with it (and you definitely have the basic knowledge that I mean), and it will help consolidate your knowledge.

    Intermediate Perl has a somewhat higher prerequisite. In my view, it would make sense to go for Intermediate Perl after you've gone through Modern Perl.

Re: Should I go back to basics of keep moving on?
by BillKSmith (Monsignor) on Jan 14, 2018 at 23:50 UTC
    I completely agree with Laurent. "Intermediate Perl" is much more advanced than the title suggests. I have also found that it does not meet the quality standards of the other O'Riley Perl books (code that does not work exactly as described). Despite this, you should read it eventually, but not yet.
    Bill

      Hi BillKSmith

      Thanks for the advice. This really helps clear the confusion. Perlmonks is as awesome as Perl. :)

Re: Should I go back to basics of keep moving on?
by chromatic (Archbishop) on Jan 15, 2018 at 21:58 UTC

    My intended audience for Modern Perl is someone with about six months of practical programming experience. Some people pick up the basics faster, but I didn't want to spend a lot of time explaining how to use a text editor or IDE, install a programming language, or run code. I covered a lot of basics of the language to explain its design principles, but it's not really a beginner book in the same way as Learning Perl.

    From your code, you seem like you'd be fine with Modern Perl.

      Thank you Sir. Point taken. You are a great author and I am thankful you wrote this book.

Re: Should I go back to basics of keep moving on?
by Your Mother (Archbishop) on Jan 15, 2018 at 22:39 UTC
Re: Should I go back to basics of keep moving on?
by Anonymous Monk on Jan 14, 2018 at 22:10 UTC

    Laurent_R, I sincerely apologize for the typo. I never meant to refer to it as pearl. That alone would warrant a "go back to the basics", but thanks for gently pointing it out.

    Thanks for your input and suggestion.

      I sincerely apologize for the typo. I never meant to refer to it as pearl. That alone would warrant a "go back to the basics"
      Not to worry. It's just a typo, I mentioned it for the record, but don't particularly care.

      The code you've shown is essentially sound. In fact, being able to understand and use map and grep is often considered as entering intermediate level in Perl. I would still maintain my recommendation that you start with chromatic's Modern Perl to consolidate your current knowledge before going to Intermediate Perl. But the code you've shown tells me that you definitely don't need to start allover again from the beginning. Go forward.

        Thank you very much for the clarity. I will proceed to download the Modern Perl and go through it.

Re: Should I go back to basics of keep moving on?
by pwagyi (Monk) on Jan 16, 2018 at 05:44 UTC

    So are you already expert on Perl data structures? scalar, array, hash, reference, nested data structures (AOA, AOH, ..)? functions that manipulate string, number, array, hash? Looping? Regular expression? writing your own subroutine (following good coding convention) File IO? perldoc covers quite a lot of what I have mentioned above.

      Nope, not at all. I never claimed to be an expert in the first place, I just came here to get some clarity. Thanks a lot for pointing to perl docs but, are you saying I need to know these things before I touch Modern Perl?

      Update:- Just saw a reply from Chromatic. If he feels I am good enough to start with his book, I will

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1207233]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-18 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found