in reply to Removing and replacing values from an array.
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 likeIP URL Desc IP URL Desc IP URL Desc IP URL Desc
or even bettermy @array = split /\s+/, $line, 3;
You then want to clean up the IP and URL, so maybemy ($ip, $url, $desc) = split /\s+/, $line, 3;
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:$ip =~ s/\[\.\]/./g ; $url =~ s/\[\.\]/./g ;
This should give you a good starting point. Let me know how things progress.push @ips, $ip; push @urls, $url; push @list, $stuff_you_processed;
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing and replacing values from an array.
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 Laurent_R (Canon) on Aug 18, 2014 at 18:55 UTC | |
by douggie305 (Initiate) on Aug 18, 2014 at 17:26 UTC |