Professional Web Applications Themes

Running command from string variable as if part of script - PERL Beginners

I'm reading another perl script into array and want to commands from the the array as if normal perl commands. How do I do it?...

Sponsored Links
  1. #1

    Default Running command from string variable as if part of script

    I'm reading another perl script into array and want to commands from the the
    array as if normal perl commands. How do I do it?
    Sponsored Links
    Tushar Gokhale Guest

  2. #2

    Default Re: Running command from string variable as if part of script


    On Dec 22, 2003, at 5:05 AM, NYIMI Jose (BMB) wrote:
    [..]
    > I'm wondering if you really need
    > to read a script into an array ?
    > Ugly for me ;)
    [..]

    I agree with you, it is clearly not making sense
    why one would want that as a pattern - it clearly
    can be done:
    my $username = 'drieux';
    my alt_cmd = qw/ps -fu/;
    my cmd = qw/ps -aU/;

    my response = `cmd $username`;
    foreach my $line (response)
    {
    print $line;
    }

    If anything, the idea of running a hash of arguments
    to a command has some value:

    my $username = 'drieux';
    my $ps_args = {
    'broken' => '-fu',
    'smallUser' => '-aU',
    'bigUser' => '-axwwU'
    };
    foreach my $key (keys %$ps_args)
    {
    print "running with args: $ps_args->{$key}\n";
    my response = `ps $ps_args->{$key} $username`;
    foreach my $line (response)
    {
    print $line;
    }
    }


    Drieux Guest

  3. #3

    Default Re: Running command from string variable as if part of script

    Tushar Gokhale wrote:
    > I'm reading another perl script into array and want to commands from the the
    > array as if normal perl commands. How do I do it?
    The truly helpful answer would be: "Don't do this!". OTOH, if you want to try
    it out for yourself, I would suggest wrapping in in an eval block. This will
    basically run the script for you. It will not do anything to compensate for
    lack of program structure, though.

    Why do you want to run one script from another? We may be able to find better
    ways for you to achieve your purpose.

    Joseph

    R. Joseph Newton Guest

  4. #4

    Default Re: Running command from string variable as if part of script

    "R. Joseph Newton" wrote:
    > Tushar Gokhale wrote:
    >
    > > I'm reading another perl script into array and want to commands from the the
    > > array as if normal perl commands. How do I do it?
    >
    > The truly helpful answer would be: "Don't do this!". OTOH, if you want to try
    > it out for yourself, I would suggest wrapping in in an eval block. This will
    > basically run the script for you. It will not do anything to compensate for
    > lack of program structure, though.
    >
    > Why do you want to run one script from another? We may be able to find better
    > ways for you to achieve your purpose.
    >
    > Joseph
    Just read back through the list. Is this a continuation of the test harness
    thread? If so, you would get more focused help by staying on-thread. Reading the
    earlier thread showed that there was a purpose, but I still question its
    applicablity. The best test harness for a script is probably the command line.
    For any piece of code that can run from the command line on its own, a test harness
    is likely to obscure problems and make debugging more difficult, rather than less.

    Test harnesses are more appropriate for modules intended for use within a complex
    system. Since each module should, ideally be tested independently, we use test
    harnesses to simulate the demands and conditions the module will face when placed
    in production, in order to better focus on the problems that arise from other parts
    of the application system.

    Creating an effective test harness will therefore require some serious high-level
    design work. To be used effectively, a test harness should very closely reflect
    the interface of the module, from the calling routine's perspective. It should
    test all boundary conditions that may affect operation, as well as operation under
    normal cirstances. It would be very difficult to do this using a single generic
    harness for multiple scripts. The fan-out should be in the other direction. Any
    large system will probably require many test harnesses in its development, each
    specialized to test some portion of the system in isolation.

    For any script that can be run from the command line, the interpreter itself shold
    be an adequate test harness. It will provide focused feedback on both the sytactic
    integrity of the code, and warnings of likely logic errors. An interactive
    debugger can help, also. I believe that there is something along that line
    available with the standard install of Perl, but I haven't explored it myself. You
    might try:

    perldoc perldebug

    for more information on the built-in test harness for scripts.

    Joseph


    R. Joseph Newton Guest

Similar Threads

  1. P part of string (mid string function ?)
    By mimages in forum PHP Development
    Replies: 7
    Last Post: September 27th, 12:58 AM
  2. Replies: 4
    Last Post: September 12th, 04:19 PM
  3. Windows Explorer Right Click Command (+ Custom Command Script)
    By lennySydney webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 1
    Last Post: September 6th, 07:59 PM
  4. Replies: 1
    Last Post: August 19th, 02:26 AM
  5. getting part of a string
    By Micah Montoy in forum PHP Development
    Replies: 1
    Last Post: July 9th, 04:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139