Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get 'use: command not found' when I run my Perl script?

Tags:

perl

I'm new to Perl. And I have used following code from one forum to connect to one of the server. but throwing error messages

[root@Cus]# cat tt.pl
#!/usr/bin/perl
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');
$telnet->open('10.0.0.28');
$telnet->waitfor('/login:/');
$telnet->print('administrator');
$telnet->waitfor('/Password:/');
$telnet->print('test');
$telnet->waitfor('/switch8-12>/');
$telnet->print('whoamI');
$output=$telnet->waitfor('/switch8-12>/');
print $output;

But throwing following error messages.

[root@Cus]# ./tt.pl
./tt.pl: line 3: use: command not found
./tt.pl: line 4: syntax error near unexpected token `('
./tt.pl: line 4: `$telnet = new Net::Telnet ( Timeout=>2, Errmode=>'die');'
like image 415
user301133 Avatar asked Mar 25 '10 15:03

user301133


People also ask

Which command is used to run Perl script programs?

1. Run the "perl" command with the Perl script included in the command line. For example, enter the following command line in a shell window: /home/herong$ perl -e "print 'Hello world!

What is the use of Perl command?

"Perl" officially stands for "Practical Extraction and Report Language." It was originally a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It quickly became a good language for many system management tasks.

How do I run a Perl command in Python?

Your answer Open your Python code in your Python editor of choice. Go to the line in the code where you want to run your Perl script. Type "pyth. RunPerl.


1 Answers

My guess is that you're using a weird flavour of unix that doesn't respect the #! line, and is trying to run the script via the shell instead of via perl.

Another reason why this might happen is if tt.pl starts with a blank line. The #! must appear at the very start of the file.

Try running perl tt.pl and see what happens.

like image 128
dave4420 Avatar answered Oct 01 '22 13:10

dave4420