in reply to parsing a path

This might be easier than all that stuff you do with the array...
#!/usr/bin/perl -w use strict; my $path = '\nb\v5\srcccc\ans.cpp@@\main\\'; my ($dir, $subDir, $file) = $path =~ /^\\([^\\]+)\\([^\\]+).*?(\w+\.cp +p)/; print "$dir\n$subDir\n$file\n";
Joshua

Replies are listed 'Best First'.
Re: (joshua)Re: parsing a path
by Juerd (Abbot) on Jul 17, 2002 at 17:30 UTC

    /^\\([^\\]+)\\([^\\]+).*?(\w+\.cpp)/

    And you say that might be _easier_? :)

    Anyway, I think you missed a $ (or even better: \z) there... \foo\bar\baz.cpp.cpp.cpp.blah.cpp.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Ah, good point. I was just building on kvale's code though.
        How about this way..
        #!/usr/bin/perl -w use strict; while (<DATA>) { my @a = split(/\\/); print "$a[1] $a[2] $a[4]\n"; } __DATA__ \nb\v5\srcccc\ans.cpp@@\main\ \nb\v5\srcccc\ans.cpp@@\main\ \nb\v5\srcccc\test.cpp@@\main\ \nb\v5\safe\test.cpp@@\main\ \nb\v5\safe\test.cpp@@\main\