in reply to Perl and Excel

you might change this:
if (/\S+/){ . . .}
to something that matches what will exist in the cell. So instead of checking to see if it has at least non-space character, you can check to make sure it has one of whatever character might be in there. If you are dealing strictly with numbers:
if (/[0-9]/){ ... }
would work. or if dealing with numbers and letters and an underscore:
if (/[\w]/) {...}
On another note the + is ambiguous as it will only be true if there is at least one of whatever character you are matching anyway.

update: much to my chagrin. Yes \d is the same as [0-9] and the brackets are not necessary with \w or the \d for that matter. Thank you anonymous monk.

-enlil

Replies are listed 'Best First'.
Re: Re: Perl and Excel
by Anonymous Monk on Jan 13, 2003 at 21:45 UTC
    [0-9] is the same as \d [\w] the brackets arent necesary, use just \w instead
Re: Re: Perl and Excel
by Anonymous Monk on Jan 13, 2003 at 23:00 UTC
    Many thanks for your help guys, unfortunately the problem remains. I tried the \w character, and with and without +. Curiouser and curiouser.
      Eureka! I have since found the problem is due to the fact that  @hsbcdataread = $sheets[1]->next_row is returning an array of less than the expected size of 6 columns. For some reason, sometimes it returns six columns where one is empty, and other times it just returns 5 columns instead, meaning that the foreach loop is not always entered into for the sixth column in my Excel spreadsheet. A quick and messy if statement has solved this problem. As is often the case, the problem was not what it initially appeared to be. Many thanks to those who contributed. New Code:
      while ($sheets[1]->has_data) { @hsbcdata = (); @hsbcdataread = $sheets[1]->next_row; $size = @hsbcdataread; if ($size < 6) { $hsbcdataread[5] = "X"; } foreach $_ (@hsbcdataread) { s/^\s*//; s/\s*\r*$//; chomp ($_); if (/\S+/) { push (@hsbcdata, $_); } else { push (@hsbcdata, "X"); } } . . }