1833187 Members
2806 Online
110051 Solutions
New Discussion

about perl

 
SOLVED
Go to solution
kamal_15
Regular Advisor

about perl

hi all
iam new in perl language
i have hp-ux v 10.2
and perl 5

i get documentation about perl
but
when i tryed to write a simple script as follow:

my $a="hello";
print $a;

this script will return error syntax
"my $a"
i executed this file as (perl script_name.pl)

please help if there is any environment is not defiened correctly
thankx
kamal

12 REPLIES 12
Peter Godron
Honored Contributor

Re: about perl

Kamal,
can you please attach the script?
I just copied it into a.pl and executed via:
perl a.pl
and it worked.
What does the error syntax message say?
kamal_15
Regular Advisor

Re: about perl

many thanks peter for your help

this is script NO.1 (p1.pl)
*********************************
my %var1 = (
user1 => "kamal"
user2 => "ahmed",
);
print keys %var1;
***********************************
and it is the error
***********************************
Illegal modulus of constant zero in file t1.pl at line 1, next 2 tokens "var1 ="
syntax error in file t1.pl at line 2, next 2 tokens "=>"
Execution of t1.pl aborted due to compilation errors.

---------------------------------------------
---------------------------------------------
this is script NO.2 (p2.pl)
***********************************
my $a = "hello"
print $a;
***********************************
and it is the error
***********************************
syntax error in file t2.pl at line 1, next 2 tokens "my $a "
Execution of t1.pl aborted due to compilation errors.
***********************************


i think i have problem in my environment for perl.

please help

thank you

kamal
Rodney Hills
Honored Contributor

Re: about perl

my %var1 = (
user1 => "kamal"
user2 => "ahmed",
);

You are missing a comma after "kamal".

my $a = "hello"
print $a;

You are missing a semi-colon after "hello".

HTH

-- Rod Hills
There be dragons...
Hein van den Heuvel
Honored Contributor

Re: about perl

The script you show does NOT match the original scripts posted!

my %var1 = (
user1 => "kamal"
user2 => "ahmed",
);
print keys %var1;

Here you should have a comma after kamal, but not after ahmed.

***********************************
my $a = "hello"
print $a;


This misses the required semicolon after on the first line!

---------------------------
my %var1 = (
user1 => "kamal",
user2 => "ahmed"
);
print keys %var1;
-----------------------
my $a = "hello";
print $a;
-------------------------

H.Merijn Brand (procura
Honored Contributor

Re: about perl

No need to attach the script here.

'my' is a perl5 keyword, and I bet you have an old perl4 (/usr/contrib/bin) that prevails in your $PATH

# perl -v

should show it

just make sure (edit /etc/PATH) that /usr/contrib/bin is last in your $PATH

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: about perl

For #2:

add a ; after "hello"


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Peter Godron
Honored Contributor

Re: about perl

Kamal;
a very quick check:
perl -e'my $a="hello";print $a'
Ensure that perl/lib is in your $PATH
Check what you are running with : which perl
Ours is in /usr/contrib/bin
kamal_15
Regular Advisor

Re: about perl

hil all

sorry for missing ;( i forget it only during copy script but it exist).


i tryed command
perl -v
and return (This is perl, version 4.0).

and (/usr/contrib/bin)exist in my path variable.

what can i do?
thankx



Peter Godron
Honored Contributor

Re: about perl

kamal,
download/install the latest version then try again.
http://www.perl.com/CPAN/ports/index.html
Regards
H.Merijn Brand (procura
Honored Contributor
Solution

Re: about perl

your header states that you also have installed perl5, so as I said, move /usr/contrib/bin to the end of your $PATH

perl4 is dead!

# echo $PATH
# /usr/contrib/bin:/bin:/usr/local/bin:/usr/bin

for sh/ksh/bash:
# export PATH=/bin:/usr/local/bin:/usr/bin:/opt/perl/bin:/usr/contrib/bin
for tcsh/csh:
# setenv PATH /bin:/usr/local/bin:/usr/bin:/opt/perl/bin:/usr/contrib/bin

Be sure to change it in /etc/PATH too!

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
kamal_15
Regular Advisor

Re: about perl

many thankx for all

i found perl 5 installed
but the path for perl 5 not including in /etc/PATH. (only perl 4 including)

i made the changes
and now every thing is ok

many thankx again for all

kamal
kamal_15
Regular Advisor

Re: about perl

thankx