in reply to Re: Splitting a hash
in thread Splitting a hash

++++ for you!!! Thanks so much, that definatley did the trick. Why was my snippet ignoring the data?

"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re^3: Splitting a hash
by tall_man (Parson) on Mar 11, 2003 at 05:11 UTC
    Why was my snippet ignoring the data?

    The data that you wanted (the separated fields) were in the variables you split them to. You ignored them, perhaps expecting the values within the hash itself to become split. But the original values remained as they were, because split returns a new array of values. It doesn't affect the original.

      Thanks for your help. I was actually expecting the variables to be defined and used when used in a split. That does make sense now that I think about it. I made new variables ($address1, $address2...) but I only asked to print the hash $dbm{$_} leaving the only part I was looking for in the dust.

      Again, thanks for your help, I really appreciate it.

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
Re: Re: Re: Splitting a hash
by greenFox (Vicar) on Mar 11, 2003 at 05:26 UTC

    Why was my snippet ignoring the data?

    Well let's examine your snippet:
    my ($number, $email, $address1, $address2) = split "\0", $dbm{$name}; foreach (sort keys(%dbm)) { print "$dbm{$_}\n"; }

    Your first line does a split on null characters of the hash record with a key of $name, the result is returned to several variables which aren't used again in the snippet. Then you loop around the hash, by key, and print the values.

    dws's example put the split inside the loop and then prints out the values split returned.

    --
    Life is a tale told by an idiot -- full of sound and fury, signifying nothing. William Shakespeare, Macbeth