in reply to Make a hash by a range of keys and values

Several issues:
  1. chomp doesn't return the modified string, it changes the argument in place.
  2. xpoints needs a sigil.
  3. Spaces aren't needed before semicolons.
  4. Numbers don't need double quotes.
  5. The actual number of elements is ($xpoints + 1) * ($ypoints + 1) - 1 because you start at 0, 0.

#! /usr/bin/perl use warnings ; use strict ; print 'Last X Point' , "\n"; chomp( my $xpoints = <STDIN> ); print 'Last Y Point' , "\n"; chomp( my $ypoints = <STDIN> ); my %position; my $key = 'a'; for my $y (0 .. $ypoints) { for my $x (0 .. $xpoints) { $position{$key++} = [$x, $y]; } } for my $key ('a' .. $key) { print "'$key' => [$position{$key}[0],$position{$key}[1]],\n" if $position{$key}; }
Note that the output is different to yours which is missing "j":
'a' => [0,0], 'b' => [1,0], 'c' => [2,0], 'd' => [3,0], 'e' => [0,1], 'f' => [1,1], 'g' => [2,1], 'h' => [3,1], 'i' => [0,2], 'j' => [1,2], 'k' => [2,2], 'l' => [3,2], 'm' => [0,3], 'n' => [1,3], 'o' => [2,3], 'p' => [3,3],

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Make a hash by a range of keys and values
by GHMON (Novice) on Nov 01, 2018 at 13:31 UTC

    TNX BRO :)))))