N
Niall
I am processing some data where normally there are the same number of
tokens in each line but occasionally one value may be missing . In the
attached example there are normally 4 values per line but the second
line has field 3 missing. I think I could use a multiplier
[\s+(\d+)]{0,1} which would work here , but this would not work if the
data in column 4 happened to also be numeric.
I would be grateful for any suggestion as to how the 2 regexes could be
combined if this is possible.
use strict;
use warnings;
while(<DATA>)
{
chomp;
if(/(\S+)\s+(\d+)\s+(\d+)\s+(\w+)/)
{
print ("\nMatch 1 Got[$1][$2][$3][$4]");
}
elsif(/(\S+)\s+(\d+)\s+(\w+)/)
{
print ("\nMatch 2 Got[$1][$2][$3]");
}
else
{
print ("\nNo match");
}
}
################################
__END__
ABC 1233 456 XYZ
ZZZ 66555 JKL
YYY 1717 284 MNOP
tokens in each line but occasionally one value may be missing . In the
attached example there are normally 4 values per line but the second
line has field 3 missing. I think I could use a multiplier
[\s+(\d+)]{0,1} which would work here , but this would not work if the
data in column 4 happened to also be numeric.
I would be grateful for any suggestion as to how the 2 regexes could be
combined if this is possible.
use strict;
use warnings;
while(<DATA>)
{
chomp;
if(/(\S+)\s+(\d+)\s+(\d+)\s+(\w+)/)
{
print ("\nMatch 1 Got[$1][$2][$3][$4]");
}
elsif(/(\S+)\s+(\d+)\s+(\w+)/)
{
print ("\nMatch 2 Got[$1][$2][$3]");
}
else
{
print ("\nNo match");
}
}
################################
__END__
ABC 1233 456 XYZ
ZZZ 66555 JKL
YYY 1717 284 MNOP