Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Need help in parsing an input

by roboticus (Chancellor)
on Jan 17, 2013 at 11:46 UTC ( #1013763=note: print w/replies, xml ) Need Help??

in reply to Need help in parsing an input


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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013763]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2016-10-24 13:42 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (306 votes). Check out past polls.