Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

regex on path

by Sara (Acolyte)
on Aug 06, 2002 at 15:26 UTC ( [id://188058]=perlquestion: print w/replies, xml ) Need Help??

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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://188058]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found