perl script help

Hi all,

I have a text file which contain space details of oracle Table space in following format.

text file name say: indexlog.txt ****NOTE*** column has multiple space in between*******
--
MCDX 9859393 5678923 3700 12
MCDDXY 78934 34589 3500 23
MCDX_Q1 4589244 456788 3900 45
MCDX_Q2 7601113 4589002 3802 34
MCDDXY_Q1 562004 590022 3400 43
MCDXY_Q2 23012 2202 3900 80

I want to write a perl script to get all the value of record in the following ways -

index-log.pl
-----------

open(FH,"indexlog.txt") || die "could not able to open the file : $!";
while(defined(my $line = <FH>))
{
my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = $line=~/^(\w+) \s+ (\d+) \s+ (\d+) \s+ (\d+)$/;
print $tbl_spc,$max_size,"\n";
}

close(FH);

i want to write a regular expression that could read all the column and assign each to variable -- so that i can format it in my own way .

Please suggest what is wrong with this code --as it is not able to assign the column value to the variable at left hand.

when i tried some thing like

$tbl_name = $line=~/^(\w+) (\s+)/; in the script

it is reading the table name into variable.

Thanks
Jam

you have a lot of extra spaces in your regex

$line=~/^(\w+)_\s+_(\d+)_\s+_(\d+)_\s+_(\d+)$/;

why not ..

my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = split(/\s+/, $line);

Hi HPAVC,

That is good idea and it worked.
But the way i tried :even removing the space as you noticed above .still not giving me the proper data ,Can you please suggest me the exact regx to get those kind of data ?

Any way thanks for input.

you only have three \d+'s and your data requires four if you keep the $ there.

#!/usr/bin/perl                                                                                                              

use strict;
use warnings;

open(FH,"indexlog.txt") || die "could not able to open the file : $!";

while(defined(my $line = <FH>))
{   
    #                                                                                               1         2         3           4          5
    my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = $line =~ m/^(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/;
    #my ($tbl_spc,$max_size,$free_size,$max_block,$pctfree) = $line=~/^(\w+) \s+ (\d+) \s+ (\d+) \s+ (\d+)$/;
    print $tbl_spc,$max_size,"\n";
}

close(FH);