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

Hello dear monks, thank you for helping me with my previous question regarding my first assignment which I was given by the book I'm learning from. In the second assignment, I've been given an exercise which asks the practitioner to compare two files. Firstly, it asks me to type the code print "Hi Mom.\nThis is my second program.\n" I open up my text editor in ubuntu, and type up this code:
#!/usr/bin/perl use warnings; print "Hi Mom.\nThis is my second program.\n";
and I save it as "newline.pl" Unfortunately, when I open up the terminal in Ubuntu, it doesn't work. I typed in perl begperl/newline.pl I specified begperl as the folder because that's where it is located. However, I get this message back: "Can't open perl script "begperl/newline.pl": No such file or directory" I then tried writing the code as print "Hi mom. This is my second program." and saved it as newline.pl and still I got the same message returned to me as: "Can't open perl script "begperl/newline.pl": No such file or directory" That's funny to me because when I created helloworld.pl that is the same folder where I saved it in, and it worked just like it was supposed to. I'm not sure as to why it's not working now. When I type in perl begperl/helloworld.pl it still works fine, I get the message, Hello World! What am I doing wrong? Thank you for your suggestions in advance - it's highly appreciated :)

Replies are listed 'Best First'.
Re: perl can't find my script on ubuntu
by Khariton (Sexton) on Dec 14, 2010 at 21:10 UTC
    May be You newbee in linux too.
    You go to terminal. You run script from which folder? Where begpirl folder? May be in folder where you are not persent begpirl folder?
    be carefully when run script.
    For first time, may be you can use direct path to script?
    as example: perl /home/user/begperl/newline.pl
    Sorry for my poor English...
      Yes, I'm new to Ubuntu - sorry I should've mentioned that. I'm running the script from my home folder. Thats why when I ran the helloworld.pl file I had to specify the folder as perl begperl/helloworld.pl I'm just not sure why the same method isn't working with the new file newline.pl It's saved in the same folder.
Re: perl can't find my script on ubuntu
by JavaFan (Canon) on Dec 14, 2010 at 22:39 UTC
    What do you get when you do the following commands:
    $ ls -l begperl $ ls -l begperl/newline.pl
      When I input the command $ ls -l begperl I get this message
      -rw-r--r-- 1 samurai samurai 62 2010-12-07 19:37 helloworld.pl -rw-r--r-- 1 samurai samurai 94 2010-12-14 13:51 newline.pl
      and when I input ls -l begperl/newline.pl I receive the message ls: cannot access begperl/newline.pl: No such file or directory

        Samurai Monkey:

        Try ls -lb begperl and see what it prints. I'm wondering if you accidentally got a control character in the name of the file. (It happens, sometimes.) Also, if you're at the command prompt, then you could always type perl begperl/new and then hit the tab key to see if autocomplete will fill in the rest for you. If neither of those work for you, I'll try to think of something else.

        Oh, yeah, you can use the cd command to change directories, so cd begperl will put you in the begperl directory, and cd .. will take you back down a level. Type man cd to read the manual page for cd.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Re: perl can't find my script on ubuntu
by zentara (Cardinal) on Dec 15, 2010 at 13:56 UTC
    "newline.pl" Unfortunately, when I open up the terminal in Ubuntu, it doesn't work.

    The first program I recommend to newbies on linux is mc.

    Try learning with Midnight Commander.... for Ubuntu, it's "sudo apt-get install mc". With mc, you just hit Enter on a script, and it will run if the script's shebang line is properly set, and permissions are right. See mc homepage

    The program mc, was one of the original filemangers for linux, before Xwindows became so prevalent. It handles permissions, has syntax highlighting for Perl scripts, contains a binary viewer/editor, etc.... a swiss-army knife for filesystems.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Excuse my ignorance, but is MC like Ubuntu? Or is it something FOR UBuntu that helps programmers run perl scripts?
        mc is a terminal mode filemanager, it is a program that runs in a terminal. Just start a terminal, and type mc,(then Enter), and it will run. Google for some tutorials on how to use it, but it is pretty self explanatory. It views, edits, and executes files as a start. I find it makes writing/debugging scripts easier, because you can quickly learn it, and it has hotkeys with many commands a linux system administrator would use.

        It is an old program, but many people still swear by it, as it runs without an Xserver, and works over ssh. It is often compared to the old Norton Commander, the msdos filemanager program.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh
Re: perl can't find my script on ubuntu
by RedElk (Hermit) on Dec 14, 2010 at 21:48 UTC

    Like the previous post commented, you may not be at the right directory. For example, may be missing a preceeding '/' such as... perl /begperl/newline.pl.

    I encountered this problem often and anymore CD to the required directory before running anything.

      RedElk, thank you for your response. I've been trying to figure out how to change the directory from my home directory to the directory that I want to work off of such as the begperl directory in the Ubuntu terminal. You said you used to encounter this same problem before, but not any more because you changed the directory? How did you do so in the Ubuntu terminal?

        Roboticus touched on it in his post. The change directory command is cd. However, before I use cd I start with the list command ls. This allows me to see everything in my home directory. From there, I cd into the needed directory. I may alternate these commands two or three times depending upon what level I need to get to. Admittedly, I prefer visual queues. Your stylings may vary

        That being said, I'm always starting from my Ubuntu home directory. I would assume this is the case for you as well. But to check this, you can use the working directory command pwd. If you're not at your home directory use the cd command followed by nothing to navigate there.I've found this command line reference helpful.

        I still think that you need a '/' at the beginning of the line when you intend to navigate multiple directories on the command line such as when you try to run your newline.pl script.

        perl /begperl/newline.pl ^