http://www.perlmonks.org?node_id=1013763


in reply to Need help in parsing an input

sandeepda:

Parsing the strings ought to be easy. It prefaces the interesting data with a bar of hyphens, and the name, IP and port ought not have whitespace. So you can simply read and discard lines until you find the line of hyphens. After that, you can use a simple split to break out the individual fields:

while (my $line = <$FH>) { next if $line =~ /^-----/; my ($name, $ip, $port) = split /\s+/, $line; print "Name: $name, IP: $ip, Port: $port\n"; }

Other alternatives include using substr or unpack for breaking up lines with fixed-length fields.

...roboticus

When your only tool is a hammer, all problems look like your thumb.