in reply to problems with arrays
Well, there are some possible points of confusion. Your snippet of code doesn't show what you do with @array after the while loop; that suggest me that you could be reading the file, modifying each line and then throwing away the modified line. Anyway, I'll try to work on the snippet.
On the first iteration, @array contains nothing (since you commented the assignment @array = () ;), so the subsequent foreach won't run, and if $line contains a leading whitespace, it won't catch it.
Your code could be patched by using the peculiarities of split when working on $_, like this
But if preserving the value of $_ it is vital for you, you could change it slightly this way:while (<FH>) { chomp ; @array = split ; # do something with @array }
while (<FH>) { $line = $_ ; chomp $line ; $line =~ s/^\s// ; # delete leading whitespace, if any @array = split /\s+/,$line ; # do something with @array; $_ is preserved so you # can use it again }
That's all I could do with the information you sent ;-). If these solutions don't fit, just ask specifying better.
--bronto
PS: ...and if you need more information on the behaviour of split with no arguments, there is no better source than perldoc -f split;-)
|
|---|