Your script seems to work fine when I throw away all that html stuff.

#!/usr/bin/perl use 5.8.8; use warnings; use strict; my $del= '----------'; my @comments= ('John','Woo',$del,'Karl','Zeiss',$del,'Jehud', 'Menuhin +',$del,'Bjoern','Borg',$del,'George','Bernhard','Shaw'); setText(); my @text=getArray(); my $flipped=flipText(@text); print $flipped; #first, define the subroutines sub setText{ my $commentsString=join ("\n", @comments); open my $writeComments, '>', 'comments.txt'; $commentsString=$commentsString . "\n----------\n"; print $writeComments $commentsString; close $writeComments; } sub getArray{ #you want to return an array from here open my $readComments, 'comments.txt'; my @text1=<$readComments>; close $readComments; my $text=join ('', @text1); #at this point you should have a string, $text, comprised of #your text file, commentsTesting.txt as a string, including #\n's & ----- @text1=split(/----------\n/, $text); return @text1; #so you've put each line into each element of the array, #preserving your newline chars & incl \n's & ---------- #you've translated to a string, $text, via join, incl \n's & ----- #you've translated back into array, (split by -----), where #each section is an element; note ----- are excluded } sub flipText{ my @text1=@_; my @flipped=reverse(@text1); my $flipped1=join ("----------\n", @flipped); $flipped1=$flipped1 . "----------\n"; return $flipped1; } #--------------------- #prints George Bernhard Shaw ---------- Bjoern Borg ---------- Jehud Menuhin ---------- Karl Zeiss ---------- John Woo ----------

You might print out (with the help of Data::Dumper) the contents of your variables at different times in your script to a log file to see exactly what happens when with what data

Btw: What exactly is wrong with the output you get? Are the lines inside some of the comments reversed or is the order of the comments not right?


In reply to Re: array gone amiss by jethro
in thread array gone amiss by bluegospel

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.