nidhi has asked for the wisdom of the Perl Monks concerning the following question:

Hello peer monks. Some of the lines from the config line and searching for pattern-matching usinf perl are :
description c3560-a68.mud g6/20-g7/2 or description c3560-a68.mud :::Leaf::: or description c3560-a68.mud blah blah
I need to extract only "c3560-a68.mud" from this line. What i am using right now is :
my ($key) = /description\s+(.*)/;
this is getting me everything after description.
Can someone suggest what changes do i make to the regex to stop the search immed. after c3560-a68.mud. I have several other lines in the config file with similar names.
Thanks

Replies are listed 'Best First'.
Re: remove extra spaces/characters after a given result is found
by GrandFather (Saint) on Aug 28, 2007 at 00:05 UTC

    See perlretut and perlre.

    use strict; use warnings; while (<DATA>) { chomp; next unless /description\s+ ([^\s]+)/x; print "$1\n"; } __DATA__ description c3560-a68.mud g6/20-g7/2 description c3560-a68.mud :::Leaf::: description c3560-a68.mud blah blah

    Prints:

    c3560-a68.mud c3560-a68.mud c3560-a68.mud

    DWIM is Perl's answer to Gödel
      thanq grandfather .^_^.
Re: remove extra spaces/characters after a given result is found
by graff (Chancellor) on Aug 28, 2007 at 02:45 UTC
    Once you read perlre, you'll see that this also works:
    my ($key) = /description\s+(\S+)/;