I keep squinting at your code and wondering how it is that you could say it works. If I give it a seven element array, it returns a hash with six elements. None of the values actually correspond directly to a set of numbers that directly resembles the input string. Take the following example I gathered using your code.

use 5.012.02; use strict; use warnings; my %base_stat; my @temp_array; my $basecount; my @string; my @string_array = qw/this that and all manner of other/; my $pos; my $pos_score; foreach (@string_array){ @string=split(//,$_); $basecount=0; foreach $pos (@string){ $basecount++; $pos_score=ord($pos)-33; @temp_array=$base_stat{$basecount}; # line 124 push (@temp_array,$pos_score); $base_stat{$basecount}="@temp_array"; } } say "\%base_stat contains:"; foreach my $key ( sort keys %base_stat ) { say "$key => $base_stat{$key}"; }

And the output:

Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. Use of uninitialized value $temp_array[0] in join or string at test.pl + line 26. %base_stat contains: 1 => 83 83 64 64 76 78 78 2 => 71 71 77 75 64 69 83 3 => 72 64 67 75 77 71 4 => 82 83 77 68 5 => 68 81 6 => 81

Is that really what you want? Look at how poorly the output corresponds to the input strings. There's not a direct 1:1 correlation of string characters to values on a per-input-line basis. If all you want is a set of values corresponding to an array of input strings, how about this?

use 5.012.02; use strict; use warnings; my @input_string_array = qw/this that and all manner of other/; my @output_array; foreach my $string ( @input_string_array ) { push @output_array, join " ", map { ord($_) - 33 } split //, $stri +ng; } say $_ for @output_array;

Or if you really need a hash that is indexed like an array but starting with an index of '1', (all of which seems silly to me, but you might have your reasons), you could do it like this:

use 5.012.02; use strict; use warnings; my @input_string_array = qw/this that and all manner of other/; my %output_hash; foreach my $iterator ( 0 .. $#input_string_array ) { $output_hash{ $iterator + 1 } = join " ", map { ord($_) - 33 } spl +it //, $input_string_array[$iterator]; } foreach my $key ( sort keys %output_hash ) { say "$key => $output_hash{$key}"; }

Dave


In reply to Re: Why is it uninitialized? by davido
in thread Why is it uninitialized? by yehudithasin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.