On Sat, 14 May 2005 14:12:37 +0800, Aditi Gupta <[EMAIL PROTECTED]>
wrote:
hi everybody,
Hi,
is it possible to search for a pattern in each column of a file. I've
only
This may not exactly what you want.
But hopefully it can give you some ideas.
The idea is to get all those column in to
a hash of array, and then process each hash according
to your desired regex.
The code below prints:
$VAR1 = {
'0' => [
'AB', # your columnwise data
EF
],
'1' => [
'BC',
'FG'
],
'2' => [
'CD',
'GH',
]
};
which gives column (of the size 2) wise extraction
of the data.
__BEGIN__
use Data::Dumper;
my %hash;
my $sub_length = 2;
while (<DATA>) {
chomp;
for my $j (0 .. length - $sub_length)
{
push @{$hash{$j}}, substr $_, $j, $sub_length;
}
}
print Dumper \%hash;
foreach my $hkey (keys %hash)
{
foreach my $i ( 0 .. $#{ $hash{$hkey} } )
{
print "$hash{$hkey}[$i]";
# or do some regex with it
}
}
__DATA__
ABDC
EFGH
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>