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();
~/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.
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.
# 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{\/$});

In reply to Redifined variable? by Rabenschwinge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.