Hello all,

I have started working on my first real project, to send reminder emails out when meetings are due. Ultimately I want to read a text file (prev.txt) which consists of lines with 9 entries into an array, for each set of 9 entries process them and send emails as necessary, then write the amended array to a file again.

After an earlier query I have altered my first snippet of code as below and put the print command in to test what I have got but it doesn't work. If I replace the 2 with 0 I get what looks like the first line of the data file printed but I expected to get just the first item, 31307MWB using the example below.

A line of data looks like:-

31307MWB name@address name@address name@address 10 11 103 90 0

Can someone tell me what I am doing wrong?

TIA S.

#!/usr/bin/perl -w use strict; my(@DATAFILE); @DATAFILE=&readdata(); print $DATAFILE[2]; &writedata(@DATAFILE); # # Subroutine for reading prev.txt into an array # sub readdata { open (PH, "prev.txt") || die "Cannot open prev.txt: $!"; my(@DATA)=<PH>; chomp @DATA; close (PH); return(@DATA); } # # Subroutine for writing array into prev.txt # sub writedata { my(@DATA)=@_; open (PH, ">prev.txt") || die "Cannot open prev.txt: $!"; foreach(@DATA) { print PH "$_\n"; } close (PH); }

In reply to Passing Arrays to Subroutines by shemyaza

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.