Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: how to use join my array ?

by rnewsham (Curate)
on May 01, 2014 at 10:24 UTC ( #1084600=note: print w/replies, xml ) Need Help??


in reply to how to use join my array ?

It is not clear exactly what you are trying to achieve. It looks like you want to create an array @ab that contains just the keys from the hash %abc, each with a hypen prepended.

use strict; use warnings; my %abc = ( to => 'def', from => 'ghi', ); my @ab; for ( keys %abc ) { push @ab, "-$_"; } print "$_\n" for @ab; #Output -to -from

Will do that, or you can use map to do the same thing.

use strict; use warnings; my %abc = ( to => 'def', from => 'ghi', ); my @ab = map { "-$_" } keys %abc; print "$_\n" for @ab;

As doing this disconnects the modified keys from their previously associated values, I guess this is not really what you want. I think it is more likely that you want to just modify the keys in the hash, or more simply create a new hash with the modified keys.

my %ab = map { '-' .$_ => $abc{$_} } keys %abc;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1084600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2020-11-27 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?