in reply to 'split'-ting headache

You very likely have 'empty' columns in your data which get eaten up by your \s+ match.

@array = split (/ /, $line);
Should work, if you don't have spaces in your data. (remember that split(/ /) is different from split() or split(" ") - read perldoc -f split )

Update: this code assumes you have exactly one space between columns, adjust as needed.

-- Joost downtime n. The period during which a system is error-free and immune from user input.

Replies are listed 'Best First'.
Re: Re: 'split'-ting headache
by Anonymous Monk on Jun 11, 2002 at 14:39 UTC
    unfortunately i do have spaces (which vary in length) in my data so that wont work Joost. the output i am expecting is just to select certain numbers from elements if they pass a certain criteria e.g if $array[[0]] > 95 && $array[8] =~ /hello/
      Then what you need to do is inspect your data. I was working on similar problem recently and finally noticed that i had a few records with trailing leading* space - that is, a space or two before any data. Use Data::Dumper to inspect your arrays (and use strict!):
      use strict; use Data::Dumper; while (my $line = <FILE>) { chomp ($line); #$line =~ s/^\s*//; my @array = split(/\s+/,$line,16); print Dumper \@array; }
      Also, notice that i used the third argument for split - LIMIT. Since you know that you need 16 elements, explicitly let Perl know. If you do find that trailing space is the culprit, you can uncomment the commented line from above.

      Good luck!

      * thanks particle ;)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)