Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Removing and replacing values from an array.by kennethk (Abbot) |
on Aug 18, 2014 at 16:00 UTC ( [id://1097870]=note: print w/replies, xml ) | Need Help?? |
Hi douggie305. Welcome to the monastery.
What are you using as your template for learning Perl? There are a number of great resources out there, e.g. perlintro, Tutorials, course notes offered by Perl Training Australia. As you seem to know regular expressions from VI, you should find the information in perlretut a straightforward guide to Perl's particulars. In posting, it's also particularly helpful to provide an explicit input and and explicit output, wrapped in code tags. It removes ambiguity associated with wordy descriptions. See How do I post a question effectively?. I'm guessing you file looks vaguely like where the IPs look like 1[.]1[.]1[.]1 and the URLs look like url[.]com. The first natural step here would be split, where, since your description may contain whitespace, you will want to use the split /PATTERN/,EXPR,LIMIT syntax. That line might look like or even better You then want to clean up the IP and URL, so maybe Note the subtle change in the regular expression from what you've proposed. You next step will depend on whether you just want a streaming parser, at which time you could just output, or if you actually want to store them for later use. Assuming you want to store them, you'd insert a declaration for 3 arrays outside your loop (my (@ips, @urls, @list);) and then push the new values onto the arrays: This should give you a good starting point. Let me know how things progress. #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In Section
Seekers of Perl Wisdom
|
|