in reply to Multiple Transformations with "map"

map returns the value of the last expression evaluated within { #block }. The last expression you're evaluating is a substitution operator, and its value is a boolean value; true (1) if a match occurred, or false if there was no match. That's why it keeps passing '1' into @nar. If you want to return the result of the substitution, make sure that value is the last thing evaluated in { #block }.

@nar = map { # get rid of trailing number my $st = ( split( " ", $_ ) )[0]; # replace bracket with S $st =~ s/\[[ATCG]+\/S/g; # return result value $st; } @arr;

...that ought to do it...


Dave

Replies are listed 'Best First'.
Re^2: Multiple Transformations with "map"
by sauoq (Abbot) on Nov 26, 2005 at 13:06 UTC
    The last expression you're evaluating is a substitution operator, and its value is a boolean value; true (1) if a match occurred, or false if there was no match.

    If a match occurs, the substitution operator returns the number of substitutions made, not simply 1 (unless that happens to be the number of substitutions made... as in this case.)

    -sauoq
    "My two cents aren't worth a dime.";