Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: hash of arrays

by spazm (Monk)
on Oct 26, 2011 at 09:32 UTC ( #933836=note: print w/replies, xml ) Need Help??


in reply to Re^2: hash of arrays
in thread hash of arrays

what output do you get if you change your print loop to
foreach my $key ( keys %hash ) { #print "$key: @{ $hash{$key} }\n" print "$key: \n"; foreach (@{$hash{$key}}) { print $_ , "\n"; } }
Does each line get printed correctly, or are the lines garbled as in your old output?

Replies are listed 'Best First'.
Re^4: hash of arrays
by Anonymous Monk on Oct 26, 2011 at 09:45 UTC
    Now the output is correct but when I want to use a loop as this:
    foreach my $key ( keys %hash ) { #print "$key: @{ $hash{$key} }\n" #print "$key: \n"; for my $i (1..$#{$hash{$key}}) { print $hash{$key}[0],"\t" ,$hash{$key}[$i], "\n"; } }
    the output would be again corrupted as:
    A bird iA bird is bathing in a sink. the running water from a faucet. A bird iA bird is splashing around under a running faucet.m a faucet. A bird iA bird is bathing in a sink. the running water from a faucet. A bird iA bird is standing in a sink drinking water that is pouring ou +t of the facet. A bird iA faucet is running while a bird stands in the sink below.et. A bird iA bird is playing in a sink with running water.from a faucet. A bird iA bird is playing in tap water.e running water from a faucet. A bird iA bird is bathing in the sink.he running water from a faucet. A bird iA bird is taking a bath.nder the running water from a faucet.
      Try downloading the data you uploaded here. Sounds like you may have embedded escape characters like control-M in your data input file.

      We are running with the 7bit clean data provided in the "download" link of your original sample.

        Thanks the problem solved by adding this after the chomp.
        s/\r//g;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://933836]
help
Chatterbox?
Discipulus played the guitar in a ska band 12 elemnts, very fun
[LanX]: well ... the prize for worshipping satan is high ...
[Discipulus]: you value too much your soul LanX
[Eily]: LanX: you mean people end up losing their health insurance?
LanX could be a reference to Trump and/or Brexit ...
[LanX]: ... anyway getting a support call from food! Need to respond ... ;-)
LanX see you later

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2017-03-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.