in reply to Re: Assign result of map to scalar variable
in thread Assign result of map to scalar variable
$VAL = join '', map { /^\*\s\(?([^\)]+)\)?/ ? $1 : '' } @GET_STRING;
It's not clear to me from the OP, but I'm assuming the @GET_STRING array may contain any number of matching or non-matching strings in any order. If this is so, a join solution such as you have would not work:
>perl -wMstrict -le "my @GET_STRING = ('no', '*nine', '*(not)', '* yes', '* (yup)', '* ya)'); ;; my $VAL = join '', map { /^\*\s\(?([^\)]+)\)?/ ? $1 : '' }@GET_STRING +; print qq{'$VAL'}; " 'yesyupya'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Assign result of map to scalar variable
by hdb (Monsignor) on Jul 19, 2013 at 07:22 UTC | |
by AnomalousMonk (Archbishop) on Jul 19, 2013 at 09:31 UTC | |
by hdb (Monsignor) on Jul 19, 2013 at 09:45 UTC |