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!

In reply to variable assignment error by bluethundr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.