Assistance understanding this script

Hi guys!

Im having problems trying to understand what the following code snippet does.
Any help appreciated.

What i do understand is....

- Open a directory called c:\started
- For each file $f in the started folder, read the file, and thats where i fall down.

=============================================================

opendir(DIR,"c:\\started");
foreach $f (readdir(DIR)) {
$file = $f;
$file =~ s/.*\///;
open(SUB,"<started/$f");
while (<SUB>) {
$_ = lc($_);
$_ =~ s/
//g;

$line = $_;
if ($_ =~ /^\n$/) { next; }

chomp($_);


print $f;
}
}

==========================================================
LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
opendir(DIR,"c:\\started"); #Open a directory called c:\started
foreach $f (readdir(DIR)) { #- For each file $f in the started folder,
$file = $f;
$file =~ s/.*\///;
open(SUB,"<started/$f");
while (<SUB>) { #read the file
$_ = lc($_); # get a lower case version of the line , see perldoc -f lc
$_ =~ s/
//g;  # remove newlines, see perldoc perlop

$line = $_; #make a copy of the line that never seems to be used
if ($_ =~ /^\n$/) { next; } # skip lines  that still contain only a newline

chomp($_); # remove a trailing newline, see perldoc -f chomp


print $f;  #print the name of the file, see perldoc -f print
}
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
ozo youre a champion.
Really appreciate your kind help.
I have another one id like to get help on so Ill post it :>)
Im actually going through a huge script and testing things as I go, and anything im not sure about, im posting snippets :>)
0
TintinCommented:
That code makes no sense.  If you remove all the redudant lines you are left with:
opendir(DIR,"c:\\started");
foreach $f (readdir(DIR)) {
  open(SUB,"<started/$f");
  while (<SUB>) {
    chomp;
    print $f;
  }
}

Open in new window

0
ozoCommented:
and given that $_ is not used, you can remove the chomp too
If $file and $line are used later, it also has the side effect of setting $file to the last file, and $line to the last line in the last file
If $/ has been set, or if there are blank characters that we don't see in the s/// then it could be possible for the print of the filename to be skipped some times
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.