in reply to Hash Problem

I would push all value pairs on to an array, and assign them later to the hash:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %keypal; my @line; while(<DATA>) { chomp; push(@line, (split(/,/))[0,1]); } %keypal = @line; print Dumper(\%keypal); __DATA__ 297220,ITEM 207420,NEW
best regards,
neniro

Replies are listed 'Best First'.
Re: Re: Hash Problem
by Wonko the sane (Curate) on Mar 05, 2004 at 23:03 UTC
    I have OCD related to while loops and hash assignments. Also a liking of maps, to an unhealthy level. :P

    I always liked this syntax better for stuff like this.

    %h = map { chomp $_; split( ',', $_, 2 ) } <DATA>; # or %h = map { /^([^,]+)\s*,\s*([^\n\r,]+)/ } <DATA>;

    Wonko

Re: Re: Hash Problem
by Anonymous Monk on Mar 05, 2004 at 21:04 UTC
    Thank you all very much!!
    I found where the problem was based in your answers!!
    Thanks again!!!