in reply to Using a regex to extract a version from a Un*x path

I've come up with a regex which works, but is hardly elegant.

Don't use a regex, use a function.

my $version = get_version( $path ); sub get_version { # complicated logic here my($p) = @_; my $v ; $v = get_version_home_csv($p); return $v if $v; $v = get_version_custom1($p); return $v if $v; ... }

Replies are listed 'Best First'.
Re^2: Using a regex to extract a version from a Un*x path
by Marshall (Canon) on Mar 18, 2010 at 08:57 UTC
    I am curious as to what get_version_home_csv() and get_version_custom1() do? i.e. show some code.
      Which part of "complicated logic", do you not understand? :) Every time a new version types is added, or there is a new change in the configuration management system, you add a function tailored specifically to that type of path. A single regular expression is the wrong way to deal with this, you need a factory pattern.
Re^2: Using a regex to extract a version from a Un*x path
by gcmandrake (Novice) on Mar 18, 2010 at 16:05 UTC

    Good idea. I originally organized the different regexes into separate functions, but I later felt that having them in one place would make support easier. I think it depends on how many corner cases I need to support.