[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Syntax problems . . .



Adam.Reynolds@syphax.co.uk wrote
>sub make_file {
>  if ($form{'EntryType'} eq "Enhanced") { ## if enhanced then create a
>directory to put 5 files in (eventually)
>    if (%page_loop = 1) {
>      $dirname = "$root$Profiles$form(OCNumber)";
>      mkdir ($dirname, 0755);
>      }
>    $filename =
>"$root$Profiles$form(OCNumber)$dir$form(OCNumber)%page_loop$html";
>    }
>  else {
>    $filename = "$root$Profiles$form(OCNumber)%page_loop$html"; ## not
>enhanced only create 1 file
>    }
>  open (OUT,">$filename") ||
>  }
>
>, is the subroutine.  I am performing syntax checks as I go through so I
>don't end up with one almighty mess at the end (I am still very new at
>this) and I keep getting a report that there is a syntax error near the
>final }

I think you want either
  open (OUT,">$filename");
or
  open (OUT,">$filename") || die "trying to open '$filename';

more importantly though YOU SHOULD CHECK EVERY SYSTEM CALL FOR FAILURE
I suspect your mkdir above is going to fail either because the name gets
too long or perhaps you'd intended there to be a path separator ':'.

You also want to start every script like so
#!perl -w
use  strict;
scripts should run without producing any compiler or run-time warnings.
Sure if you're know what you're doing you can get lax and ignore them when
you know you can get away with it, but as a beginner you should accept that
each of them is likely to indicate a bug, maybe not causing a problem now
but going to bite you sooner or later. Probably later when you've forgotten
all about how the program works and it will take ten times as long to
find/fix the problem.

You also are using global variables instead of passing parameters to the
subroutine, so I'd probably rewrite it something like this, but it's not
really clear whether the directory structure being created is correct (you
really want
"$root$Profiles$form(OCNumber)$root$Profiles$form(OCNumber)$form(OCNumber)%p
age_loop$html" ? (assuming that you mean $dirname instead of $dir.


sub make_file (\%$$)
{
  my ($form, $dirname, $page_num) = @_;
  my ($path);

  if ($form->{'EntryType'} eq "Enhanced") {
    if ($page_num = 1) {
       $dirname .= ":Enhanced";
       mkdir ($dirname, 0755) || die "trying to mkdir '$dirname'; $!";
    }
  }
  $path = "$dirname:$form->(OCNumber)$page_num.html";
  open (OUT,">$path") || die "trying to open '$path'; $!";
}

  # I'm sure I'm not getting the directory structure right...
  for my $i (1..$form{"NumPages"}) {
    make_file %form, "$root:$Profiles:$form{OCNumber}", $i;
  }

cheers,
Danny Thomas



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch