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

Hello everybody, I am a total beginner in Perl and I am facing some problems. I have a book which covers up to Perl 5.8 but I installed Ubuntu 14.04 which have Perl 5.18.2. I am facing some problems in my programs. My book has some examples of code which I am writing them again in a text editor in order to practice more. The thing is that even these programs (which are exactly copy-paste from the book) cannot be executed and I have many fault messages in my terminal. Could be responsible my Perl version? Are there so many differences between Perl 5.8 (text book) and 5.18.2 (my Ubuntu Perl version)? Thank you in advance for your answer and your time. Regards, A desperate beginner.
  • Comment on Differences between Perl 5.8 and Perl 5.18.2

Replies are listed 'Best First'.
Re: Differences between Perl 5.8 and Perl 5.18.2
by toolic (Bishop) on Apr 19, 2015 at 16:41 UTC
    While there have been many changes since 5.8, many code examples from 5.8 should still run without modification on 5.18. I recommend posting a short example of your problematic code along with the exact error messages.

    BTW, the changes are detailed in the many perldelta docs in http://perldoc.perl.org/index-history.html. As a beginner, this will probably not be of much help yet.

Re: Differences between Perl 5.8 and Perl 5.18.2
by Laurent_R (Canon) on Apr 19, 2015 at 16:53 UTC
    Almost any program that runs under Perl 5.8 will still run on Perl 5.18, especially programs in a book for beginners (the opposite would not be true). There must be something that you are not doing right when typing or copying and pasting the source code. Please provide a verbatim example of a program that does not run on your computer.

    One possible explanation is that the "shebang line" (something like #!/usr/bin/perl at the top of the program does not correspond to the place where Perl is installed on your computer. Try to type which perl at the shell prompt to check where Perl is installed.

    Je suis Charlie.
      Thank you for your prompt reply. The program is this one:
      #!/usr/bin/perl -w $im_thinking_of=int(rand10); print "Pick a number:"; $guess=<STDIN>; chomp $guess; if ($guess>$im_thinking_of) { print "You guessed too high!\n"; } elsif ($guess < $im_thinking_of) { print "You guessed too low!\n"; } else { print "You got it right!\n"; }
      I have the following errors:
      Argument "rand10" isn't numeric in int at guess line 3
      Furthermore, it always gives me the answer
      You guessed too high!
      It is like it never reads elsif or else. This is only one example. I have other programs that have mistakes as well and it is not even my code. When I say that I copy and paste them, I mean that I read them from the book and write them again identically in my text editor.
        You transcribed at least one line incorrectly. Change:
        $im_thinking_of=int(rand10);

        to (space between rand and 10):

        $im_thinking_of=int(rand 10);

Re: Differences between Perl 5.8 and Perl 5.18.2
by 2teez (Vicar) on Apr 19, 2015 at 17:13 UTC

    Hi mbgbioinfo

    ..The thing is that even these programs (which are exactly copy-paste from the book) cannot be executed and I have many fault messages in my terminal..

    If I may add to what has been said in line with the quote above from your question. I will suggest you type out the code yourself instead of copy AND paste.
    In my experience, when you copy from say pdf file, your text editor might not recognize the quotes and a number of letters properly. Some text editor will even tell you that, your code cannot be saved because you have "unicode" string in your file.
    So, type out the codes you want to try and run it.

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me