Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: Is there a better way.

by Lawliet (Curate)
on Feb 24, 2009 at 01:47 UTC ( #745876=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Is there a better way.
in thread Is there a better way.

Without digressing too much, why is it better to use Perl's built-in functions?

And you didn't even know bears could type.

Comment on Re^3: Is there a better way.
Replies are listed 'Best First'.
Re^4: Is there a better way.
by graff (Chancellor) on Feb 24, 2009 at 03:28 UTC
    Because someone might decide to copy the script to a machine where there is no command called "ls" (or where such a command is not in the user's PATH). Also, it might seem unlikely in this case, but one person's "ls" command might produce different output (or perform some different function) than another person's "ls" command.

    A perl-internal method like a glob or opendir()/readdir() can be counted on to produce consistent results wherever perl is installed.

Re^4: Is there a better way.
by jwkrahn (Monsignor) on Feb 24, 2009 at 03:21 UTC

    The qx operator forks off a separate process and then runs a shell (usually /bin/sh) to execute the `ls` command.   Perl's glob executes the glob(3) library function directly.

    If ls encounters a directory name matching *$caseNumber* then it will descend into that directory and list all the files there.

    If any of the file names contains a newline then qx will split it on the newline into separate file names.

Re^4: Is there a better way.
by k0d3Monkee (Initiate) on Feb 25, 2009 at 00:08 UTC
    In general built-in functions are less platform dependent than invoking a command line program which may behave differently on various flavors of UNIX. In this case, 'ls' probably will work the same everywhere, but the general rule holds...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://745876]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2015-11-26 08:25 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (696 votes), past polls