Re: missing curly - brain fried



Hi Amichai,

first of all never write own code without these two lines:

use strict;
use warnings;

this should allways help a lot. Remember the e-mail from Chas Owens
regarding the "shuffling cards".

making comments in perl goes this way:

# hello, i am a comment.

you made C-style comments: //, /* and */ are not allowed in perl.


there are some other mistakes in your code (e.g use "for" always in this
way: for(..) { .. } ) but you should fix your comments first and then you
can start over trying to learn perl :)
Have fun!

HTH, Martin


On Thu, 28 Jun 2007 17:54:01 +0300
"Amichai Teumim" <amichai@xxxxxxxxxx> wrote:

Where is the open curly missing here?

#!/usr/bin/perl

@array = (5,3,2,1,4);


for ($i=0; $i<$n-1; $i++) {
( for ($j=0; $j<$n-1-$i; $j++)


if ($array[$j+1] < $array[$j]) { /* compare the two neighbors
*/
$tmp = $array[$j]; /* swap $array[j] and $array[j+1]
*/
$array[$j] = $array[$j+1];
$array[$j+1] = $tmp;
}
}


foreach $elem (@array){
print "$elem";
}
.



Relevant Pages

  • Re: error messege: "subroutine Cwd::fastcwd redefined"
    ... Attached is the file created by perlbug. ... asking for all warnings even though Cwd is trying (via the older ... case it looks like a bug in the Perl distribution. ... HOME (unset) ...
    (perl.beginners)
  • Re: What do you need to have to be considered a Master at Perl?
    ... (--and note the warnings, in particular: ... Because perl's regex engine is not currently re-entrant, ... Quote from "perlre - Perl regular expressions" ... ... defined inside an eval'ed pattern are not available ...
    (comp.lang.perl.misc)
  • Re: file rename help
    ... > I am very novice as you will see in my Perl skills. ... use warnings; ... because I am not afraid of undef values, ... even as a piece of shell code, your command is wasting at least two ...
    (comp.lang.perl.misc)
  • Re: debugger exiting
    ... strict and warnings pragmas. ... I think portraying Perl as a command-line tool limits it to fewer platforms than ... work only as a Unix shell command line. ...
    (perl.beginners)
  • Re: Multiple Parameters
    ... The above two lines ask Perl to hold you to the laws of good ... programming. ... you'll get better error messages and warnings ...
    (perl.beginners)