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

Hello, I am starting to learn perl. when i go to run and type perl it opens but when i type the basic program $a=2; $b=$a + $a; print $b ; and then press enter i dont get any output.i thought i would get 4 as output. i want to know what i am doing wrong.need some help just to start. i tried going to perl critic but it gives error message on the first line.error message is 'code before strictures are enabled' some one please help.

Replies are listed 'Best First'.
Re: starters querry
by GotToBTru (Prior) on Mar 30, 2015 at 18:03 UTC

    See this tutorial for a step-by-step example of getting your program to run. Perl is not interactive in that way. You need to save your program in a file and then use the Perl compiler to run it. Or you can run a short program in the command line in this fashion:

    perl -e "$a=2; $b = $a + $a; print $b,'\n'"
    Dum Spiro Spero
Re: starters querry
by toolic (Bishop) on Mar 30, 2015 at 18:02 UTC
Re: starters querry
by jeffa (Bishop) on Mar 30, 2015 at 18:17 UTC

    Just to comment on your immediate needs -- after you type (or paste) in your sample program, enter Control-d and then press enter. By pressing Control-d, you are essentially letting the shell know you have entered all the data you wish for the perl interpreter, allowing the interpreter to now run your code.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: starters querry
by karlgoethebier (Abbot) on Mar 30, 2015 at 20:07 UTC

    I guess you want it interactive. If so, please try something like this:

    karls-mac-mini:~ karl$ perl -d -E 1 Loading DB routines from perl5db.pl version 1.44 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(-e:1): 1 DB<1> $a=2; DB<2> $b=$a + $a; DB<3> say $b; 4

    Please see perldebug and perlrun for more details.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»