in reply to Removing duplicates lines
use strict; #### Always have these lines. use warnings; #### They will save you lots of time debugging use DBI; use Time::localtime; use File::Compare; use XML::Simple; # qw(:strict); use Data::Dumper; my $user = "213256"; my @filesToProcess = glob "/export/home/$user/Tests/Match/dummy2*"; + #### Need ""s. ''s do not do variable interpolation foreach my $file (@filesToProcess) { open(FILE, $file) or die "Can't open `$file': $!"; my $prev_var = -1_000_000; #### set this to a value that wil +l never appear as the numbers you need to check. #### (Obviously the 2-digit numbe +rs must be in the range 0 to 99) while ( my $line = <FILE> ) #### do NOT read entire files int +o memory if they are big. Much better to process them a line at a ti +me { chomp $line; my $var = substr($line, 10, 2); #### Do you mean substr($line, + 9 , 2)? substr() consders the first character to be at offset zer +o if ($var != $prev_var) #### if number is different to nu +mber in previous line, then process it { $prev_var = $var; ... process $line here .... } } close FILE; }
AB000000026JHAHKDFK AB00000003033AFSFAS = "30" line AB000000028JHKHKHKJ AB000000030HJHKH80J = "30" line AB0000000324446KJHK AB000000030LOIKJUJ8 = "30" line
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing duplicates lines
by Not_a_Number (Prior) on Sep 04, 2013 at 20:15 UTC | |
by zork42 (Monk) on Sep 05, 2013 at 12:01 UTC | |
|
Re^2: Removing duplicates lines
by vihar (Acolyte) on Sep 04, 2013 at 20:33 UTC |