in reply to Spurious `undefined' values and conversion issues

As an aside note, you could make some of your code look more Perl-ish. For example, instead of C-style "for" loops, you could take advantage of Perl's Range Operator (see perlop) by changing this:
$j=0; for ($j=0;$j<=16381;$j++){ if (defined($counts_rebin[$j])){ next; } else{ $counts_rebin[$j]=0; } }

into this:

for my $j (0..16381) { $counts_rebin[$j] = 0 unless defined $counts_rebin[$j]; }

You could even take things a step further and employ map to initialize the @energy_rebin array by changing this:

for ($i=0; $i<16834; $i++){ $energy_rebin[$i] = ($rebin_width * $i); }

into this:

my @energy_rebin = map { $_ * $rebin_width } (0..16833);

Replies are listed 'Best First'.
Re^2: Spurious `undefined' values and conversion issues
by sf_ashley (Sexton) on May 30, 2008 at 18:54 UTC

    As I am still rather new to programming with perl, I still think in terms of fortran, which I have had a little experience with.

    It is rather overwhelming, in terms of all the commands available, as to what one can do and it doesn't help when I still think very much in a limited sense to the basic commands and building up from there.

    However, the more I see and play with it, the more it will seep in, and your suggestion regarding map is very interesting. I'll have to read around that.

    I suppose, all in all, that at the monent, my handicap in perl golf is a little on the high side!

    Many thanks for your comment

    Steve