Not able to run the simple perl script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Not able to run the simple perl script
# 1  
Old 10-12-2009
Question Not able to run the simple perl script

Hi Experts,

I have written simple perl script, which assign the value to variable and print it. Following is the script:

HTML Code:
$ cat 3.pl
#!/usr/bin/env ksh
#!/usr/bin/perl
print "Hello World";
$iputlne = 34;
print $iputlne;
The error output is:

HTML Code:
$ /usr/bin/env perl 3.pl
Hello World
3.pl[4]: =: not found [No such file or directory]
This is simple script but it is not running... Smilie

Thanks in Advance!!
# 2  
Old 10-12-2009
I wouldn't have expected this to cause your error here (as you are specifying the interpreter to use on the commandline), but you are selecting ksh as your interpreter in the first line which will override the request to use perl on the next line.
The error message itself suggests that ksh, rather than perl is being run...
# 3  
Old 10-12-2009
Either change the first two lines to
Code:
#!/usr/bin/env perl

or
Code:
#!/usr/bin/perl

or
Code:
#!/usr/bin/env ksh
exec perl -w -x $0 "$@"
#!perl

# 4  
Old 10-12-2009
Thanks for the reply!!
My bad... Smilie
now i ran the same script in bash (removing the /usr/bin/env ksh)..and its running fine... Smilie

In the same script i have used "Spreadsheet::ParseExcel;" and now its again giving the compliation error... Smilie

