On Aug 9, 2005, at 6:20, Vema Venkata wrote:

sub get_work_station_id {
    # return W0010A40C06D0 from vbop-0x4E580000:W0010A40C06D0:windows
    my $id = shift;
    return $1 if $id =~ /:([^:]+):/;
    return;
}


[snip]


Can you help me how to get with prefixed letter respectively


Change the body of the subroutine with:

    my $id = shift;
    my ($machine, $prefix) = $id =~ /:(([^:])[^:]*):/;
    return $machine, $prefix;

and use it like this:

    my ($machine, $prefix) = get_work_station_id($id);
    if (defined $machine && defined $prefix) {
        # process them
    }

The regexp above is not very readable, maybe this would be enough:

    my ($machine, $prefix) = $id =~ /:((.).*?):/;

or this

    my ($machine, $prefix) = $id =~ /:((\w)\w*):/;

-- fxn



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to