agustina_s has asked for the wisdom of the Perl Monks concerning the following question:

Hi perlmonks... thanks so much for your wonderful help... I want to ask concerning the next lines below... This is part of the code:
print " Description "; foreach my $de ($entry->DEs->elements()) { print OUT join ("\n", $de->text()),"\n" ; }
Basically the $entry->DEs->elements() will return an array of gen description and the $de->text() will return each element of the array... The content of the array :Cytotoxin, Cardiotoxin analog,CTX III,Ctx-3,Cardiotoxin C-10 The output of the above code is:
Description Cytotoxin Cardiotoxin analog CTX III Ctx-3 Cardiotoxin C-10
Is there any way to make the second input till the last one in bracket such as :
Description Cytotoxin (Cardiotoxin analog )(CTX III) (Ctx-3)(Cardiotoxin C-10).
Thanks so muchhh.....

Replies are listed 'Best First'.
Re: about () in the second,third etc data
by projekt21 (Friar) on Jan 17, 2002 at 16:23 UTC

    If I understood your question correctly, then try something like:

    my @a = $de->text(); print OUT shift @a, "\n", join("\n", map { "($_)" } @a);

    The shift returns (and removes) the first element, while the map adds those brackets. This is just one possible solution. You also may have a look at printf. Hope this helps.

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

      Assuming theres always more than element then the following allows you to lose the map
      my @a = $de->text(); print OUT shift @a, "\n(", join(")\n(", @a),")\n";
      ;-)

      Yves / DeMerphq
      --
      When to use Prototypes?

Re: about () in the second,third etc data
by goldclaw (Scribe) on Jan 17, 2002 at 16:58 UTC
    Seems to me like you have to grab the return of $de->text() first. Something like this should probably do what you want:
    my @lines=$de->text(); print shift @lines,"\n",map { "( $_ )\n" } @lines;
    The shift grabs the first value, the map puts () around the remaining values, and adds a newline to them all. goldclaw