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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The thing is, you can write Perl in a very C-like manner. (Some people like to play the sport where you write programs which will compile as both valid C and valid Perl!) Writing Perl that way will probably not take you long to pick up...

# Function to add a list of numbers together sub sum { my @numbers = @_; my $sum = 0; for (my $i = 0; $i <= $#numbers; $i++) { $sum += $numbers[$i]; } return $sum; }

But on the other hand, this function might look more foreign to you, but if you had experience writing Haskell or Miranda would seem perfectly obvious:

use List::Util 'reduce'; sub sum { my @numbers = @_; return reduce { $a + $b } @numbers; }

A seasoned Perl programmer will probably have discovered that the following knocks the socks off both of the above performance-wise...

sub sum { my $sum; $sum += $_ for @_; return $sum; }

But once you'd gained familiarity with the core libraries and with CPAN, you'd realise that List::Util (from which we borrowed the reduce keyword earlier) has a sum function available, and it runs about 40 times faster that the first example given above. :-) So you'd just borrow that...

use List::Util 'sum';

So in answer to your question, it might take you a couple of days to start writing C-like code in Perl, but as with any mature programming language, familiarity with the important libraries, and a feel for writing elegant and efficient code take many years to develop.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Whats the average time taken to learn Perl? by tobyink
in thread Whats the average time taken to learn Perl? by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (2)
    As of 2018-05-26 16:15 GMT
    Find Nodes?
      Voting Booth?