On Mon, Jul 21, 2014 at 04:01:05PM -0600, Sherman Willden wrote:
<snip>
>
> I have several files and I attached one of them. I want to sort the file
> and remove duplicate lines. The file is a list of key phrases to search the
> internet for. These are long lines so I don't know if this will work. I
> would like the file to be generic. Is my logic below correct?
>
> Check perl file for two inputs: <file-to-be-read-from> <file-to-write-to>
> Create array which will end up with all non-duplcate lines
> Open <file-to-be-read-from>
> Read in <file-to-be-read-from>
> Search the array
> If the line read in is not in the array, place it in the array
> Close <file-to-be-read-from>
> Open <file-to-write-to>
> For each line in the array, write that line to <file-to-write-to>
> Close <file-to-write-to>
> Sort <file-to-write-to>
>
<snip>

Rather than scanning an array again and again assign each line as the
key to a hash which will automatically delete the duplicates then
assign the keys to an array and sort it before writing out to a file.

If you're working in a 'Nix system just use 'sort | uniq' which will
give you what you want much more quiclky.

Cheers,
Mike
--
"Be humble, and act wisely."
    - Jeralean Talley, America's oldest living woman

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to