Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: execution of command inside for loop fails

by hdb (Monsignor)
on Oct 01, 2013 at 13:32 UTC ( #1056480=note: print w/replies, xml ) Need Help??

in reply to execution of command inside for loop fails

If you add use strict; use warnings; at the beginning of your script, Perl will tell you what you are doing wrong.

UPDATE: I cannot test this but I guess you need a chomp. Here is how I would write it:

use strict; use warnings; sub ReadPolicies { my $type = shift; my @Policies = `/opt/OV/bin/opctemplate -l | grep -i $type | awk ' +{print \$2}'`; return @Policies; } for( ReadPolicies( "DBSPI" ) ){ chomp; # not sure this is required.... my $cmd = "/opt/OV/bin/opctemplate -e $_"; print "$cmd\n"; my $output= `$cmd`; print "$output\n"; }

Replies are listed 'Best First'.
Re^2: execution of command inside for loop fails
by kaka_2 (Sexton) on Oct 04, 2013 at 10:41 UTC

    Thank You. adding strict and warnings was very helpful.

      Here is my updated code

      sub ReadPolicies { # based on the below command it reads values in ar +ray my ($type) = @_; my @Policies = `/opt/OV/bin/opctemplate -l | grep -i $type | awk '{pri +nt \$2}'`; return (@Policies); } #MAIN My @FailoverPolicies = &ReadPolicies(DBSPI); For (my $i=0; $i < @FailoverPolicies; $i++) { my $cmd "/opt/OV/bin/opctemplate -e" . " " . "$FailoverPolicies[$i]"; my $output= `$cmd`; # here i expect this command read each value from +the array and take action, -e to enable }

      and this works fine but the problem i face is that i see so many <defunct> process on system and i think it is because first command is not completed and second also start and so one and one point this hangs.

      What can i do to ensure 2nd command executes only when first is completed in the loop.

      Thank You.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056480]
[Tanktalus]: well, putting 600MB into an SQLite database seems like the first thing wrong, erix :)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-12-12 00:02 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (319 votes). Check out past polls.