Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with code snippet..

Status
Not open for further replies.

kudithipudi

IS-IT--Management
Feb 11, 2002
29
0
0
A2
Hello Guys,
Am staring at this peace of code for 2 hours now and have finally given up


#!/usr/bin/perl

use strict;

my $infile = 'machines.txt';
my $outfile = 'results.txt';

my @machines;
my ($machine, $CaptureSize, $FileSize);
my $datadir = '/home/migrate/data';

open(READ,"$infile");
@machines = <READ>;
close(READ);

open(WRITE,&quot;>$outfile&quot;);
chdir($datadir);
foreach $machine(@machines)
{
chomp($machine);
if (chdir($machine))
{
$CaptureSize = `du -ch CAPTURE.* | grep total`;
$FileSize = `du -ch *.MCF | grep total`;
print WRITE &quot;$machine $CaptureSize $FileSize\n&quot;;
}
chdir($datadir);
}
close(WRITE);


I am trying to parse a directory and get the size of some particular files in that directory. The code runs without any issues, but does not write anything to the results.txt file. What am I doing wrong here?

Thanks for the help.

- V.
 
My bad :).. I didn't notice that the directories don't even exist!! :). Think my code works fine. But would appreciate and input on making it better :). Thanks much.

- V.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top