perl example not runiing

hi,
i wrote simple perl script and trying to run geting below error from


https://www.tutorialspoint.com/unix_terminal_online.php

sh-4.4$ vi hi.pl                                                                                                                                                                            
sh-4.4$ pwd                                                                                                                                                                                  
/home/cg/root                                                                                                                                                                                
sh-4.4$ /home/cg/root/hi.pl                                                                                                                                                                  
sh: /home/cg/root/hi.pl: Permission denied                                                                                                                                                  

i just wrote in hi.pl as
print "hii";


in command prompt of windows it ran fine once i install activevperl
https://www.activestate.com/activeperl/downloads

C:\Users\ss\perl\code>perl hello.pl
hii

please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Fr hi.pl to run, the permissions on the file must be 700 or -rwx------
The important parts are the r for read and the x for execute making the file an executable.
The last item, the first line in the script must be #!/usr/bin/perl
Without the above, even if you run chmod 700 hi.pl or chmod o+x hi.pl
Your error is because the file hi.pl is not executable. Once the above is done, the next attempt to run hi.pl
Will might error out because it would not know how to handle your input, or alternatively, sone she'll have a print function, and the script will run under a bash, zsh, ksh shell versus under perl as you intend.

Note the distinction of how you are trying to run hi.pl in the UNIX environment versus in the Windows. If you do the same in UNIX as you did on Windows you will get the same result, output.
Point being perl is the executeable and the file is an input argument.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
now is ee below error with print


sh-4.4$ vi hi.pl                                                                                                                                                                            
sh-4.4$ pwd                                                                                                                                                                                  
/home/cg/root                                                                                                                                                                                
sh-4.4$ /home/cg/root/hi.pl                                                                                                                                                                  
sh: /home/cg/root/hi.pl: Permission denied                                                                                                                                                  
sh-4.4$ chmod 700 hi.pl                                                                                                                                                                      
sh-4.4$ /home/cg/root/hi.pl                                                                                                                                                                  
/home/cg/root/hi.pl: line 1: print: command not found
0
gudii9Author Commented:
i have below content in file just one line

print "hii";
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

arnoldCommented:
Add the following as the first line in hi,pl
#!/usr/bin/perl

to make hi.pl look like (vi hi.pl
#!/usr/bin/perl
print "hi\n";

Open in new window


now run it, ./hi.pl
and you should see
hi
as the output.
0
gudii9Author Commented:
now i see output

sh-4.4$ vi hi.pl                                                                                                                                                                            
sh-4.4$ ./hi.pl                                                                                                                                                                              
hish-4.4$  

what is meaning of below line
#!/usr/bin/perl

my perl script not at above location but at brlow location

sh-4.4$ pwd                                                                                                                                                                                  
/home/cg/root

please advise
0
arnoldCommented:
Refereñce your Windows example
Your script, hi.pl is in the location reflected by pwd, the interpreter, perl is located in /usr/bin/perl
The first line tells the shell (environment in your case it is bash) where the interpreter that will process the script is.
Run the command,
which perl
This will tell your the command for perl is.
0
gudii9Author Commented:
sh-4.4$ which perl                                                                                                                                                                          
/usr/bin/perl  
is above is path where perl library is inatalled?
do we need to refer that in everu perl script i write at top?

who installed there tutoralpoint guys?
https://www.tutorialspoint.com/unix_terminal_online.php

i just instaled on windows laptop only
0
arnoldCommented:
Yes, unix, Linux scripts have to include the interpreter to be used to process the script as the first line
Note # means it is a comment
!/usr/bin/perl means use this executable.
At times shell script using sh, bash, ksh, zsh tcsh might be processed by the shell in which the person is
I.e. While first line says /bin/sh bash as the environment might process the script.
There are times where a script should be processed in a specific way, and to make sure one is directed to explicitly run
<shell> shell_script
Similar to the perl hi.pl you ran under Windows and can run under UNIX/Linux.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.