Why doesn't Perl have cp or mv?

Discussion in 'Perl Misc' started by Andras Malatinszky, Mar 27, 2005.

  1. Why is it that Perl emulates Unix commands like chmod and chown but not
    such basic operations like cp or mv?
     
    Andras Malatinszky, Mar 27, 2005
    #1
    1. Advertising

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


    perldoc File::Copy
     
    Steven N. Hirsch, Mar 27, 2005
    #2
    1. Advertising

  3. Steven N. Hirsch wrote:
    > Andras Malatinszky wrote:
    >
    >> Why is it that Perl emulates Unix commands like chmod and chown but
    >> not such basic operations like cp or mv?

    >
    >
    > 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?"
     
    Andras Malatinszky, Mar 27, 2005
    #3
  4. On Sat, 26 Mar 2005 22:41:52 -0500, Andras Malatinszky wrote:

    > 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.

    --
    Ron Coscorrosa
    http://coscorrosa.com
     
    Ron Coscorrosa, Mar 27, 2005
    #4
  5. Andras Malatinszky

    Tim Heaney Guest

    Andras Malatinszky <> writes:

    > 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).
     
    Tim Heaney, Mar 27, 2005
    #5
  6. Andras Malatinszky

    Ala Qumsieh Guest

    Andras Malatinszky wrote:
    > 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
     
    Ala Qumsieh, Mar 27, 2005
    #6
  7. Andras Malatinszky

    Chris Barts Guest

    Andras Malatinszky wrote:
    > 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.
     
    Chris Barts, Mar 27, 2005
    #7
  8. Andras Malatinszky wrote:

    > 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?"
     
    Chris Mattern, Mar 27, 2005
    #8
  9. Andras Malatinszky wrote:

    > Steven N. Hirsch wrote:
    >> Andras Malatinszky wrote:
    >>
    >>> Why is it that Perl emulates Unix commands like chmod and chown but
    >>> not such basic operations like cp or mv?

    >>
    >>
    >> 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?"


    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?"
     
    Chris Mattern, Mar 27, 2005
    #9
  10. Andras Malatinszky

    Guest

    Ala Qumsieh <> wrote:
    > 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
     
    , Mar 27, 2005
    #10
  11. Chris Mattern <> wrote in news::

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

    >
    > perldoc File::Copy
    >


    OTOH, I remember Abigail having some objections to File::Copy.
    They made sense to me so here is a reference:

    <URL: http://groups-beta.google.com/group/comp.lang.perl.misc/msg/18b26366b3aad30a?dmode=source>

    <URL: http://tinyurl.com/3prlb>

    Sinan
     
    A. Sinan Unur, Mar 27, 2005
    #11
  12. wrote:

    > Ala Qumsieh <> wrote:
    >> 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.
    >

    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?"
     
    Chris Mattern, Mar 27, 2005
    #12
  13. Chris Mattern wrote:
    > Andras Malatinszky wrote:
    >
    >
    >>Steven N. Hirsch wrote:
    >>
    >>>Andras Malatinszky wrote:
    >>>
    >>>
    >>>>Why is it that Perl emulates Unix commands like chmod and chown but
    >>>>not such basic operations like cp or mv?
    >>>
    >>>
    >>>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?"

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


    You obviously don't.
     
    Andras Malatinszky, Mar 27, 2005
    #13
  14. Ala Qumsieh wrote:
    > Andras Malatinszky wrote:
    >
    >> 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
    >

    Good point, thanks.
     
    Andras Malatinszky, Mar 27, 2005
    #14
  15. Tim Heaney wrote:
    > Andras Malatinszky <> writes:
    >
    >
    >>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).



    I see. Thanks very much.
     
    Andras Malatinszky, Mar 27, 2005
    #15
  16. Andras Malatinszky

    Guest

    On Sat, 26 Mar 2005 22:41:52 -0500, Andras Malatinszky
    <> wrote:

    >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.
     
    , Apr 1, 2005
    #16
  17. Andras Malatinszky

    Bart Lateur Guest

    Andras Malatinszky wrote:

    >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.

    --
    Bart.
     
    Bart Lateur, Apr 1, 2005
    #17
  18. Andras Malatinszky

    Joe Smith Guest

    Bart Lateur wrote:

    > 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
     
    Joe Smith, Apr 5, 2005
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    6
    Views:
    5,528
    Kevin Spencer
    Aug 18, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    933
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,123
    Smokey Grindel
    Dec 2, 2006
  4. Nanostuff
    Replies:
    9
    Views:
    157
    Gary Wright
    Mar 1, 2007
  5. Al
    Replies:
    1
    Views:
    164
    Henry Law
    Oct 16, 2005
Loading...

Share This Page