C
clearguy02
Hi all,
Below is the scenario:
I have a file (c:\test.txt) with the below lines:
===============================
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
================================
The logic is that if the same name has two or more different numeric
values (example: JSMITH has 2002.05.00 and 2003.06.10), you need to
skip those lines.
So, output file should be as follows:
==================================
BBRAND 2002.05.00
MSUBBA 2003.06.10
JPORTER 2003.06.10
=================================
So, how can I get the above output from the above input file?
Below is my stupid piece of code which doesn't work:
====================================
while (<DATA>)
{
($name, $version) = split (/\s+/, $_);
next if (($name =~ /$version/) && ($name !~ /$version/));
print $_;
}
__DATA__
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
===================================
I guess using hashes is a way to go. Can some one suggest me how I can
use hashes in this case?
Thanks,
Rider.
Below is the scenario:
I have a file (c:\test.txt) with the below lines:
===============================
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
================================
The logic is that if the same name has two or more different numeric
values (example: JSMITH has 2002.05.00 and 2003.06.10), you need to
skip those lines.
So, output file should be as follows:
==================================
BBRAND 2002.05.00
MSUBBA 2003.06.10
JPORTER 2003.06.10
=================================
So, how can I get the above output from the above input file?
Below is my stupid piece of code which doesn't work:
====================================
while (<DATA>)
{
($name, $version) = split (/\s+/, $_);
next if (($name =~ /$version/) && ($name !~ /$version/));
print $_;
}
__DATA__
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
===================================
I guess using hashes is a way to go. Can some one suggest me how I can
use hashes in this case?
Thanks,
Rider.