On Dec 17, 3:22 am, [EMAIL PROTECTED] (Pauld) wrote: > my $var=0;my [EMAIL PROTECTED]; > while ($var<$va_length) > { > print "${$daylistsorted[$var]}{TH} "; > print 'from '; > print ${$daylistsorted[$var]}{START}; > print ' to '.${$daylistsorted[$var]}{END_DS}; > print " duration ";print int((${$daylistsorted[$var]}{END}-$ > {$daylistsorted[$var]}{START})/60);
It's unusual in Perl to need to access an array element by its index number. This is one of those times, though, when it is useful to use an index because you need to peek ahead at the next item in the array. But you only need the index for the next item, not for the current item, so you can clean up things a bit with something like this (untested, and posted without much effort to parse or understand the objective of the code, and using printf instead of a bunch of concat'ed strings): my $index = 0; foreach my $day( @daylistsorted ) { printf ( "%s from $s to %s duration %s %s\n", $day{'TH'}, UnixDate($day{'START'}, '%Y:%m:%d %H:%M'), UnixDate($day{'END_DS'}, '%Y:%m:%d %H:%M'), int(($day{END} - $day{START})/60); (exists( ${$daylistsorted[$index+1]}{TH} ) ) ? "\tinterval to next start " .int (( ${$daylistsorted[$index+1]}{START} -$day{END} )/60) : '' ); $index++; } -- The best way to get a good answer is to ask a good question. David Filmer (http://DavidFilmer.com) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/