Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

richardc (1662)

richardc
  (email not shown publicly)
http://unixbeard.net/~richardc/

Journal of richardc (1662)

Thursday November 28, 2002
06:21 AM

thinking out loud

[ #9193 ]
I just sent this out, and then remembered that the fine people of use.perl have made good suggestions about this in the past, so here we go.

On Tuesday, Nov 26, 2002, at 11:36 Europe/London, Tatsuhiko Miyagawa
wrote:
>BTW, why not including a executable script to replace /usr/bin/find in
>File::Find::Rule distribution?
>
>  % findrule -type file -mp3 title="youth gone wild" -mp3 length="3min" /mp3
>  % findrule -md5 blahblahblah /archives
>  % findrule -type file -image_x 120

It's a good idea, so I started on one yesterday[1].  Unfortunately I
quickly hit on a problem of how to group without splitting arguments in
a way that wouldn't be ideal.

What I currently have is something that works like so:

% findrule file name [ red blue ]
# files called red or blue, below the current directory

% findrule file name red blue
# files called red, below the directory called blue

But it kindof expects you to know what takes arguments (like name) and
what doesn't (like file), which I'm not sure is so great.  There's
possibly adding - to indicate that you mean a clause, but then what if
you really want to pass something starting with - as an argument.  Hmmm.

% findrule -file -name red blue
# files called red or blue, below the current directory

% findrule -file -name red -- blue
# files called red, below the directory called blue

% findrule -file -name -name
# syntax error?  I really wanted files called -name

I'm more just thinking out loud right now, but if you have any
suggestions I'd be glad to steal them from you.

Thanks

[1] http://mirth.unixbeard.net/svn/richardc/perl/File-Find-Rule/findrule

--
Rich ard Clamp <richardc@unixbeard.net>

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I guess if you're building a workalike for unix find, you should follow the syntax used by that command (probably the GNU version, or maybe BSD [openbsd.org] if that's what floats your boat).

    Either way, it's probably worth letting tomc know about your script, as the version of find [perl.com]currently on the Perl Power Tools [perl.com] site doesn't implement a lot of the find functionality.

  • Ah yes, *lightbulb*. I can steal the GNU convention of putting where first, rather than last, giving us:

    % findrule -file -name red blue
    # find files called red or blue, below the current directory

    % findrule blue -file -name red
    # find files called red, below the directory blue

    Though I think it still leaves the ambiguity about finding things named -*, maybe we could use '[' ']' to disambiguate that (of course then we can't find things called '[' or ']'

    % findrule -file -name [ -red ]
    # find files

  • If the -* is entered on the command line, in all Unices I've used, the shell will pre-populate the list. To get around it using "-*" will allow the string to be passed as an argument. Perhaps you could then specifically check for the wildcard character when reading the arguments and options, and deal with it appropriately.
  • If the -* is entered on the command line, in all Unices I've used, the shell will pre-populate the list. To get around it using "-*" will allow the string to be passed as an argument.

    Sorry, I think you've taken my ramblings a bit too literally. I was talking of nailing down the meaning of -name -red. If I apply a simple "things matching /^-/ are commands" rule then that translates to the Perl ->name()->red(), so how would I get to ->name( '-red' ), which is what I really wanted.

    Perhaps you

  • Quotes could still be used to escape a file ("-red") or pattern ("-*") that could be misled as an option name. Although the use of [] might be obvious in Perl syntax, I've not come across that style of grouping command line arguments. Not that that is a reason not to use them.
  • You can't do that. Well, you could, but you'd have to double-quote, ie:

    -name '"-red"'

    Just to get around the shells quoting. Ewww.

    -Dom

  • Korn and Bash shells use [ .. ] as a shorthand for test .., so it would be unwise to use those characters.
  • Korn and Bash shells use [ .. ] as a shorthand for test .., so it would be unwise to use those characters.

    Odd, not from my the bash on my box, and not in a script either.[0]

    This was giving me a little trouble before though, more for consistency with find(1) than anything, so I switched it over to using '(' and ')' as parameters. The hard part is finding a set of grouping characters that aren't significant in any shell, since () themselves are used by bash and zsh.

    [0]

    bash-2.05a$ ls [ foo ]
    ls: [: No