Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

print statement does not work

by Hammy (Scribe)
on Dec 17, 2002 at 00:30 UTC ( [id://220410]=perlquestion: print w/replies, xml ) Need Help??

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

I have installed perl (myself) and loaded a number of libraries (lwp, cgi, dbd - got lots of errors with that install). When I write a simple 2 or three line program, the print statement does not do anything. It does not error out, but it does not do anything. Echo works just fine. Any idea where I can look. The program sits in the cgi-bin directory and has the header #!/bin/sh if that helps. Its a Sparc/Solaris box also. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: print statement does not work
by graff (Chancellor) on Dec 17, 2002 at 00:49 UTC
    Well, if it's a file containing a perl script, on a solaris box, then the first line of the file should read:
    #!/usr/bin/perl
    or whatever the path is to the perl interpreter (binary executable) file that you have installed.

    If the installation went well enough for the perl interpreter to run, then the following shell command ought to work, printing the config/environment info for your installation:

    perl -V
    and so should the next command line, printing "hello, world" on your screen, assuming that your newly installed perl can be found in the PATH variable of your current environment setup.:
    perl -e 'print "hello world\n"'
    (note the use of both single and double quotes)

    What seems odd is that you have to install perl yourself on a solaris box -- I would have thought that perl would be there already. Anyway, if you've done your own perl install for whatever reason, you have to know the path to your "perl" executable, and you have to make sure you cite that path on the shebang line of every script you write.

      Thank you, your help is appreciated. The command line perl statement works well (as did the perl -v). When putting the /usr/local/bin/perl in the first line, I get an internal error as if it does not know where it is. Is there a way to check where it thinks perl exists.
        Folks here might be able to help if you:
        • Post the code you're trying to run
        • Post the error message or other odd result you're getting

        The information you've provided so far is too vague.

        By the way, what do you get in response to either of these two commands:

        type perl which perl
        Those should print the path where your shell finds the perl executable, given your current PATH setting. That is what should be on the shebang line of any perl script you write. (Note: this could report the path to a version of perl that you did not install yourself. You do know the path to the version you installed, right? Did you actually place your installation in /usr/local/bin?)
Re: print statement does not work
by pg (Canon) on Dec 17, 2002 at 02:26 UTC
    If you print without "\n", the msg is not neccessary to show up on screen at the time you expected. It will show up when one of those happened:
    1. The output buffer is full
    2. a later print statement contains \n
    3. the program finished
    If you don't want to wait:
    1. end your msg with "\n"
    2. at the beginning of your code: $| ++
Re: print statement does not work
by waswas-fng (Curate) on Dec 17, 2002 at 00:51 UTC
    1, I have installed perl (myself) and loaded a number of libraries (lwp, cgi, dbd - got lots of errors with that install).
    Errors with that install? Did you fix them or just ignore them?

    2, has the header #!/bin/sh if that helps
    The shabang on the script should point to your perl bin whereever you installed it to, usually it is in /usr/bin/perl or /usr/local/bin/perl but not always.

    -Waswas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://220410]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-23 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found