Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Need help in parsing an input

by roboticus (Canon)
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

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.


Comment on Re: Need help in parsing an input
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-07-29 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (213 votes), past polls