In your first while(<$IN>) loop you run through each line of the file until the end - after that loop $IN is empty. You need to put some check to break out of the first loop once you have the info you require, something like:
while (<$IN>) {
if (/(^w.*)/) {
push @lsl,$1;
}
elsif (/^Directories/) {
last;
}
}
In your second while(<$IN>) loop you print out the contents of %Hash for each found line - the first time %Hash will have only one item, the second two and so on. You need to take the print out of that loop. Also, everything is being added to the single @array and to the single @indexes, so the information of all keys will be printed for each key. Here is a different way to do it:
sub GetDFSdata {
#...
#Get the list of file names and indexes
my $name;
while(<$IN>){
chomp;
next if /^operator/;
#...etc.
if (m/$start/) {
$name = $1;
} elsif (m/^record size:\s+\d+/) {
$Hash{$name}{'record_size'} = $_;
} elsif (m/^last record:\s+\d+/){
$Hash{$name}{'last_record'} = $_;
} elsif (m/^data byte count:\s+\d+/) {
$Hash{$name}{'data_byte_count'} = $_;
} elsif (m/^\s+index name:\s+(\w.*)/) {
push(@{ $Hash{$name}{'indexes'} }, $1);
}
}
close $IN;
foreach my $key (keys %Hash) {
print $OUT "File: $key<BR>\n";
print $OUT "\tRecord Size: $Hash{$key}{'record_size'}<BR>\n";
print $OUT "\tLast Record: $Hash{$key}{'last_record'}<BR>\n";
print $OUT "\tData Byte Count: $Hash{$key}{'data_byte_count'}<
+BR>\n";
my $str = join ',', @{ $Hash{$name}{'indexes'} };
print $OUT "Index Names: $str\n";
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|