develooper Front page | perl.beginners | Postings from January 2002

another easy question (actually 3)

Thread Next
From:
Booher Timothy B 1stLt AFRL/MNAC
Date:
January 3, 2002 14:31
Subject:
another easy question (actually 3)
Message ID:
30C9E24891FFD411B68A009027724CB701C9AD55@eg-002-015.eglin.af.mil
o.k. here is another one:

I still have a text file I am trying to get into a csv line, for example:

            cheese          olives         beans       carrots

So I put this into an array like:
      
my @headers = split /\s+/;

But now I want to print this in csv format:
"cheese","olives","beans","carrots".

My best results have been to use:

      foreach (@headers) {
	  print "\"$_\",";
      }

But I am sure there is a better way, for example can I define the '$,'
variable to be a comma? I have searched all my documentation and haven't
come to any solid conclusion.

Secondly, I find that I get a zero-length field for $headers[0] and don't
understand why.

Lastly, does /\s+/ mean 2 or more spaces or does it mean one or more spaces,
I imagine that \s counts for one space and the '+' counts for one or more
'other' spaces - is this correct (i.e. I don't need /\s\s+/ to find two or
more spaces).

Laters,

Tim

____________________________________________________
Timothy B Booher, Lt USAF, AFRL/MNAC
101 West Eglin Blvd, Suite 339 
Eglin AFB FL 32542-6810 
Phone: 850-882-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About