Rabenschwinge has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I am having a problem for which I don't quite understand the reason...
Perl complains that I am trying to redefine variables, even when I am just accessing them.
Could anyone explain this to me, please?
1 #!/usr/bin/env perl 2 use strict; 3 use warnings; 4 use Net::FTP; 5 6 my $host = 'ftp.example.com'; 7 my $user = 'smith'; 8 my $pass = 'secret'; 9 my $dir_name = '/'; 10 my $target_dir = '/var/tmp/ftp-download'; 11 my $tmp_dir = '/var/tmp'; 12 my $last_index_file = '/var/tmp/last-index'; (...) 42 my $ftp = Net::FTP->new($host); 43 $ftp->login($user, $pass); 44 $ftp->cwd($dir_name); 45 my @dir = $ftp->ls();
FIXED. There were two lines wrong I didn't quote. Instead of !~ to see whether a regular expression does not match I wrote ~! twice in the lines above that. I don't know how this could lead to the error, but it seems fixed now.~/bin# ./test.pl "my" variable $host masks earlier declaration in same scope at ./ftp-t +est.pl line 42. "my" variable $ftp masks earlier declaration in same scope at ./ftp-te +st.pl line 43. "my" variable $user masks earlier declaration in same scope at ./ftp-t +est.pl line 43. "my" variable $pass masks earlier declaration in same scope at ./ftp-t +est.pl line 43. "my" variable $ftp masks earlier declaration in same scope at ./ftp-te +st.pl line 44.
# Append a '/' to directories if needed if ($target_dir ~! m{\/$}) { $target_dir .= '/'; } if ($tmp_dir ~! m{\/$}) { $tmp_dir .= '/'; }
# Append a '/' to directories if needed $target_dir .= '/' unless ($target_dir =~ m{\/$}); $tmp_dir .= '/' unless ($tmp_dir =~ m{\/$});
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Redifined variable?
by almut (Canon) on Sep 30, 2009 at 14:28 UTC | |
|
Re: Redifined variable?
by moritz (Cardinal) on Sep 30, 2009 at 14:11 UTC | |
|
Re: Redifined variable?
by JavaFan (Canon) on Sep 30, 2009 at 14:33 UTC | |
|
Re: Redifined variable?
by Anonymous Monk on Sep 30, 2009 at 13:59 UTC | |
|
Re: Redifined variable?
by venkatesan_G02 (Sexton) on Sep 30, 2009 at 14:19 UTC |