douggie305 has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, I just started using perl, and this is my fist attempt and any sort or programming/scripting.
I would like to make a script that takes a file read from standard input then creates 3 arrays out it, the file contains IP addresses and URLs delimited with [] around the period, and after each there is white space followed by a description.
I want to first remove the description. In VI I would use %s/ .*//. to do this I would assume the same regex would work in the script.
Next I want to remove the braces and the period and replace it with just a period again in VI that would be %s/\[.\]/\./g
Then have what remains (just the IPs and URLs with out any braces or descriptions) put into an array that I will do more editing with, I have the last bit of code figured out I've been testing with the original file already having the [] and descriptions removed, Its just that the file's content will change every time I need to run this script so if I could make the script replace as well as the other functions it would save me a lot of time.
I don't have much code because I don't know where to start after I get the text into the script. I would like the new text placed in an array name @list after the braces and descriptions have been removed then I can take parts of that array and add them to 2 others one name @ips and the other @urls kinda self explanatory what my intent is but like I said I don't have the faintest idea where to start. Please help! Thanks in advance for any and all help!
#!/usr/bin/perl use warnings; use strict; foreach my $line (<STDIN>){ chomp $line; #remove extra words and braces. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing and replacing values from an array.
by kennethk (Abbot) on Aug 18, 2014 at 16:00 UTC | |
by douggie305 (Initiate) on Aug 18, 2014 at 16:40 UTC | |
by kennethk (Abbot) on Aug 18, 2014 at 17:14 UTC | |
by Laurent_R (Canon) on Aug 18, 2014 at 17:52 UTC | |
by kennethk (Abbot) on Aug 18, 2014 at 18:34 UTC | |
| |
by douggie305 (Initiate) on Aug 18, 2014 at 17:26 UTC | |
|
Re: Removing and replacing values from an array.
by GotToBTru (Prior) on Aug 18, 2014 at 15:51 UTC |