in reply to extracting names between symbols

Sample data please.

Here is code based on my assumptions of what you need:

my $transcript=q|tom t-Dick -Harry|; my @analysts= $transcript=~/([^-]+)-?/g; print qq|=$_=\n| for @analysts;
Output:
=tom t= =Dick = =Harry=
The RE can be tightentd to ignore leading/trailing spaces.:
my @a= $transcript=~/\s*([^-]+\w)\s*-?/g
This deletes the space after =Dick.

     Theory is when you know something, but it doesn't work.
    Practice is when something works, but you don't know why it works.
    Programmers combine Theory and Practice: Nothing works and they don't know why.         -Anonymous

Replies are listed 'Best First'.
Re^2: extracting names between symbols
by aka_bk (Novice) on Nov 18, 2009 at 02:07 UTC

    Thanks to both of you. Sorry for not presenting all the necessary infos. The second solution is perfect, because i need an array to work further with.

      Glad to hear that you can proceed further!

      The solution from NetWallah looks fine to me.

      I added a line to make it clear that the foreach() in my code does use an @variable. And I showed the idioms for deleting whitespace before and after a "line". Anyway, very happy that you can proceed further!

      #!/usr/bin/perl -w use strict; my $line = "this- is-aline - one- two "; my @array = split (/-/,$line); foreach (@array) { s/\s+$//g; #throw away tailing whitespace s/^\s+//g; #throw away leading whitespace print "$_\n"; } __END__ PRINTS: this is aline one two

        If you change the split regex to allow optional spaces around the hyphen and prepend and append hyphens to the text you can avoid the space trimming substitutions. You do have to shift away the empty first element though.

        $ perl -le ' > $str = q{ this- is-aline - one- two }; > @arr = split m{\s*-\s*}, qq{-$str-}; > shift @arr; > print qq{->$_<-} for @arr;' ->this<- ->is<- ->aline<- ->one<- ->two<- $

        I hope this is of interest.

        Cheers,

        JohnGG