in reply to Re: Printing an array
in thread Printing an array

Thanks for your help and suggestions. I have read up on subroutines now and come up with the code below. I think this addresses a lot of the points and appears to work quite well but I don't see all of my data file (prev.txt) on screen. Have I still got something wrong? TIA S.
#!/usr/bin/perl -w use strict; my(@DATAFILE); @DATAFILE=&readdata(); &testcode1(@DATAFILE); &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); } # # Subroutines for various tests on the code # sub testcode1 { print "@_"; }

Replies are listed 'Best First'.
Re: Re: Re: Printing an array
by CountZero (Bishop) on Nov 26, 2003 at 20:33 UTC
    I tested your code and it runs without a hitch. The testcode-subroutine nicely prints out a textfile I happened to have on the hard-disk.

    Of course it was a smallish file and that may be where your problem lies: perhaps --I'm just guessing here-- your file is so large that when it is printed on the screen, some buffers overrun and not everything is shown or parts get lost.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law