in reply to Help to improving my code please?
This will give you a hash of arrays:($firstLetter)= ($file_name=~ /^(.)/); push(@{$hash{uc($firstletter)}}, $infoline);
with this loop$hash{'A'} -> [ infolineA1, infolineA2 ... ] $hash{'B'} -> [ infolineB1, infolineB2 ... ]
you can output your lists. Note that I've added a uc() to $firstletter above, giving you just upper case.foreach $letter (sort keys %hash) { print $letter; foreach $infoline (@{$hash{$letter}}) { print $infoline; } }
This might not be the best way to do it, but its at least one way.
|
|---|