in reply to Re: extracting names between symbols
in thread extracting names between symbols

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.

Replies are listed 'Best First'.
Re^3: extracting names between symbols
by Marshall (Canon) on Nov 18, 2009 at 02:55 UTC
    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