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

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

Replies are listed 'Best First'.
Re: Re: Re: Building regexp from a 'mask' string of placeholders.
by tachyon (Chancellor) on Feb 10, 2003 at 07:35 UTC

    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

        Ah good point, I was just trying to think of something word like that 3D designers could remember....

        I will modify the code to use # for posterity.

        cheers

        tachyon

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