Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Good Perl book?

by Anonymous Monk
on Feb 10, 2017 at 14:44 UTC ( #1181670=perlquestion: print w/replies, xml ) Need Help??

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

Hi all,

I had written some scripts in Perl about 4-5 years ago. I had used Perl 5.14. It was my first programming language and I totally loved the experience. I tried to use Perl Modules wherever I could in order to avoid simply wrapping commands inside the Perl scripts. The SSH and Email Modules were my favourite because I could accomplish a lot by using them to login to the various servers and devices, collect the outputs, dump them into a text file, use regular expressions (I love Perl's Regex), filter the required parts and mail them to the team so that appropriate actions could be taken.

I am planning to get back to Perl. I am not a programmer by profession. Just a regular IT Guy. Should I start from scratch or some intermediate level book? I hope this doesn't sound like me asking here "What should I eat? Chicken or fish?" :)

If my question appears relevant, kindly guide me.

Replies are listed 'Best First'.
Re: Good Perl book?
by neilwatson (Priest) on Feb 10, 2017 at 14:54 UTC
Re: Good Perl book?
by Athanasius (Bishop) on Feb 10, 2017 at 15:35 UTC

      Regarding perldocs, they are like impossible for newbs to understand and even intermediate users like me tend to avoid them and do a google search instead. It's a bad habit to get into, though, as perldocs make it really easy to look things up fast if you get familiar with them. This is something I try to work on.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: Good Perl book?
by haukex (Bishop) on Feb 10, 2017 at 15:35 UTC
Re: Good Perl book?
by nysus (Vicar) on Feb 10, 2017 at 15:23 UTC

    Oh, and as far as books go, get the Camel book. It's a little hard to slog through but it is authoritative and no nonsense. It's an essential reference.

    As I recall, Learning Perl is also very good and easier to digest.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Re: Good Perl book?
by nysus (Vicar) on Feb 10, 2017 at 15:01 UTC

    I can't tell you what works for you but I can tell you my experience as you sound kind of like me who uses Perl for the fun of it. I look at it as a kind of fun puzzle to figure out and I get great joy writing programs as bad as they often are. I've programmed in short spurts over many years when the Perl bug strikes.

    Anyway, my advice is to start from scratch, at least until you get reacclimated. Perl has a lot of little gotchas and essential idioms you should know and you aren't likely to remember them. I've "relearned" Perl several times. Each time it gets easier. But I always found I got a deeper and deeper understanding of the language.

    I also highly recommend checking out Moose, a framework that makes it exceedingly easy to write OO code in Perl. It has made my experience with Perl very pleasurable and fun. I really enjoy programming with it. I only started using it last year thanks to PerlMonks who tipped me off about it. Wish I knew about it long ago.

    Good luck and happy programming.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Re: Good Perl book?
by Anonymous Monk on Feb 10, 2017 at 14:58 UTC

    Hi Neil,

    Thanks for the pointers. I hope Modern Perl doesn't turn out to be super advanced for my level :)

      IMHO, Modern Perl is not the best for a pure beginner, but it is really excellent if you know already some of the basics of the language. So it seems to be a good pick for you.

      Otherwise, the Camel book is obviously a must it you want to go further.

Re: Good Perl book?
by Anonymous Monk on Feb 10, 2017 at 15:56 UTC

    Hi all

    Thank you for your responses. I just tried the following. Took me a few searches, I also happened to get the brackets wrong for the array....used [ instead of (... and then went "heck, [ is for anonymous arrays..." hahaha. The map and grep took google searches to get it flowing back.

    C:\>more first.pl #use warnings; #use strict; my @arr = (1..10); foreach my $num (@arr) { print "Index is: $num. Value is: $arr[$num] "; } #Another way print "\nWith a C like for loop\n"; for($num = 0; $num<= $#arr;$num++) { print "Index is: $num. Value is: $arr[$num] "; } my @divbytwo = map { $_ / 2} @arr; print "\n\@divbytwo = @divbytwo\n"; my @divbytwoo = grep { $_ % 2 == 0} @arr; print "\@divbytwoo = @divbytwoo\n"; C:\>perl first.pl Index is: 1. Value is: 2 Index is: 2. Value is: 3 Index is: 3. Value i +s: 4 Index is: 4. Value is: 5 Index is: 5. Value is: 6 Index is: 6. V +alue is: 7 Index is: 7. Value i s: 8 Index is: 8. Value is: 9 Index is: 9. Value is: 10 Index is: 10. +Value is: With a C like for loop Index is: 0. Value is: 1 Index is: 1. Value is: 2 Index is: 2. Value i +s: 3 Index is: 3. Value is: 4 Index is: 4. Value is: 5 Index is: 5. V +alue is: 6 Index is: 6. Value i s: 7 Index is: 7. Value is: 8 Index is: 8. Value is: 9 Index is: 9. Va +lue is: 10 @divbytwo = 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 @divbytwoo = 2 4 6 8 10

    I think I better start from scratch :)

      This is actually pretty close to what you wanted. Un-comment use warnings and the resulting message will help to identify the problem:

      Use of uninitialized value in concatenation (.) or string at first.pl +line 5.

      The problem loop is:

      foreach my $num (@arr) { print "Index is: $num. Value is: $arr[$num] "; }

      and as the output shows, the loop value is always one greater than the index. That’s because arrays in Perl (as in C) are subscripted starting from zero, so $arr[1] is actually the second element. The loop is easily fixed:

      foreach my $num (@arr) { print "Index is: $num. Value is: $arr[$num - 1] "; # Subtra +ct 1 from the index }

      Also un-comment use strict, and you’ll see that the only error message pertains to this line:

      for($num = 0; $num<= $#arr;$num++) {

      Declare $num as a lexical variable:

      for (my $num = 0; ...

      and strict is happy.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Thank you for your patience and guidance. It was stupid of me to comment it out. Perl and perlmonks are awesome. Respect.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2020-10-25 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?