My brain was thinking along the lines of C and its char** argv, which is normally used as "read only"

argv[0] isn't read-only in C, either:

/tmp>cat foo.c #include <string.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char ** argv) { pid_t pid; int status; strcpy(argv[0],"Did you expect this?"); pid=fork(); if (pid<0) { perror("Can't fork"); } if (pid==0) { execlp("ps","ps","-f",NULL); exit(127); } else { waitpid(pid,&status,0); } exit(0); } /tmp>make foo cc foo.c -o foo /tmp>./foo UID PID PPID C STIME TTY TIME CMD foken 1255 1254 0 15:06 pts/0 00:00:00 -bash foken 1676 1255 0 15:21 pts/0 00:00:00 Did you expect this? foken 1677 1676 0 15:21 pts/0 00:00:00 ps -f /tmp>

Of course, manipulating argv[] is not portable. Most Unixes support it in a more or less limited way. The example from above runs on linux 2.6.29.6, and exibits the typical Linux behavior. BSDs and other Unixes may show a different behaviour. On Windows, such a program would only manipulate a copy of the original command line, generated by the C runtime library. (Windows has no concepts like fork(), exec(), or argc/argv[]. Windows programs are expected to parse a single string containing all arguments.)

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^4: Perl Script own path by afoken
in thread Perl Script own path by muzammil18

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.