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

Hi everyone, I typed up a simple code and for some reason I can't get anything to print. Could someone please look at this for me and tell me what the problem is? $fnord = 23; $blee = "The magic number is $fnord."; print "$blee";

Replies are listed 'Best First'.
Re: Print Help in Perl
by moritz (Cardinal) on Sep 11, 2008 at 16:45 UTC
    On my terminal I sometimes don't see output unless it's followed by a newline.

    This works for me:

    $ perl -e '$fnord = 23; $blee = "The magic number is $fnord."; print " +$blee\n";' The magic number is 23.

      zshell 4 was|is horrible, unlike bash 3 that I was using earlier, in this regard when I was confounded myself seeing no output from a perfectly good program. I had to tweak some option or add some workaround in zshell.

      Few minutes later ... a Google search (zsh print program | script newline "no output" | nothing) produced setopt no_prompt_cr.

Re: Print Help in Perl
by kyle (Abbot) on Sep 11, 2008 at 16:46 UTC

    It works for me. I'd recommend you use strict and warnings and put a "\n" at the end of the string you print.

    use strict; use warnings; my $fnord = 23; my $blee = "The magic number is $fnord."; print "$blee\n"; __END__ The magic number is 23.

    With the "\n" on there, it will have a line break between its output and the prompt when you run it.

Re: Print Help in Perl
by FunkyMonk (Bishop) on Sep 11, 2008 at 16:46 UTC
    It works for me, but you could add a newline to your print and see if that makes a difference:
    print "$blee\n";

Re: Print Help in Perl
by CountZero (Bishop) on Sep 11, 2008 at 18:55 UTC
    Could it be that you are suffering from buffering?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James