in reply to Re: Regexp help
in thread Regexp help

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