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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: regex on path
by aufrank (Pilgrim) on Aug 06, 2002 at 15:35 UTC

    you'll want to consider something like

    m!^/(.*?)/!
    and also to read some of the resources listed here.
    --au

Re: regex on path
by bronto (Priest) on Aug 06, 2002 at 16:10 UTC

    You should follow aufrank's advice, or use split. For example:

    my $DRIVENAME = (split /\//,$ENV{PWD})[1] ;

    Or, if you want to keep on with awk, you should just put in your backticks:

    pwd | awk -F/ '{ print $2 }'

    With -F/ you are stating that the separator is slash, and you are printing the second field (the first -that is: what comes before the first slash- is empty)

    Anyway, I strongly descourage you to do so: it's a task that Perl can easily accomplish without spawning any external process, so why do it?

    Ciao!
    --bronto

    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->made($love) ;
    }

      thanks
Re: regex on path
by Basilides (Friar) on Aug 06, 2002 at 15:41 UTC
    would m'/(\w*)'; print $1; work?