I have following code
#!/usr/bin/perl
$startDir = q{c:\test};
$newDir = q{c:\new};
&myReadDir($startDir);
exit 0;
sub myReadDir
{
my ($dir) = @_;
my (@dirs,$list);
opendir(DIR,$dir) || warn "can't open the directory $dir: $!\n
+";
@dirs=grep {!(/^\./) && -d "$dir\\$_"} readdir(DIR);
closedir (DIR);
for $list(0..$#dirs)
{
mkdir ($newDir) unless -d $newDir;
$ndir = $dir;
$ndir =~ s/c:\\test/c:\\new/;
print $ndir."\\".$dirs[$list],"\n";
mkdir ($ndir."\\".$dirs[$list]);
&myReadDir($dir."\\".$dirs[$list]);
}
return 1;
}
&myReadDir($startDir);
what does & mean in this line of code ? If I want to use subroutine, I just need to use it as myReadDir($startDir). What is "&" used for as prefix ?
my ($dir) = @_;
Why is variable $dir surrounded by () ?
my (@dirs,$list);
What does this code do ? Usually we declare list in bracket on right hand side and that contains values. What does this code do ? Where can I find more details about this code ?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.