Ah, that changes things a bit. Is there a distinct and consistent string pattern that separates one ipconfig output from another, such as a blank line, or a line of dashes?
If so, you can assign that string to "$/" (rather than leaving it with the default value of CRLF, or setting it to undef, as suggested by BrowserUK). This way, you read one whole ipconfig output set in a single iteration of while (<>). For example, if the successive records are separated by a single blank line (and blank lines never occur within a single ipconfig output record), then you could do like this (untested):
(update: removed a spurious line of code)my %hostdata; { $/ = "\x0d\x0a\x0d\x0a"; # record separator is now a blank line while (<>) { # $_ now contains one whole ipconfig output next unless ( /Host Name.*?:\s*(.*)/ ); my $host = $1; @{$hostdata{$host}{dns}} = ( /\s(\d+\.\d+\.\d+\.\d+)\s/g ); ( $hostdata{$host}{typ} ) = ( /Node Type.*?:\s*(.*)/ ); } } # Now, keys %hostdata gives the list of host names from # all the ipconfig runs, and $hostdata{"hostname"} contains # the dns and node type info for each host. for ( sort keys %hostdata ) { print join "\n", $_, @{$hostdata{$_}{dns}}, $hostdata{$_}{typ}, "\n +"; }
If the separation between ipconfig runs is not distinct or consistent, then you'll want to fall back on BrowserUK's less-favored method that reads one line at a time and uses a status flag to keep track of what it's supposed to look for (and what it's supposed to do) as it works through each multi-line record.
In reply to Re: Re: Re: Re: Re: reading lines
by graff
in thread reading lines
by spill
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |