Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re (2): Array for system() call

by dmmiller2k (Chaplain)
on Oct 23, 2001 at 22:09 UTC ( #120855=note: print w/replies, xml ) Need Help??

in reply to Re: Array for system() call
in thread Array for system() call

To elaborate further, use this (note double quotes): system("@Call"); instead of this: system(@Call); to achieve the same effect as your first fragment.

And, BTW, you probably meant to do this:

$Call[0] = "gawk"; $Call[1] = "-f"; $Call[2] = "test.gawk"; $Call[3] = "test.file"; $Call[4] = ">"; $Call[5] = "out.file";

or (slightly more efficiently) this:

@Call = ( "gawk", "-f", "test.gawk", "test.file", ">", "out.file" );

rather than your original code, which is assigning values to 1-element array slices, which are sublists -- NOT arrays! -- of references to the elements of the @Call array; needless to say, although it works, it is somewhat less efficient than either of the above approaches, and bad practice besides.


Give a man a fish and you feed him for a day ...
Teach the man to fish and you feed him for a lifetime

Replies are listed 'Best First'.
Re: Re (2): Array for system() call
by blakem (Monsignor) on Oct 23, 2001 at 22:45 UTC
    Here is an example of why using @arr[0] is just asking from trouble...
    #!/usr/bin/perl -wT use strict; my @arr; @arr[0] = localtime(); $arr[1] = localtime(); print "\$arr[0] = $arr[0]\n"; print "\$arr[1] = $arr[1]\n";
    Any guesses about the output of this simple script? Select area below to find out.

    =OUTPUT Scalar value @arr[0] better written as $arr[0] at ./ line + 6. $arr[0] = 58 $arr[1] = Tue Oct 23 14:30:58 2001
    5 points for anyone who expected $arr[0] to contain an integer. 20 points for anyone who knew it would contain the seconds value, *not* the number of elements in the list returned by localtime().

    (10 points for anyone who coded up an example because they weren't sure... woohoo)


      Thanks for the example, blakem


      You can give a man a fish and feed him for a day ...
      Or, you can teach him to fish and feed him for a lifetime

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://120855]
[stevieb]: I don't know what you mean. I write the code in C/C++ that accesses the ICs per the datasheet, wrap it for Perl, then use them. My code ensures that the functions/methods from Perl do the right thing for the chips/sensors etc
[stevieb]: At least that's what I'm working on right now. I've also been updating my automated test software Test::BrewBuild so it handles this work properly. It's not really easy meshing high level languages with low-level hardware :)
[stevieb]: this link is probably better for an overview of my test software
[stevieb]: the top-level Raspberry Pi distribution, that sucks in all sub modules. All of this software have imminent updated releases coming

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-06-25 23:15 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.