in reply to Building regexp from a 'mask' string of placeholders.

The logic of what you are trying to do eludes me, can you be more specific? Why not just pass your script an appropriate regex string:

$_ = 'some.567.jpg'; m/^[^\.]*\.(\d+)\.(\w+)$/; print "$1 $2"

This will capture the digits and extension into $1 and $2 but I fail to see how one might extrapolate that from a string like 'numberedfiles.@.tif' as this does not give sufficient detail of what is required. It seems to me that by the time you develop a pseudo language to describe what you want you might as well just use the Perl RE language - after all that is what it is designed for.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Building regexp from a 'mask' string of placeholders.
by submersible_toaster (Chaplain) on Feb 10, 2003 at 06:47 UTC

    Good point , sorry for skimming the specifics,
    As much fun as it would doubtless be to try to teach 3d animators perl regex syntax, it's hard enough getting them to consistantly name their files, as you see I have graciously been afforded the '.' as a seperator in filenames. So the final objective is a script that given...

    ./myscript.pl /nfs/bigdisk/renders/monsterrender.cin.@ 50 920
    the script is then able to run some verification on each file in the sequence, perform a few operations, etc. The mechanics of this I already have working, but of course they're for my use, so I asked the 3d team for their preferred CLI. Which I am now trying to accomodate.


    I can't believe it's not psellchecked

      You asked them for an interface that would seem to not have enough flexibility.... Why not give them a syntax like:

      # & = words & digits (alphanumeric) # @ = digits # # = word chars ie [a-zA-Z_] # . = literal . used to separate parts of interest # Anything else is taken to be literal in meaning my $str = "some-file.123.tif"; my $find_str = qq!some-#.@.&!; print "Here is our filename: $str\nHere is the interface string: $find +_str\n"; my @bits = split '\.', $find_str; for (@bits) { s/([^&@#a-zA-Z_])/\\$1/g; s/&/\\w*/g; s/@/\\d*/g; s/#/[a-zA-Z_]*/g; $_ = "($_)"; } my $re = join "\\.", @bits; print "Here is the RE: m/$re/"; $re = qr/$re/; my (@matches) = $str =~ m/^$re$/; $" = ', '; print "\nAnd we got: @matches"; __DATA__ Here is our filename: some-file.123.tif Here is the interface string: some-#.@.& Here is the RE: m/(some\-[a-zA-Z_]*)\.(\d*)\.(\w*)/ And we got: some-file, 123, tif

      The syntax is pretty basic - just three chars for word, dogit and alphanumeric. . for the separator. all other chars are literal. This gives you a lot of power to match subsets of filenames and should take no more that 2 minutes to learn....

      Update

      Changed " token to # so you don't have to escape it in the shell as pointed out by waswas-fng

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        ++ tachyon Maybe a different placeholder than " for word would be better -- as you would not have to escape it for your shell.

        -Waswas