Results 1 to 5 of 5

Thread: Made little Perl program, but terminal won't find it?

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Beans
    2

    Made little Perl program, but terminal won't find it?

    So I'm just starting out with perl (literally just got the book for learning it yesterday) and one of the exercises, was making this program in text editor in ubuntu:
    #!/usr/bin/perl
    print "Hello, world!\n";

    then I went and saved it and it said I have to identify it as an executionable file or something like that. Here is the full paragraph:

    You may also need to do something so that your system knows it’s an executable program (that is, a command). What you’ll do depends upon your system; maybe you
    won’t have to do anything more than save the program in a certain place. (Your current
    directory will generally be fine.) On Unix systems, you mark a program as being executable using the chmod command, perhaps like this:
    $ chmod a+x my_program



    I entered that phrase: chmod a+x my_program
    ((the file was called my program, I named it that))

    and terminal gave me this: chmod: cannot access 'my_program' : no such file or directory

    and I tried renaming the program with a space and with the underscore, and placing it in different places like my documents, but it just keeps saying no such file or directory. Please help!!!!

  2. #2
    Join Date
    Jan 2010
    Location
    Hyperborea
    Beans
    1,440
    Distro
    Ubuntu

    Re: Made little Perl program, but terminal won't find it?

    Try this
    Code:
    ./my_program
    The ./ (dot and forward slash) means that the script you are trying to run is in the current directory. Otherwise I think you would have to give the whole path to it.
    Code:
    /home/joe-bloggs/my_program

  3. #3
    Join Date
    Jul 2012
    Location
    Elmira, NY
    Beans
    153
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Made little Perl program, but terminal won't find it?

    by default the terminal is in directory /home/<username> . It appears that your file you created is not in that directory. If you put the file in ~/Documents, then the command would be
    Code:
    $ chmod a+x ~/Documents/my_program
    which is giving the full path to the file

    Or
    Code:
    cd Docuements
    Code:
    chmod a+x my_program
    I entered that phrase: chmod a+x my_program
    That is not a "phrase" it is a command.
    where:
    [CMD] [MODE] [PATH TO FILE]
    where path to file could simply be the filename, "if" you are in the directory that the file resides, otherwise the full path must be used to the file

    If your file has an ext, that also will need to be added to the command as well
    Last edited by micahpage; January 24th, 2013 at 02:47 PM.
    Ubuntu 13.04, x86_64, 3.8.0-19-generic, gnome3 desktop, multi-boot
    Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz, 8GB RAM, dual monitors, AMD Radeon HD 6770
    Python 3.2.3 and 2.7.3, tkinter 8.5, pyqt 4.8.1, pygame 1.9.2 pre
    https://github.com/metulburr

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,273
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Made little Perl program, but terminal won't find it?

    if the program is in the directory not listed in $PATH (echo $PATH to see the list), you have to give path explicitly, eg ./program or ~/program or /home/me/some_dir/program or whatever.
    in case of hand-made tools you can create bin directory inside your home. In ubuntu the terminal is configured by default to check for existence of that directory and adds it to the $PATH variable.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  5. #5
    Join Date
    Jan 2013
    Beans
    2

    Re: Made little Perl program, but terminal won't find it?

    Alright, thanks a lot everyone! That REALLY helped me!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •