Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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.

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://745876]
help
Chatterbox?
[Discipulus]: a solution would be disabiltate sig as default and let users to show them
[karlgoethebier]: now it's getting weird...
[GotToBTru]: 'getting'?
[Discipulus]: why karlgoethebier ?
[GotToBTru]: ugh .. what's the term for comparing versions of an algorithm to determine which is most efficient?

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2017-06-22 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.