Aloha, I am trying to iterate through a simple array of 5 lines (read from a text file). I know the array always starts with 0. So when using the for each loop it skips 0. Why? This makes it leave out the first line, I only get 4 lines. I need to use PERL more often! I use BBEdit. I just opened my names.txt in Firefox also confirming 5 names. and added print scalar of @data.
foreach $name (@data) { print "$name"; }
#!/usr/bin/perl use strict; use warnings; my @data; my $name; open (JOE, "</Users/mrg/Desktop/names.txt") or die "No can!"; while (<JOE>) { @data = <JOE>; } foreach $name (@data) { print "$name"; }
This is names.txt
Joseph.Guillaume Fred.Flintsone Barney.Rubble George.Jetson ElRoy.Jetson
This is the Ouput:
Last login: Wed Jul 23 13:44:11 on ttyp1 Welcome to Darwin! G4-2:~ mrg$ /var/tmp/folders.507/Cleanup\ At\ Startup/test-238549606.0 +74.pl.command; exit Fred.Flintsone Barney.Rubble George.Jetson ElRoy.Jetsonlogout [Process completed]
Problem solved! by injunjoe Mahalo (Thank You)

In reply to foreach in array by loop362

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.