On Oct 18, Vladimir Lemberg said:
>John Creamer: 123 345 123 678 345
>Erick Morillo: 123 432 876 123 432
>Cris Fortier: 678 123 987 123 345
>
>I need to remove duplicated numbers from each line. The output file would be:
>
>John Creamer: 123 345 678
>Erick Morillo: 123 432 876
>Cris Fortier: 678 123 987 345
>foreach (<INFILE>){
> @temp = split/:/;
> print OUTFILE "\n$temp[0]:";
> @numbers = split(/\s+/, $temp[1]);
You should be declaring your variables with 'my', and writing your code to
be 'strict' compliant. If you do that, and then include
my %freq;
you'll be ok.
If not, just include:
%freq = ();
before the foreach loop below:
> foreach $number (@numbers){
> $freq{$number}++;
> print OUTFILE $number if $freq{$number}==1;
> }
>
>}
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>