>>>>> "VW" == Vaughan Williams <vaughan...@gmail.com> writes:
VW> Hi all, VW> I'm hope you all could help me with a very simple question. VW> I have a multi line text file laid out as below. VW> 10.10.10.45 bobs VW> 10.10.10.34 jims VW> 10.10.10.27 jacks VW> ..... VW> ..... VW> I would like to that the 10.10.10.??? and move it to the end of the same VW> line so the output will look like. VW> bobs 10.10.10.45 VW> jims 10.10.10.34 VW> jacks 10.10.10.27 ok, that is a simple enough problem. what have you tried so far? i could quickly write a one liner but that wouldn't teach you much. this list is about learning perl, not getting programs (however simple) written for you. so i will walk through the ideas needed and you should be able to code them up. first off you need to read in the file. this can be done line by line or as the whole file if it is small enough (and small is megabytes these days). given this is some form of hosts file (a good guess) it will be small enough. so write code to read it in and loop over each line. the next step is to flip the fields. this can be done many different ways. you first need to get the 2 parts and then recombine them in the other order. split or a regex will get the parts for you. either is easy enough to code up even for a newbie but split would be simpler i think. then combining those 2 parts back into a line is very easy and can be done with a simple "" string. the final step is just printing out the lines. you can print them to stdout (default for print) and save the output into a file with a shell redirect (>). or you could open the file in perl (before the loop!) and print each line to that. again, this is easy perl. so each step is very easy. do them all and you will have a working perl program that does what you want. if you get stuck, write back to the list and show the code and explain your problem. thanx, uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/