Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Basic help with mapping

by sk (Curate)
on Nov 22, 2005 at 04:29 UTC ( #510634=note: print w/ replies, xml ) Need Help??


in reply to Basic help with mapping

Am i missing something? Your second map logic works fine (modified space to -) if i understand the problem

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $AoH_orig = [ { 'title' => 'aaa-aaa', 'name' => 'tom' }, { 'title' => 'bbb-bbb', 'name' => 'kathy' }, { 'title' => 'ccc-ccc', 'name' => 'bill' } ]; #try mapping print Dumper ($AoH_orig); my $AoH_new = map { $_->{'title'} =~ s/-/_/g } @$AoH_orig; print Dumper($AoH_orig);

$VAR1 = [ { 'name' => 'tom', 'title' => 'aaa-aaa' }, { 'name' => 'kathy', 'title' => 'bbb-bbb' }, { 'name' => 'bill', 'title' => 'ccc-ccc' } ]; $VAR1 = [ { 'name' => 'tom', 'title' => 'aaa_aaa' }, { 'name' => 'kathy', 'title' => 'bbb_bbb' }, { 'name' => 'bill', 'title' => 'ccc_ccc' } ];

All dashes (-) are replaced with underscore (_) isn't that what you are trying?

I probably will not use map for this as you are not returning a list back. I would stick with your for for idea.

 $_->{'title'} =~ s/-/_/g for(@$AoH_orig); should work just fine (i think)

cheers

SK


Comment on Re: Basic help with mapping
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (15)
As of 2014-10-21 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls