Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-09-23 08:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found