in reply to converting from string to SCALAR when using strict "refs"

Here's the code from your update with <code> tags added.

$processor = `/aa/bin/get_pbind_cpus.ksh`; # Line 325 system("$os_cmd_table{$^O}{pbind} -b $$processor $$proc_id{$_} >/dev/n +ull 2>&1") if defined $$processor;

From this, I think that $processor is being misused as a reference. Line 325 should be:

system("$os_cmd_table{$^O}{pbind} -b $processor $$proc_id{$_} >/dev/nu +ll 2>&1") if defined $processor;

Try it and let us know how it works.

Replies are listed 'Best First'.
Re^2: converting from string to SCALAR when using strict "refs"
by usrlocal (Novice) on Jan 21, 2009 at 16:47 UTC
    Line 325 cant really be modified as it is used many other methods too... can the $processor = `/aa/bin/get_pbind_cpus.ksh`; be modified to populate the processor number correctly?

      If it needs to be a reference to a scalar (as it appears it does), then you want this:

      my $processor = \`/aa/bin/get_pbind_cpus.ksh`;

      That's kind of odd, however. I'd look at the other usages to see if they really are passing in a scalar reference. I'm not saying it's impossible, but I find it strange since there isn't really any advantage to passing in a reference rather than the variable itself.

      I don't have ksh or the commands to test, but it might be a simple as predeclaring the hash %proc_id, but you may need to go a bit deeper depending on how $proc_id{} is setup prior to the command. Just a WAG,
      # borrowing from [kyle]'s translation, # at program beginning my %proc_id; system("$os_cmd_table{$^O}{pbind} -b $processor $$proc_id{$_} >/dev/nu +ll 2>&1") if defined $processor;

      I'm not really a human, but I play one on earth Remember How Lucky You Are
        I tried out kyles suggestion of putting a '\' before the $processor but got the error message
        Processor is SCALAR(0x15f1a8) and qmgr is QM_P266 In bind_cpu_solaris , Processor is SCALAR(0x15f1a8) In for loop ... In Next Loop ... /usr/sbin/pbind: must specify at least one pid usage: /usr/sbin/pbind -b processor_id pid[/lwpids] ...
        The processor variable is populated in one other location where it looks for pid's of other processes already bound to a specific processor and tries to bind to the same (i.e populate $processor with the same proocessor id). the code is like the below:
        sub get_cpu_used_by_other_processes { my $other_process = shift; my $proc_id = locate_process_id( $other_proc ); my $processor = undef; my $pid = undef; my @cmd_output = `$os_command_table{$^O}{pbind} -q 2>/dev/null +`; die "ERROR:failed to retrieve the bound processors\n" unless ( + $? == 0 ); ##### increase the weight of processors based on used or not # +#### foreach ( keys %{$proc_id} ) { $pid = $$proc_id{$_}; next unless defined $pid; foreach ( @cmd_output ) { $processor = $1, return \$processor if /proces +s\s+id\s+${pid}\s*:\s*(\d+) $/; } } }
        I tried out kyles suggestion of putting in the '/' before the 4processor but get the error message:
        after call to bind cpu:WARNING:failed to bind process xxxxa0 PID 3720 +to processor SCALAR(0x15f1a8)(rcode 256) /usr/sbin/pbind: must specify at least one pid usage: /usr/sbin/pbind -b processor_id pid[/lwpids] ... /usr/sbin/pbind -U [processor_id] ... /usr/sbin/pbind -Q [processor_id] ... /usr/sbin/pbind -u pid[/lwpids] ... /usr/sbin/pbind [-q] [pid[/lwpids] ...]
        The processor variable is populated in one other method too before the bind_cpu is invoked. In this case it looks for other processes and binds to the the same processor:
        sub get_cpu_used_by_other_process { my $other_mgr = shift; my $proc_id = locate__process_id( $other_mgr ); my $processor = undef; my $pid = undef; my @cmd_output = `$os_command_table{$^O}{pbind} -q 2>/dev/null +`; die "ERROR:failed to retrieve the bound processors\n" unless ( + $? == 0 ); ##### increase the weight of processors based on used or not # +#### foreach ( keys %{$proc_id} ) { $pid = $$proc_id{$_}; next unless defined $pid; foreach ( @cmd_output ) { $processor = $1, return \$processor if /proces +s\s+id\s+${pid}\s*:\s*(\d+) $/; } } } }