bluethundr has asked for the wisdom of the Perl Monks concerning the following question:

Hey Perl gurus

I am having another problem with my perl script.

I notice that I can run this script just fine unless I add a particular variable assignment which looks completely normal to me. I must be missing something obvious if someone could please have a look.

$gmetric $gmetric_conf "--name=VVname --value=$pVVname --type=uint32 +--units=name"; $gmetriC $gmetric_conf "--name=t --value=$t --type=uint32 --units +=t"; $gmetric $gmetric_conf "--name='I/O per second Cur' --value=$ioCu +r --type=uint32 --units=ioCur";


The script runs fine without these lines. But as soon as I re-add them it explodes.. Any idea what I'm doing wrong?

Here's the full code followed by the error I am getting:

#!/usr/bin/perl use strict; use warnings; use IO::Pipe; use IO::Handle; use IO::File; my $system; my @systems = ( '3par-S400', '3par-E200' ); open( MYFILE, '>>data.txt' ); foreach $system (@systems) { my $output = run_command($system); while (<$output>) { next if (m/^$/); next if (m/KBytes/); next if (m/VVname/); last if (m/^\-\-\-\-\-.*$/); s/^ *//; s/ +/\|/g; print MYFILE $_; } } close(MYFILE); open( MYFILE, '<data.txt' ); while (<MYFILE>) { my $thisline = $_; chomp($thisline); my ( $VVname, $t, $ioCur, $ioAvg, $ioMax, $kbCur, $kbAvg, $kbMax, +$svtCur, $svtAvg, $iokbCur, $iokbAvg, $Qlen) = split /\|/, $thisline; print "$VVname $ioCur $ioAvg $ioMax $kbCur $kbAvg $kbMax + $svtCur $svtAvg $iokbCur $iokbAvg $Qlen\n"; } close(MYFILE); open( MYFILE, '<data.txt' ); while (<MYFILE>) { my $gmetric="/usr/bin/gmetric"; my $gmetric_conf="-c /etc/gmond.conf"; my $thisline = $_; chomp($thisline); my ( $VVname, $t, $ioCur, $ioAvg, $ioMax, $kbCur, $kbAvg, $kbMax, +$svtCur, $svtAvg, $iokbCur, $iokbAvg, $Qlen) = split /\|/, $thisline; $gmetric $gmetric_conf "--name=VVname --value=$pVVname --type=uin +t32 --units=name"; $gmetriC $gmetric_conf "--name=t --value=$t --type=uint32 --units +=t"; $gmetric $gmetric_conf "--name='I/O per second Cur' --value=$ioCu +r --type=uint32 --units=ioCur"; $gmetric $gmetric_conf "--name='I/O per second Avg' --value=$ioAv +g --type=uint32 --units=ioAvg"; } close(MYFILE); sub run_command { my $user = 'gmon'; my $system = shift; my $protocol = 'ssh'; my $ssh_flags = "-l $user"; my $command = "statvv -ni"; my $space = " "; my $do_command = $protocol . $space . $ssh_flags . $space . $syste +m . $space . $command; my $cmd = IO::Pipe->new; $cmd->reader($do_command); return $cmd; }


Here's the error:

