Assuming you are only concerned with repeated numbers in consecutive lines, then something like this would do (untested):
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;
}
======
Thought #1:
In your example the lines are sorted by the 2-digit number. If that is typical, then at the most you're only going to have to process 100 lines from the huge files.
Is that what you expect?
======
Thought #2:
Q: What are you supposed to do if you get repeated numbers, but in non-consecutive lines like below?
AB000000026JHAHKDFK
AB00000003033AFSFAS = "30" line
AB000000028JHKHKHKJ
AB000000030HJHKH80J = "30" line
AB0000000324446KJHK
AB000000030LOIKJUJ8 = "30" line
UPDATE:
Replaced:
foreach my $line ( <FILE> ) #### do NOT read entire files into memory if they are big. Much better to process them a line at a time
with
while ( my $line = <FILE> ) #### do NOT read entire files into memory if they are big. Much better to process them a line at a time
Embarassing bug that! In my defence the original code had 'foreach' and I probably just missed it.
Had I written the code from scratch I would (I hope!) have used 'while'. I'm still an idiot though! :)
Thanks very much to Not_a_Number for pointing this out!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.