in reply to How to find start position of each column

So i need to know position (in the line) of each column.

There are various ways to understand your question. For example, it could mean that there are column markers like "<C>" (literally) in the first/header row, and you want to find where they occur on that line.  In that case, you could do something like

my $firstrow = "<S> <C> <C> + <C> <C> <C> <C> <C> <C> <C> <C +> <C>"; my @columnpos; while ($firstrow =~ /(<\w>)/g) { push @columnpos, pos($firstrow) - length($1); } print "positions: @columnpos\n"; __END__ positions: 0 30 47 57 68 78 82 88 101 111 121 128

Replies are listed 'Best First'.
Re^2: How to find start position of each column
by johngg (Canon) on May 28, 2008 at 14:04 UTC
    while ($firstrow =~ /(<\w>)/g) { push @columnpos, pos($firstrow) - length($1); }

    You could use a look-ahead to avoid doing the capture, length and subtraction.

    push @columnpos, pos $firstrow while $firstrow =~ m{(?=<\w>)}g;

    I hope this is of interest.

    Cheers,

    JohnGG