in reply to problem printing array elements -- printing # of lines in array instead

you have to remember that you split a a string into discrete elements that would be fed to an array and you join discrete elements together from an array to form a continuous string, hence you can not do what you have been trying (i.e to split an array) unless of course you are using that array in a different context by dereferencing it with $array[$index]...another thing is that, from how you printed @command_array at the beginning of the program I wonder if you used the appropriate splitting pattern, you are splitting over /:/, so I am not sure what your data looks like and remember bad data can ruin your day, so if you want to split around /:/ this pattern better be sure your data elements are separated according to this pattern, I have made the DATA part into a one-line : separated...I have come up with this code, it solves the problem if your data was organized that way.
#!/usr/local/bin/perl use strict; use warnings; my $index; my @command_array = <DATA>; my @command_array_split; print "@command_array"; for($index=0;$index<=$#command_array;$index++){ my @command_array_split = push @command_array_split,(split(/:/ +,$command_array[$index])); } print "Individual Elements\n\n"; print "$command_array_split[0]\n"; print "$command_array_split[1]\n"; print "$command_array_split[3]\n"; __DATA__ fault-reportin email:smtp-server 1.2.3.4 from me@here.com:recipient me +1@here.com:recipient me2@here.com:recipient me3@here.com:recipient me +4@here.com:enable
I welcome everyone to criticize my programming approach, for I am not perfect and towards perfection I am sailing comrades.
  • Comment on Re: problem printing array elements -- printing # of lines in array instead
  • Download Code