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

Hello monks!

I am having a bit of trouble with this script and I do appreciate your putting up with various iterations of it over the past few days. As you'll see I changed my approach from trying to work directly with the rather verbose output of this networking device (the 3par I've been carping about) I decide it might result in less headdesking if I dumped the output to a file and tried to parse that. And not for nothing but I've recently discovered the joys of perltidy.:-)

The trouble I'm currently facing is that I am having some trouble assigning the text to a hash. It starts spitting out quite a lot of output. I will include that at the end.

Without further ado, here is my latest attempt:

#!/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/^$/); last if (m/^Press.*/); print MYFILE $_ . "\n"; } } close(MYFILE); open( MYFILE, '<data.txt' ); while (<MYFILE>) { next if (m/^$/); last if (m/^Press.*/); my ( $line, %seqs, $sequence, $date, $orig, $desg, $body ); if ( $line =~ /(\d+\-\d+\-\d+\s\d+\d+\ d+\ +)/ ) { $date = $1; } else { $seqs{$sequence} = "$date;$orig;$desg;$body"; } } 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 . $system . $space . $c +ommand; my $cmd = IO::Pipe->new; $cmd->reader($do_command); return $cmd; } close(MYFILE);


And this is a sample of the output I'm experiencing:

[bluethundr@cc126-200:~/perl] $:./3par-test5.pl Use of uninitialized value in pattern match (m//) at ./3par-test5.pl l +ine 29, <MYFILE> line 1. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 1. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 1. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 1. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 1. Use of uninitialized value in hash element at ./3par-test5.pl line 30, + <MYFILE> line 1. Use of uninitialized value in pattern match (m//) at ./3par-test5.pl l +ine 29, <MYFILE> line 2. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 2. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 2. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 2. Use of uninitialized value in concatenation (.) or string at ./3par-te +st5.pl line 30, <MYFILE> line 2. Use of uninitialized value in hash element at ./3par-test5.pl line 30, + <MYFILE> line 2.


Replies are listed 'Best First'.
Re: trouble assigning values to hash
by ikegami (Patriarch) on Aug 26, 2010 at 23:07 UTC

    You never assign anything to $line, $date, $orig, $desg and $body before you use them in the following:

    if ( $line =~ /(\d+\-\d+\-\d+\s\d+\d+\&#65532;d+\&#65532;+)/ ) { $ +date = $1; } else { $seqs{$sequence} = "$date;$orig;$desg;$body"; }

    You also set $date without ever using it.

Re: trouble assigning values to hash
by AnomalousMonk (Archbishop) on Aug 26, 2010 at 23:48 UTC

    Update: OPed code changed by bluethundr.

    bluethundr:

    This is a bit OT your OPed question, but in addition to what ikegami said, the deleted regex
        /(\d+\-\d+\-\d+\s\d+\d+\&#65532;d+\&#65532;+)/
    looks fishy.

    • Do you really wish to match one or more 'd' characters after the first  '&#65532;' entity (for I'm guessing that's what it is)?
    • Do you really wish to match one or more ';' characters as a part of and after the second 'entity'?
    • Do you realize that  '&#65532;' in the regex matches a literal  '&#65532;' in the string?

      Note that the &#65532; might not be in what he pasted. His browser may have substituted a U+FFFC for that. That said, his code shouldn't have U+FFFC there either.

        yes thanks for pointing that out. due to a route problem in the new office I can't tunnel into my desktop and grab the original code that I attempted to paste. I am pretty sure that I fixed it but I will have to wait until I get into the office to be sure. That'll teach me to post to this forum on my way out the door at the end of a busy day! ;)