Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(simple) perl syntax problem

Status
Not open for further replies.

bobttmac

MIS
Mar 15, 2007
3
US
Having a syntax problem and don't see it, do you?

Here's the output from the command line:

C:\Perl\site\bin>perl -w ports.pl
syntax error at ports.pl line 21, near ")
{"
syntax error at ports.pl line 25, near "}"
Execution of ports.pl aborted due to compilation errors.




#!/usr/bin/perl -w

#************************************************
# modify list of ports for use in cisco/catos command file
#************************************************

# < or r Read Only Access
# > or w Creates, Writes, and Truncates
# >> or a Writes, Appends, and Creates
# +< or r+ Reads and Writes
# +> or w+ Reads, Writes, Creates, and Truncates
# +>> or a+ Reads, Writes, Appends, and Creates

open (COMMANDS, "<commands.txt") or die "Could not open commands.txt.\n";
@commands = <COMMANDS>;
close COMMANDS;
#
$x = 0;
#
While ( $commands[$x] )
{
chomp ($commands[$x]);
print "$command[$x]\n";
$x= $x + 1;
};
 
I saw another mistake:
print "$command[$x]\n";
should be
print "$ocmmands[$x]\n";



also if you are just printing the hash you can do
chomp @commands;
for $command (@commands) {
print "$command\n";
}
 
all builtin perl functions are all lower-case: "While" has the be "while".

Note also you have the wrong variable name here:

Code:
print "$command[$x]\n";

should be:

Code:
 print "$command[red]s[/red][$x]\n";

You should be using:

Code:
use strict;
use warnings;

in your perl scripts. They will help you write good perl code.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
ahh, travs69 was much faster on the draw. [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
You guys have good eyes, thanks for the tips esp. about the use commands for help in getting syntax right.

I wrote a simple comiler a long time ago, it would have caught the keyword not begin a legal one...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top