shemyaza has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing Arrays to Subroutines
by jeffa (Bishop) on Nov 26, 2003 at 13:38 UTC | |
by shemyaza (Novice) on Nov 26, 2003 at 16:36 UTC | |
|
Re: Passing Arrays to Subroutines
by duff (Parson) on Nov 26, 2003 at 14:56 UTC | |
by shemyaza (Novice) on Nov 26, 2003 at 16:46 UTC | |
by jeffa (Bishop) on Nov 26, 2003 at 18:40 UTC | |
|
Re: Passing Arrays to Subroutines
by Abigail-II (Bishop) on Nov 26, 2003 at 13:38 UTC | |
by shemyaza (Novice) on Nov 26, 2003 at 16:41 UTC |