Perl While Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow syntax error at near the company Business Learn more about hiring developers or posting ads with us Stack perl syntax error near my Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of perl syntax error near unexpected token 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Perl syntax error near for loop? [closed] up vote 1 down vote favorite On the code block given
Perl Else If
below when I run it under linux... my $source = 'BAD-IP-Addresses-LABEL'; my $type_description = 'honeypots-for-examnple'; open(FP, 'your-csv-file.csv') for my $line (
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Perl Syntax Error - “syntax error line 15 near ”} else“ ” up vote 1 down http://stackoverflow.com/questions/20706112/perl-syntax-error-near-for-loop vote favorite I've got a really annoying problem in Perl. Here is my code: if $password eq "a_secret"; { foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print '${var}=\"${val}\"\n' }; } else { print "
Unauthorized
You do not have permission to access \printenv\printenv.pl on this server."; } When I execute this code I get the following error message: syntax error line 10 near "else" Any Ideas? Note http://stackoverflow.com/questions/13730208/perl-syntax-error-syntax-error-line-15-near-else that some of the code has been removed. perl share|improve this question edited Dec 5 '12 at 18:56 asked Dec 5 '12 at 18:44 Python Kid 83418 What's with the -4??? This is a well worded, concise question. –ikegami Dec 5 '12 at 20:27 add a comment| 3 Answers 3 active oldest votes up vote 4 down vote accepted if ($password eq "a_secret") { foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print '${var}=\"${val}\"\n'; } } else { print "Unauthorized
You do not have permission to access \printenv\printenv.pl on this server."; } share|improve this answer answered Dec 5 '12 at 20:34 Starfish 799720 Thanks! This really helped! –Python Kid Dec 5 '12 at 20:40 add a comment| up vote 5 down vote So many things to comment on. The error is in the very first line: you're missing parenthesis around the condition, and that ; at the end is superfluous. Next: Writing \n inside a single-quoted string '...' will not do what you want. Then, not really wrong, but not exactly good style either: print "..." } ; should have the ; and the } reversed. share|improve this answer answered Dec 5 '12 at 18:48 Moritz Bunkus 8,66222446 Not to nitpick butQ&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Nov 06, 2007 at 11:07UTC ( #649179=perlquestion: print w/replies, xml ) Need Help?? greymoose has asked for the wisdom of the Perl Monks concerning the following question: I have a piece http://www.perlmonks.org/?node_id=649179 of code that looks up two arrays from a table in a MySQL http://perldoc.perl.org/perlsyn.html database and is then supposed to print out the information on a web page. (Sorry to those monks of greater learning but I haven't got beyond using PERL for cgi.) The data is looked up by exist_deadline.cgi which is called by about_deadline.cgi The while loop (lines 30 -33 of about_deadline.cgi) where syntax error the information is supposed to print out always results in error messages: syntax error at /usr/lib/cgi-bin/about_deadline.cgi line 30, near ") { +" syntax error at /usr/lib/cgi-bin/about_deadline.cgi line 33, near "}" [download] I've found another thread asking the same question and triple checked the answers that monk received. The error disappears if I take the call to the second script out. I can't find a perl syntax error missing semicolon or extra brace (yes, my editor does colour code my syntax). That's not to say that it isn't there somewhere but I am bamboozled. I'm posting the code below. Can anyone see what I've missed? about_deadline.cgi my ($conf) = new Config::General( -ConfigFile => 'somefile.conf', -ExtendedAccess => 1 ); my ($databaseUser)=$conf->value("user"); my ($databaseName) = $conf->value("name"); my ($databasePw) = $conf->value("pass"); # Declare local variables my ($dbh); my ($stmt, $sth); my (@deadlinetyp, @deadline); my $i = 0; while ($deadlinetyp[$i]) { print $deadlinetyp[$i]." ".$deadline[$i]."
"; $i++; } [download] exist_deadline.cgi print header; my ($conf) = new Config::General( -ConfigFile => 'somefile.conf', -ExtendedAccess => 1 ); my ($databaseUser)=$conf->value("user"); my ($databaseName) = $conf->value("name"); my ($databasePw) = $conf->value("pass"); # Declare local variables my $dbh; my ($stmt, $sth); my @aRow; my $j=0; $dbh = DBI->connect($databaseName, $databaseUser, $databasePw) || die "Connect failed: $DBI::errstr\n"; #Get available deadline details $stmt = "SELECT dead_typ, dead_line FROM deadlines"; #Prepare and execute the SQL query $sth = $dbh->prepare($stmt) || die "prepare: $stmt: $DBI::errstr"; $sth->execute() || die "execute: $stmt: $DBI::errstr"; while (@aRow = $sth->fetchrow()){ $deadlinetyp[$j] = @aRow[0]; $deadline[$j] = @aRow[1]; $j++; } # Clean up the record set and the database connection $sth->finish(); $dbh->disconnec
A • B • C • D • E F • G • H • I • L M • N • O • P • S T • U • X perlsyn Perl 5 version 24.0 documentation Go to top • Download PDF Show page index • Show recent pages Home > Language reference > perlsyn Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled, or are running a non-JavaScript capable web browser. To get the best experience, please enable JavaScript or download a modern web browser such as Internet Explorer 8, Firefox, Safari, or Google Chrome. Recently read perlsyn NAME DESCRIPTIONDeclarations Comments Simple Statements Truth and Falsehood Statement Modifiers Compound Statements Loop Control For Loops Foreach Loops Basic BLOCKs Switch StatementsGoto The Ellipsis Statement PODs: Embedded Documentation Plain Old Comments (Not!) Experimental Details on given and whenNAME perlsyn - Perl syntax DESCRIPTION A Perl program consists of a sequence of declarations and statements which run from the top to the bottom. Loops, subroutines, and other control structures allow you to jump around within the code. Perl is a free-form language: you can format and indent it however you like. Whitespace serves mostly to separate tokens, unlike languages like Python where it is an important part of the syntax, or Fortran where it is immaterial. Many of Perl's syntactic elements are optional. Rather than requiring you to put parentheses around every function call and declare every variable, you can often leave such explicit elements off and Perl will figure out what you meant. This is known as Do What I Mean, abbreviated DWIM. It allows programmers to be lazy and to code in a style with which they are comfortable. Perl borrows syntax and concepts from many languages: awk, sed, C, Bourne Shell, Smalltalk, Lisp and even