Why doesn't Perl have cp or mv?

A

Andras Malatinszky

Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?
 
A

Andras Malatinszky

Steven said:
perldoc File::Copy

Thanks. Unfortunately I didn't find the answer to my question in that
doc. Perhaps, if it's not too much trouble, you could quote the relevant
part?

Notice that the question was "why doesn't Perl emulate cp or mv?" or in
other words, "why didn't the designer of Perl include a cp and an mv
function?" rather than "how do I make up for the lack of cp or mv?"
 
R

Ron Coscorrosa

Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?

Probably because chmod and chown are system calls, mv and cp aren't.
 
T

Tim Heaney

Andras Malatinszky said:
Why is it that Perl emulates Unix commands like chmod and chown but
not such basic operations like cp or mv?

Perl doesn't actually emulate the Unix *commands* chmod and chown,
rather it emulates the Unix *system calls* chmod and chown. Perl has
a rename command, which is just like the rename Unix system call.

The Unix chmod and chown commands are essentially wrappers around the
chmod and chown system calls, whereas the Unix cp and mv commands are
fairly sophisticated little programs; much more than just wrappers
around the rename system call. The Perl File::Copy module has the more
sophisticated copy and move functions in it (which you may even spell
cp and mv, if you prefer).
 
A

Ala Qumsieh

Andras said:
Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?

FWIW, Perl does have a 'mv' command. It is called 'rename'.

--Ala
 
C

Chris Barts

Andras said:
Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?

Because Perl is a programming language, and programming languages don't
usually name functions after other programs.

chmod and chown are system calls into Unix and Unix-like OSes that are
commonly available as functions in languages like C and C++. Perl has
made them part of itself and emulated them even on OSes that don't
provide them (they may not do anything useful, however). The programs
chmod and chown are simply wrappers around those system calls which have
the same name.
 
C

Chris Mattern

Andras said:
Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?

perldoc File::Copy

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
C

Chris Mattern

Andras said:
Thanks. Unfortunately I didn't find the answer to my question in that
doc. Perhaps, if it's not too much trouble, you could quote the relevant
part?

Notice that the question was "why doesn't Perl emulate cp or mv?" or in
other words, "why didn't the designer of Perl include a cp and an mv
function?" rather than "how do I make up for the lack of cp or mv?"

File::Copy enables you to do copies and moves. I don't understand your
point.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
C

chris-usenet

Ala Qumsieh said:
FWIW, Perl does have a 'mv' command. It is called 'rename'.

No... they're subtly different. mv(1) will move a file between
filesystems; rename(2) won't. See the man page for rename, particularly
the EXDEV error case.

CHris
 
C

Chris Mattern

No... they're subtly different. mv(1) will move a file between
filesystems; rename(2) won't. See the man page for rename, particularly
the EXDEV error case.
mv also allows to name a directory as a destination, and name multiple
files to be moved if you do.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
A

Andras Malatinszky

Tim said:
Perl doesn't actually emulate the Unix *commands* chmod and chown,
rather it emulates the Unix *system calls* chmod and chown. Perl has
a rename command, which is just like the rename Unix system call.

The Unix chmod and chown commands are essentially wrappers around the
chmod and chown system calls, whereas the Unix cp and mv commands are
fairly sophisticated little programs; much more than just wrappers
around the rename system call. The Perl File::Copy module has the more
sophisticated copy and move functions in it (which you may even spell
cp and mv, if you prefer).


I see. Thanks very much.
 
R

robic0

Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?


using File::Copy,

move is done via os-rename function into the "ToDir".
rename ("From","To");

-- you don't think Perl rewrites file systems do you....
Somethings in Perl distribution are rewritten emulations of the
original lang constuct, like printf, etc.... but you gotta believe
it just "wraps" most os api's.
 
B

Bart Lateur

Andras said:
Why is it that Perl emulates Unix commands like chmod and chown but not
such basic operations like cp or mv?

On a similar note, I've always wondered why Perl had no curdir, or cwd.
Cwd() exists to solve that problem, but the question still remains.

Currently, I'm more inclinced on moving stuff *out* of perl and into
modules. For example, I see no reason why socket calls couldn't actually
be part of a module, instead of built into perl.

Just blame perl4, because extensible perl (with XS modules) was new for
perl5 -- since around 1995.
 
J

Joe Smith

Bart said:
On a similar note, I've always wondered why Perl had no curdir, or cwd.

Because that is not a standard system-call or standard C library
function. (Most unix-like systems only keep track of the current
directory's inode, not its name. And the name may have changed
in the interim.)
Cwd() exists to solve that problem, but the question still remains.

Have you seen how much code it takes for Cwd() to come up with
that answer? It's not something you want to do everytime perl
starts up.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top