in reply to Regexp help

A regular expression isn't necessary. How about just using split with a ':' delimiter, then taking the second array element of the result?

main::(-e:1): 1 DB<1> $str = "R4:abcxyz45:LNX" DB<2> @words = split(':',$str) DB<3> x $words[1] 0 'abcxyz45'

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: Regexp help
by Marshall (Canon) on Sep 03, 2010 at 19:48 UTC
    To just get one item, use list slice.

    A very handy technique. Note that the order of the vars on the left don't have to be in the same order that they are in the input string (the indicies to the slice can be in any order).

    I usually order the vars on the left to be in the order that they will be used in the code that follows the split. I fiddle with the indices on the right to make that possible. Also here I used a -1 instead of 2 just to show that is possible (-1 means the last thing in list)

    Oh, PS, yes it is possible to write a single char like ':' to use in the split instead of /:/, but I always use the regex form.

    #!/usr/bin/perl -w use strict; my $x = 'R4:abcxyz45:LNX'; my $server = (split(/:/,$x))[1]; print "$server\n"; #prints abcxyz45 (my $OS, $server) = (split(/:/,$x))[-1,1]; print "$OS $server\n"; #prints LNX abcxyz45
Re^2: Regexp help
by jwkrahn (Abbot) on Sep 03, 2010 at 17:51 UTC

    A regular expression is necessary because the first argument to split is a regular expression.