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

Hi Everyone, I'm trying to get a Perl script to do a little more than just write to the screen. I'm trying to get the information out into an array, but I can't think of how - when the data is coming in a single character form.

Input from SNMP
iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481153 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481154 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481155 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468865 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468866 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460673 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460674 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460675 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366465 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366466 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366467 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477057 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477058 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477059 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505729 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505730 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505731 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489345 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489346 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489347 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452481 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452482 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452483 = ST +RING:
Script so far
#!/usr/bin/perl -w use strict; use warnings; open(VPNUSERS,'-|','snmpwalk -v 2c -c public 192.168.1.1 1.3.6.1.4.1.9 +.9.392.1.3.21.1.2') || die "Failed\n"; while ((my $name = <VPNUSERS>)) { my @t = split(/\./, $name); my $x = @t; my $iii = 10; while ($iii < $x-1) { print chr($t[$iii]); $iii++; } print "\n"; }
Result
dansue dansue dansue dawnig dawnig gilboi gilboi gilboi jertra jertra jertra joahur joahur joahur judnor judnor judnor stehop stehop stehop waladl waladl waladl

Replies are listed 'Best First'.
Re: Lines of single character to array
by pme (Monsignor) on Aug 13, 2015 at 17:39 UTC
    What is the expected output of your script?
      What I am hoping for, is an array of the results
      dansue dansue dansue dawnig dawnig gilboi gilboi gilboi jertra jertra jertra joahur joahur joahur judnor judnor judnor stehop stehop stehop waladl waladl waladl
      Where each of those 6 letter becomes an object in the array.

        So everywhere you print a character, concatenate into a string. And everywhere you print a newline, push that string onto an array:

        use strict; use warnings; my @array; while (my $name = <DATA>) { chomp $name; next unless length $name; my @t = split(/\./, $name); my $x = @t; my $iii = 10; my $string; while ($iii < $x-1) { $string .= chr $t[$iii++]; } push @array, $string; } print "$_\n" for @array; __DATA__ iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481153 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481154 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481155 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468865 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468866 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460673 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460674 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460675 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366465 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366466 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366467 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477057 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477058 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477059 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505729 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505730 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505731 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489345 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489346 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489347 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452481 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452482 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452483 = ST +RING:

        Dave

        This way all the six-letter strings are pushed onto @array.
        #!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my @array; while ((my $name = <DATA>)) { my @t = split(/\./, $name); my $string = join('', map(chr, @t[15 .. @t-2])); push @array, $string; } print Dumper( \@array ) . "\n"; __DATA__ iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481153 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481154 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.110.115.117.101.18481155 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468865 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.100.97.119.110.105.103.18468866 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460673 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460674 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.103.105.108.98.111.105.18460675 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366465 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366466 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.101.114.116.114.97.18366467 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477057 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477058 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.111.97.104.117.114.18477059 = S +TRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505729 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505730 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.106.117.100.110.111.114.18505731 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489345 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489346 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.115.116.101.104.111.112.18489347 = +STRING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452481 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452482 = ST +RING: iso.3.6.1.4.1.9.9.392.1.3.21.1.2.6.119.97.108.97.100.108.18452483 = ST +RING: