develooper Front page | perl.beginners | Postings from January 2002

why am I getting syntax errors ?

Thread Next
From:
Filip Sneppe
Date:
January 8, 2002 09:30
Subject:
why am I getting syntax errors ?
Message ID:
018101c19869$f6906210$6c0a200a@yucom.local
Hi,

I have the following code to parse a config file:

my @section_headers = ("general", "database", "preprocessing",
"postprocessing", "queries");

....

while(<>)
  {
  /^[\t ]*$/ && { print "blank\n" };
  /^[\t ]*#/ && { print "comment\n" };

  /\[.*\]/   &&
    {
    $config_section = (split (/[\[\]]/,$_))[1],
    print $config_section ." \n",
#    foreach $i (@section_headers)
#      {
#      $config_current_section = (lc($config_section) eq $i) ?
$i:$config_current_section
#      },
#    die "config error - no valid section header\n" if
($config_current_section ne $config_section && $config_current_section ne
"queries"),

#    for(my $x;$x<10;++$x) print "gg",

    print "in section $config_current_section -> $config_section\n"
    };

  }

Now why am I getting syntax errors as soon as I uncomment either
the foreach stuff, the die line, or the for loop.

I came accross the while loop and the "/(matches)/ && (commands)"
when looking for a "select ... case" equivalent in perl, but I
don't want to push every additional processing of $_ to subroutines
and call them from the while loop...

Any help on how I can fix this ?

TIA,
Filip


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About