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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.