Following is the code:
HTML Code:
#!/usr/bin/perl
$path_to_excel_file  = "/home/test/Book1.xls";
$path_to_output_file = "/home/test/Book1.csv";
use Spreadsheet::ParseExcel;
do_main();
sub do_main
{
  my ($oBook, $iR, $iC, $oWkS, $oWkC);
  $oBook = Spreadsheet::ParseExcel::Workbook->Parse($path_to_excel_file);
  open(FILE_OUT, "> $path_to_output_file");
  foreach my $oWkS (@{$oBook->{Worksheet}})
  {
    for (my $iR = $oWkS->{MinRow}; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++)
    {
      print FILE_OUT "   [[" . $oWkS->{Cells}[$iR][1]->Value . "]]: " . $oWkS->{Cells}[$iR][2]->Value . "\n";
    }
  }
  close(FILE_OUT);
And the error message is :

HTML Code:
Can't locate Spreadsheet/ParseExcel.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at perl_scr1.pl line 19.
BEGIN failed--compilation aborted at perl_scr1.pl line 19.
Its showing problem with "Spreadsheet::ParseExcel"
Can anybody help me out ?? Smilie Smilie

Really thankful for the help!! Smilie
# 5  
Old 10-12-2009
Perl can't find the module in any of it's search paths. Since Spreadsheet::ParseExcel isn't part of the core distribution, you'll have to install it by yourself. If it's available through your Linux distribution, install that, otherwise you'll have to use CPAN:
Code:
perl -MCPAN -e 'install Spreadsheet::ParseExcel'

# 6  
Old 10-12-2009
Question

Quote:
Originally Posted by pludi
Either change the first two lines to
Code:
#!/usr/bin/env perl

or
Code:
#!/usr/bin/perl

or
Code:
#!/usr/bin/env ksh
exec perl -w -x $0 "$@"
#!perl

Yes!! Smilie the third option is like magic...
Thanks!! Smilie

---------- Post updated at 02:51 AM ---------- Previous update was at 02:32 AM ----------

Quote:
Originally Posted by pludi
Perl can't find the module in any of it's search paths. Since Spreadsheet::ParseExcel isn't part of the core distribution, you'll have to install it by yourself. If it's available through your Linux distribution, install that, otherwise you'll have to use CPAN:
Code:
perl -MCPAN -e 'install Spreadsheet::ParseExcel'


Thanks for the quick reply!! Smilie Smilie

Will talk to our Unix admin..and install the Spreadsheet::ParseExcel. Smilie

Again thanks for the help!! Smilie Smilie

---------- Post updated at 05:13 AM ---------- Previous update was at 02:51 AM ----------

Hi,

We tried to install the CPAN,but while automatic installation,we are facing the problem ... Smilie The error is

Can't access URL ftp://ftp-mirror.internap.com/pub/CP...1mailrc.txt.gz

HTML Code:
Please check, if the URLs I found in your configuration file
(ftp://ftp-mirror.internap.com/pub/CPAN/) are valid. The urllist can be
edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch authors/01mailrc.txt.gz
LWP not available
Fetching with Net::FTP:
  ftp://ftp-mirror.internap.com/pub/CPAN/modules/02packages.details.txt.gz
Issuing "/usr/bin/ftp -n"
ftp-mirror.internap.com: unknown host or invalid literal address
Not connected.
Local directory now /home/dsadm/.cpan/sources/modules
The config.pm file is containing the url path as:
HTML Code:
cat  /home/dsadm/.cpan/CPAN/MyConfig.pm

$CPAN::Config = {
  'build_cache' => q[10],
  'build_dir' => q[/home/dsadm/.cpan/build],
  'cache_metadata' => q[1],
  'cpan_home' => q[/home/dsadm/.cpan],
  'dontload_hash' => {  },
  'ftp' => q[/usr/bin/ftp],
  'ftp_proxy' => q[],
  'getcwd' => q[cwd],
  'gpg' => q[],
  'gzip' => q[/usr/bin/gzip],
  'histfile' => q[/home/dsadm/.cpan/histfile],
  'histsize' => q[100],
  'http_proxy' => q[],
  'inactivity_timeout' => q[0],
  'index_expire' => q[1],
  'inhibit_startup_message' => q[0],
  'keep_source_where' => q[/home/dsadm/.cpan/sources],
  'lynx' => q[],
  'make' => q[],
  'make_arg' => q[],
  'make_install_arg' => q[],
  'makepl_arg' => q[],
  'ncftp' => q[],
  'ncftpget' => q[],
  'no_proxy' => q[],
  'pager' => q[/usr/bin/less],
  'prerequisites_policy' => q[ask],
  'scan_cache' => q[atstart],
  'shell' => q[/bin/sh],
  'tar' => q[/usr/bin/tar],
  'term_is_latin' => q[1],
  'unzip' => q[/usr/bin/unzip],
  'urllist' => [q[ftp://ftp-mirror.internap.com/pub/CPAN/]],
  'wget' => q[],
};
1;
__END__
Do we need to change the url?? Smilie Smilie
# 7  
Old 10-12-2009
That message rather seems to indicate a name resolution problem. Maybe you need to set the http_proxy and/or ftp_proxy options correctly, or choose an alternative server.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Simple CEC run command on event script

To cut a long story short I need to implement a CEC server in order to allow my Samsung TV to interact with other peripherals. I plan on using a RPi for this purpose. I have installed CEC-untils and can run the tvservice monitor to look for HDMI events. I now need a simple script that will run... (3 Replies)
Discussion started by: barrydocks
3 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Hopefully a simple script, bash or perl...

I'm attempting to parse a file whose contents follow this format; 4:/eula.1028.txt: 8:/eula.1031.txt: 19:/eula.1033.txt: 23:/eula.1036.txt: 27:/eula.1040.txt: 31:/eula.1041.txt: 35:/eula.1042.txt: 39:/eula.2052.txt: 43:/eula.3082.txt: The number of lines of the file... (4 Replies)
Discussion started by: CudaPrime
4 Replies

5. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

6. Shell Programming and Scripting

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

7. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

8. Shell Programming and Scripting

simple perl script not working

why won't below work? I am trying to see a)sipfile has username of the system. b)it will read the sipfile and do a grep function against the /etc/passwd c)it will save that output to /tmp/result.. but my script is just hanging... #!/usr/bin/perl -w open(SIPFILE, "</tmp/sipfile") ... (4 Replies)
Discussion started by: hankooknara
4 Replies

9. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat test.sh #! /bin/sh cd /etc sh-2.05b$ ./test.sh sh-2.05b$ pwd /tmp sh-2.05b$ . ./test.sh sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies

10. Shell Programming and Scripting

Simple Perl Script to Screen Display

$number_clients++; print("Creating client $number_clients\r"); I have been using the above to increment on the screen as the script increments throughout a while loop. What I would like to know is what is the trick to keep the last one on the screen without printing it again? Ie ... (1 Reply)
Discussion started by: Shakey21
1 Replies
Login or Register to Ask a Question