mr_evans2u has asked for the wisdom of the Perl Monks concerning the following question:

I want to pass only the servers that are online. When doing this I'm lose the information when passing the variable($filelock). If I do a print statement in the first sub I can see the servers that are online, but once I pass the variable $filelock I get nothing. What am I doing wrong? Thanks
####.pm file####
sub sieve_util_set_flagfile { my($relay_dir,$home_dir,$filename,@lock) = @_; my $filelock; foreach my $filelock (@lock) { if (my $ftp = Net::FTP->new($filelock)) { #die "Cannot login: $@ "unless $ftp; # Log into the server $ftp->login ("$uid", "$pass"); # Change to the right directory $ftp->cwd ("$relay_dir"); # Change to binary transfer mode $ftp->binary; @check_dir = $ftp->ls($relay_dir); if ($ftp->put($filename,$flag_file)) { $ftp->quit; } else { sieve_util_generic_error ("Unable to put $flag_file in $relay +_dir. The file is not locked from other users."); } } else { next; } }#end foreach return ($uid,$pass,$filelock); }

###.cgi file#####
($uid, $pass,$filelock) = sieve_util_set_flagfile($relay_dir,$home_dir,$filename,@lock);
sieve_util_remove_page($relay, $filename, $int_ext,$filelock);
####.pm file####
sub sieve_util_remove_page { my $relay_label; my ($relay, $filename, $int_ext,$filelock) = @_; if ($int_ext =~ /^int/i) { $relay_label = "Internal Relay: $filelock"; } else { $relay_label = "External Relay: $filelock"; } print start_html(-title=>"Sieve Filter Administration",), "<div align=\"center\">\n", br(br(br(h2(b("Removed!"))))), h3(b("The file lock on $filelock has been removed!")), hidden(-name=>"tflag", -default=>"$int_ext"); print end_html(); exit; }

Replies are listed 'Best First'.
Re: passing variable problem
by Abigail-II (Bishop) on Oct 14, 2003 at 22:43 UTC
    $filelock from the main program will be third scalar returned from sieve_util_set_flagfile. This function has a variable $filelock, which is never set. But it's returned as the third scalar. Now, the loop also uses a variable $filelock, but that's lexical to the loop.

    I don't know what your intention is of '$filelock', so I cannot offer any suggestion of what to do.

    Abigail

Re: passing variable problem
by dragonchild (Archbishop) on Oct 15, 2003 at 15:57 UTC
    Change your for-loop.
    my $filelock; for my $filelock (@locks) { #### To #### my $filelock; for $filelock (@locks) {

    That should do the trick. Now, 10 points if you can tell me why ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.