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

Hello,

I started learning Perl a few hours ago after I was inspired by one of my friends. Right now > I'm trying to get into the basics because this is actually my first coding language too. I have 7 or so hours per day for the next few months to dedicate to this and I'm really serious.

Can anyone give me some code which would be good to mess' around with?

Cheers.

Replies are listed 'Best First'.
Re: Most basic code to mess around with?
by GrandFather (Saint) on Nov 08, 2014 at 21:29 UTC

    Try digging through old nodes posted here. There will be huge piles of stuff that are miles away from where you are at present, but there are a lot of fairly entry level questions too. Even where it's not clear what the question is, you will find lots of useful stuff in replies.

    Have a look through the Tutorials section.

    And as a reality check run the following:

    #!/usr/bin/perl use strict; use warnings; for my $count (1..5) { print "Hello world $count.\n"; }

    The importance of a very simple hello world program is to make sure you have everything installed and running correctly. I've dressed this up slightly to make it more interesting and give a little head start into doing something real.

    If you can afford to buy books then Learning Perl is the traditional highly recommended choice.

    Ovid's Begining Perl is also likely to be of interest and is freely available. I've not read it, but I've heard good reports of it.

    Perl is the programming world's equivalent of English
Re: Most basic code to mess around with?
by wjw (Priest) on Nov 08, 2014 at 22:25 UTC

    Welcome to Perl!

    I like the approach you are taking to learning the language, and to learning programming in general. Grandfather and Botfx both pointed out some good ideas. I would add the following:

    • select a simple task that you might do on a regular basis(ex. clean out the Download directory of anything older than x number of days, or maybe search for and relocate all .jpg files in a path to another path. Am sure you can come up with something better...)
    • Use perldoc to accomplish the task without any additional modules(CPAN). A task like this is well within the reach of core Perl
    • If you get confused, you can always ask questions here, though it is good to be able to show what you have tried. (See How to I Post a Question Effectively)
    • Once you have accomplished whatever task it is you set out to do, you will probably have been exposed to most of the basics that the rest of procedural Perl is built on.
    • Subsequently, look at CPAN and learn how to use it.
    • Redo that same project using modules from CPAN. Which will expose you to extended functionality as well as other folks methods of programming in Perl

    This is what worked for me years ago, and actually still does when I decide to take on a project that requires exposure to new things that I have not yet tried(there is a lot of that). Most of what I have done with Perl fits into just a few basic categories:

    • repetitive administrative tasks(moving things about)
    • manipulating file content(read it in, spit it back out differently, or to a new format)
    • reading/writing to storage(databases)
    • dynamically generating data/info to deliver to web apps
    There have been many other uses, but doing those forced me to learn a plethora of other related skills, like good development methodology(at least one that works for me), version control, database basics(flavors of SQL in my case), etc...

    Hope that might be helpful... and also that you find enjoyment in discovering Perl. In my opinion, you made a great choice for a first programming language.

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is simply an inconvenient fact

Re: Most basic code to mess around with?
by boftx (Deacon) on Nov 08, 2014 at 21:51 UTC

    You will quickly find out about CPAN and various commonly used modules there. I would strongly urge you to view the source for some of the (apparent) simpler ones.

    You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
Re: Most basic code to mess around with?
by karlgoethebier (Abbot) on Nov 09, 2014 at 12:50 UTC
Re: Most basic code to mess around with?
by Anonymous Monk on Nov 09, 2014 at 01:10 UTC
Re: Most basic code to mess around with?
by pritesh (Scribe) on Nov 09, 2014 at 17:28 UTC

    Hi,

    Perl is my first language too.

    Lot of great folks here have suggested good points, so nothing much to add however, you might find the following points useful.

    The best code to mess with is the one you write yourself. Because you have written it, you know it, you can tweak it and see what happens.

    I wrote something like this after dabbling with Perl initially:

    #!/usr/bin/perl use warnings; use strict; print "Enter your name: "; chomp(my $name = <STDIN>); print "Your name is: $name\n";

    And then I supplied my name. And it printed fine. Then I supplied it a number. And it still printed fine. The same thing failed when I tried in C, but Why? Because C makes you create a variable of type char or int or float. But not so with Perl. And off I went (re) reading about how Perl treats variables, how 4x4 is different from 4*4. Write your own code and mess with it. Once you are sure that it's running fine, purposely remove a colon, or a comma or something like that and see what error you get. That's the best way to learn when picking up Perl.

    Try Strawberry Perl if you are on Windows. Its at - http://www.strawberryperl.com. It's easier to install modules in Strawberry Perl and there's a portable version available. So that you can extract it to a folder, do your stuff and copy the folder to a USB and try it out on any other Windows based computer. No need to install Perl :)

    As mentioned by other folks here, Learning Perl is a great book and so is Beginning Perl (By Curtis Ovid Poe). You can get any (or both) and get started.

    Most important: Don't do the mistake I did. I skipped the exercises in hope of saving time and learning quickly. It simply didn't work. I had to go back and do the exercises. It does make a difference.