LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl - Porting Korn To Perl In AIX Platform (https://www.linuxquestions.org/questions/programming-9/perl-porting-korn-to-perl-in-aix-platform-854576/)

mufy 01-06-2011 05:37 AM

Perl - Porting Korn To Perl In AIX Platform
 
I'm in the process of brushing up my skills using Perl. As a starter, I tried to convert an existing KSH script that I wrote to Perl.

Just added:
Code:

#!/usr/bin/perl

use strict;
use warnings;

to the start of the script.

Renamed my script from bancsadm.ksh to bancsadm.pl (just for identification purpose) and called the new file. I was expecting errors, but the script fired beautifully.

I invoked the script again as:
Code:

perl bancsadm.pl
and this time a lot of errors were generated.

What I'd like to know is why the perl environment did not fire the first time even though I included #!/usr/bin/perl at the start of the script.

timmeke 01-06-2011 06:05 AM

Is the .pl file marked with executable permission?
I'm also not sure if AIX gives you a "bad interpreter" error
if there's something wrong with the shebang line (line starting with #!).
So you might want to check if /usr/bin/perl is an existing, executable file (Perl interpreter).
You could for instance try calling
Code:

/usr/bin/perl
.

mufy 01-06-2011 06:09 AM

Sure it is marked as an executable. And perl is definitely an existing executable:
Code:

root@prapbc[/home/bancsadm] #which perl
/usr/bin/perl


Sergei Steshenko 01-06-2011 06:35 AM

Quote:

Originally Posted by mufy (Post 4215059)
I'm in the process of brushing up my skills using Perl. As a starter, I tried to convert an existing KSH script that I wrote to Perl.

Just added:
Code:

#!/usr/bin/perl

use strict;
use warnings;

to the start of the script.

Renamed my script from bancsadm.ksh to bancsadm.pl (just for identification purpose) and called the new file. I was expecting errors, but the script fired beautifully.

I invoked the script again as:
Code:

perl bancsadm.pl
and this time a lot of errors were generated.

What I'd like to know is why the perl environment did not fire the first time even though I included #!/usr/bin/perl at the start of the script.

The item in red contradicts the item in blue.

mufy 01-06-2011 06:39 AM

I understand :-). What I meant was the script executed as a normal KSH script at first and threw errors only when I explicitly invoked the same from the CLI prefixing it with 'perl'.

Hope it makes sense now.

Sergei Steshenko 01-06-2011 07:00 AM

Quote:

Originally Posted by mufy (Post 4215117)
I understand :-). What I meant was the script executed as a normal KSH script at first and threw errors only when I explicitly invoked the same from the CLI prefixing it with 'perl'.

Hope it makes sense now.

How about putting this:

Code:

#!/usr/bin/perl

use strict;
use warnings;

warn "checkpoint";

__END__

in the very beginning and again trying

Code:

/full/path/to/bancsadm.pl
?

mufy 01-06-2011 07:17 AM

Even now the script is firing in a perl environment only if prefixed and invoked as:
Code:

perl bancsadm.pl
and executing as a normal KSH script if invoked otherwise. Why is that?

Sergei Steshenko 01-06-2011 07:51 AM

Quote:

Originally Posted by mufy (Post 4215161)
Even now the script is firing in a perl environment only if prefixed and invoked as:
Code:

perl bancsadm.pl
and executing as a normal KSH script if invoked otherwise. Why is that?

Publish here output of

Code:

ls -ltr /full/path/to/bancsadm.pl
- of course, use real full path.

Also, publish here output of

Code:

head -1 /full/path/to/bancsadm.pl
.
...
Did you edit your script on Windows ? What does

Code:

file /full/path/to/bancsadm.pl
say ?

mufy 01-24-2011 12:49 AM

Please find below the information requested -
Code:

root@prapbc[/] #ls -ltr /home/bancsadm/bancsadm.pl
-rwxrwxr--  1 bancsadm fnspr          3616 Jan 06 16:16 /home/bancsadm/bancsadm.pl

root@prapbc[/] #head -5 /home/bancsadm/bancsadm.pl
#!/usr/bin/env perl
use strict;
use warnings;

warn "checkpoint";

root@prapbc[/] #file /home/bancsadm/bancsadm.pl
/home/bancsadm/bancsadm.pl: commands text


Sergei Steshenko 01-24-2011 06:56 AM

Quote:

Originally Posted by mufy (Post 4235629)
Please find below the information requested -
Code:

root@prapbc[/] #ls -ltr /home/bancsadm/bancsadm.pl
-rwxrwxr--  1 bancsadm fnspr          3616 Jan 06 16:16 /home/bancsadm/bancsadm.pl

root@prapbc[/] #head -5 /home/bancsadm/bancsadm.pl
#!/usr/bin/env perl
use strict;
use warnings;

warn "checkpoint";

root@prapbc[/] #file /home/bancsadm/bancsadm.pl
/home/bancsadm/bancsadm.pl: commands text


What does the

Code:

perl -V
command produce ?

Also, try to replace

Code:

#!/usr/bin/env perl
with
Code:

#!/usr/bin/perl
.

What does

Code:

ls -ltd /home/bancsadm
command produce ?


All times are GMT -5. The time now is 09:23 PM.