Click to See Complete Forum and Search --> : CGI -> write file


doppio
12-14-2004, 02:18 AM
hello!,

I have this sub but not work...why?

Sub stampa {
my $view = shift;

if ($view eq 'ONAIR') {
$file = /ONAIR/index2.html;
$OUT = 'FILE_OUT';
}
elsif ($view eq 'STANDBY) {
$file = /STANDBY/index2.html;
$OUT = 'FILE_OUT';
}
elsif {
$OUT = 'STDOUT';
}

# Apro il file per scrivere
open (FILE_OUT, ">$file");

# Se il tipo di visualizzazione NON è onair o standby
# Stampo a video
print $OUT $pagina;

# chiudo il file aperto
close(FILE_OUT);
}

thank

Nedals
12-14-2004, 01:48 PM
sub stampa { ## lowercase
my $view = shift;
my $file = ""; ## needs to be declared if using strict

if ($view eq 'ONAIR') {
$file = "/ONAIR/index2.html"; ## not quoted
$OUT = 'FILE_OUT';
}
elsif ($view eq 'STANDBY') { ## missing quote
$file = "/STANDBY/index2.html"; ## not quoted
$OUT = 'FILE_OUT';
}
elsif { ## no condition specified. Should this read 'else'?
## if this is true, $file is undefined and will cause an error??
$OUT = 'STDOUT';
}

# Suggest you move the code below into each of the if/else blocks
# That way, you simplify the code and only open the file when needed
# Apro il file per scrivere
open (FILE_OUT, ">$file");

# Se il tipo di visualizzazione NON è onair o standby
# Stampo a video
print $OUT $pagina;

# chiudo il file aperto
close(FILE_OUT);
}