You don't show us what not's working. Just from glancing at the code you show, it looks like you will, in fact, build the data structure you describe (an array of references to arrays with strings in them). Note that the last fields in your arrays will have newlines; you don't say whether that's a problem (
chomp is the usual way to deal with this).
You also don't say why you're building the whole data structure in memory before doing the search (are you?) rather than searching on the fly as the data comes in. But assuming that's what you have to do for some reason, you can just iterate through your array:
for my $a (@foo)
{
if ($a->[0] eq 'bill')
{
$a->[1] += 3; # add 3 to second field
$a->[2] .= "!"; # add ! to third field
}
}
No reason to replace the array, as you've already replaced the values in it. That is, unless you have references to it elsewhere, in which case you could copy it:
for my $i (0 .. $#foo)
{
my $a = $foo[$i];
if ($a->[0] eq 'bill')
{
my $b = [ @$a ]; # copy a's data to b
$b->[1] += 3; # add 3 to second field
$b->[2] .= "!"; # add ! to third field
$foo[$i] = $b;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.