paulpi has asked for the wisdom of the Perl Monks concerning the following question:

OK, this may be a no-brainer to you but it's inflicted me with much gnashing of teeth...

Am coding to display directory contents on a HTML page and liked the look of File::Listing to parse the directory. My problem is that calling the parse_dir command doesn't work as I thought it would. The manual (un)helpfully provides only this to describe it's application:

parse_dir(`ls -l`)

But hey that's ok, I need to move up/down directory trees so I thought it'd be a doddle to change the function call thus:

my $dir = "/foo";
parse_dir("ls -l $dir")

Except it doesn't work!!!

even calling the function with single quotes i.e.parse_dir('ls -l') won't return.

I can get around it by calling a chdir() command prior to issuing the parse_dir call but i'm running under mod_perl so that just opens another can of worms...

What's with the back apostophe?! And how can I get around this with my teeth intact?...it's tarnishing my saintly demeanour!!

Paul

Replies are listed 'Best First'.
Re: The Apostrophe According To St Paul
by Sidhekin (Priest) on Jul 03, 2004 at 16:28 UTC

    I don't know this module, but based on your desciption, you want:

    my $dir = "/foo"; parse_dir(`ls -l $dir`);

    The backquote operator is described in perlop, but briefly, it executes an external command, capturing its (standard) output.

    HTH,

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!

      Why didn't I just try it like that?! I'd very much like to honour you properly but my brain clearly is on holiday so I'll keep it simple: THANKS A LOT SIDHEKIN - YOU'RE MY HERO!!
Re: The Apostrophe According To St Paul
by theorbtwo (Prior) on Jul 03, 2004 at 21:09 UTC

    In the computing world, ` (`, backtick or backquote), ' (', single-quote), and " (", double-quote) are all different things, and are used for different purposes. If you can't tell the difference between the three, change your font. The documentation used ` (backtick), because the point is that it runs ls -l, then passes the output of that command to the function parse_dir.

    You can find all three documented in great detail in perlop.

    (Note, BTW, that while ' is both single-quote and apostrophe, the single-quote meaning is normaly the one that is being referred to when ' is used, except in strange circumstances, or inside of a human-readable string.)

Re: The Apostrophe According To St Paul
by tachyon (Chancellor) on Jul 04, 2004 at 05:08 UTC

    If you are using Apache on *nix you can make a dir/subdirs readable in a browser simply by making that dir world readable (readable by apache) with chmod. Provided you don't have an index.htm (or whatever your config details as the defualt) Apache will produce a nice browsable dir listing for you.

    cheers

    tachyon

      That assumes you have a install of Apache that includes mod_dir. That module is included in the default build. I would never put a default Apache build on a production box. But, that's just me.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

        I would never put a default Apache build on a production box. But, that's just me.

        Neither do I. mod_perl and mod_rewrite and getting the latest patches are amongst the reasons, not excluding mod_dir ;-)

        cheers

        tachyon