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.

In reply to Re: problem printing array elements -- printing # of lines in array instead by biohisham
in thread problem printing array elements -- printing # of lines in array instead by sqspat

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.