Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; } }

In reply to Re: Pulling specific data from a large text file by tangent
in thread Pulling specific data from a large text file by TStanley

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found