[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Arrays



On Fri, 4 Feb 2000 14:50:12 -0500, Ronald J Kimball wrote:

>while (<>) {
>    push @records, [split /:/, $_];   # push an anonymous array
>                                      # (adjust field separator as necessary)
>}

You forgot to chomp(). Now the last field of the record will end in a
newline.

Also, Julian, note that empty trrailing fields will be stripped by
split(), so you could end up with undefined fields. If running under -w
(which I always recommend), you'll get a lot of "use of uninitialized
value" warnings. If you're sure that a line always contains 6 fields (5
field separators), then 

	@fields = split	/:/, $_, 6;

will help.

Complete script:

  while (<>) {
       chomp;
       push @records, [split /:/, $_, 6];   # push an anonymous array
                              # (adjust field separator as necessary)
  }

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org