[bluethundr@cc126-200:~/perl] $:./test-foo.pl Scalar found where operator expected at ./test-foo.pl line 42, near "$ +gmetric $gmetric_conf" (Missing operator before $gmetric_conf?) String found where operator expected at ./test-foo.pl line 42, near "$ +gmetric_conf "--name=VVname --value=$pVVname --type=uint32 --units=n +ame"" (Missing operator before "--name=VVname --value=$pVVname --type=u +int32 --units=name"?) Scalar found where operator expected at ./test-foo.pl line 43, near "$ +gmetriC $gmetric_conf" (Missing operator before $gmetric_conf?) String found where operator expected at ./test-foo.pl line 43, near "$ +gmetric_conf "--name=t --value=$t --type=uint32 --units=t"" (Missing operator before "--name=t --value=$t --type=uint32 --uni +ts=t"?) Scalar found where operator expected at ./test-foo.pl line 44, near "$ +gmetric $gmetric_conf" (Missing operator before $gmetric_conf?) String found where operator expected at ./test-foo.pl line 44, near "$ +gmetric_conf "--name='I/O per second Cur' --value=$ioCur --type=uint +32 --units=ioCur"" (Missing operator before "--name='I/O per second Cur' --value=$io +Cur --type=uint32 --units=ioCur"?) Scalar found where operator expected at ./test-foo.pl line 45, near "$ +gmetric $gmetric_conf" (Missing operator before $gmetric_conf?) String found where operator expected at ./test-foo.pl line 45, near "$ +gmetric_conf "--name='I/O per second Avg' --value=$ioAvg --type=uint +32 --units=ioAvg"" (Missing operator before "--name='I/O per second Avg' --value=$io +Avg --type=uint32 --units=ioAvg"?) syntax error at ./test-foo.pl line 42, near "$gmetric $gmetric_conf " Global symbol "$pVVname" requires explicit package name at ./test-foo. +pl line 42. Global symbol "$gmetriC" requires explicit package name at ./test-foo. +pl line 43. syntax error at ./test-foo.pl line 43, near "$gmetriC $gmetric_conf " syntax error at ./test-foo.pl line 44, near "$gmetric $gmetric_conf " syntax error at ./test-foo.pl line 45, near "$gmetric $gmetric_conf " Execution of ./test-foo.pl aborted due to compilation errors.


Thanks for your expert help!

Replies are listed 'Best First'.
Re: variable assignment error
by dasgar (Priest) on Sep 03, 2010 at 18:57 UTC

    In those lines, you don't have any assignment operators and you're not calling any subroutines that would assign values. Those lines are like me telling "a b c". I just told you three things, but didn't tell you what I wanted you to do with them. That's why Perl isn't too happy about those lines.

    I'm assuming that since your lines are 'variable variable string' and that those variables hold strings, that you're wanting to do some concatenation of the strings. If so, I think you would want to do something like this:

    $gmetric = $gmetric_conf."--name=VVname --value=$pVVname --type=uint3 +2 --units=name";

    or

    $gmetric .= $gmetric_conf."--name=VVname --value=$pVVname --type=uint +32 --units=name";

    If you can explain what you're trying to assign to what variables, perhaps someone can help you figure out the correct syntax.

Re: variable assignment error
by Marshall (Canon) on Sep 03, 2010 at 19:24 UTC
    In the second group, I don't see any assignment statement, just 2 variable names and then a string constant, but no "=".
    my ( $VVname, $t, $ioCur, $ioAvg, $ioMax, $kbCur, $kbAvg, $kbMax, $svtCur, $svtAvg, $iokbCur, $iokbAvg, $Qlen) = split /\|/, $thisline; $gmetric $gmetric_conf "--name=....."; $gmetriC $gmetric_conf "--name=t .....t"; $gmetric $gmetric_conf "--name='I/O ...."; $gmetric $gmetric_conf "--name='I/O per second Avg";
Re: variable assignment error
by Crackers2 (Parson) on Sep 04, 2010 at 01:01 UTC

    This looks to me like you're trying to execute $gmetric with the given parameters. I know in bash you can do

    CMD=/bin/tr PARM1=a-z PARM2=A-Z $CMD $PARM1 $PARM2

    and have it execute /bin/tr a-z A-Z, but that doesn't work in perl. You'd have to do something like

    system("$gmetric $gmetric_conf --name=VVname --value=$pVVname --type= +uint32 --units=name"); system("$gmetriC $gmetric_conf --name=t --value=$t --type=uint32 --un +its=t"); system("$gmetric $gmetric_conf --name='I/O per second Cur' --value=$i +oCur --type=uint32 --units=ioCur");

    Normally I'd be inclined to use the multi-arg version of system, but that wouldn't work here since $gmetric_conf contains more than one parameter.

      Normally I'd be inclined to use the multi-arg version of system, but that wouldn't work here since $gmetric_conf contains more than one parameter.

      Then, it should be turned into @gmetric_conf

      ;)