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

Comparing lines in txt.file

by zakishah (Novice)
on Aug 14, 2012 at 23:30 UTC ( [id://987470]=perlquestion: print w/replies, xml ) Need Help??

zakishah has asked for the wisdom of the Perl Monks concerning the following question:

I am new in perl and seeking for code to do my assignment.I want to compare ip adresses in a given traceroute result that is saved in txt file. i want to see if first and third line and 2nd and 4th line have same ip address or not? I shall be thankful for any help. here is txt file

1 10.0.0.106 (10.0.0.106) 0.495 ms 0.400 ms 0.356 ms 2 10.0.0.57 (10.0.0.57) 0.802 ms 0.714 ms 0.720 ms 3 10.0.0.50 (10.0.0.50) 1.130 ms 1.347 ms 1.301 ms 4 10.0.0.133 (10.0.0.133) 1.662 ms 1.694 ms 1.567 ms

Replies are listed 'Best First'.
Re: Comparing lines in txt.file
by Anonymous Monk on Aug 15, 2012 at 01:37 UTC
Re: Comparing lines in txt.file
by Kenosis (Priest) on Aug 15, 2012 at 02:05 UTC

    Please post your data, the code you have tried, and the results of your code's execution (within <code></code> tags), so we can better assist you.

      Well as far as code is concerned i cant make sense of it how to write that is why i seek help here and as far as my data is concerned i have already given in my first question the tracroute result where i have to match ip address in each line. once again trace route table is given below i want to check if ip address of line and the line before previous line are same it should display warning msg that says " routing loop". thanks for help

      1 10.0.0.110 (10.0.0.110) 0.449 ms 0.353 ms 0.385 ms 2 10.0.0.109 (10.0.0.109) 0.367 ms 0.355 ms 0.412 ms 3 10.0.0.110 (10.0.0.110) 0.660 ms 0.669 ms 0.644 ms 4 10.0.0.109 (10.0.0.109) 0.794 ms 0.702 ms 0.665 ms 5 10.0.0.110 (10.0.0.110) 1.113 ms 1.010 ms 0.997 ms 6 10.0.0.109 (10.0.0.109) 1.039 ms 0.997 ms 1.001 ms

        I don't want to be rude, but you said this is for an assignment. If you don't know Perl well enough to even try something that we can help you with, then you probably need to go back to the beginning and start over. If we just give you the solution, that may satisfy your teacher/boss this time, but you'll be even further behind for the next assignment.

        This is a pretty straightforward task: read the lines, parsing out the IP addresses and saving them to a hash, checking to see if they already exist as a hash key and alerting if one does. The parsing could be done with split or a regex (I'd vote for split here). All pretty basic Perl stuff.

        Aaron B.
        Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://987470]
Approved by hominid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-23 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found