CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Laurent_R] map function: Edit Log



BillKSmith
Veteran

Apr 12, 2013, 6:44 AM


Views: 591
Re: [Laurent_R] map function

I would simplify the whole subroutine.

Code
sub csv_join { 
my $QUOTE = q(");
return join(
q(,),
map {
my $row = $_;
$row //= q();
if ($row =~ m/[",\n]/){
$row =~ s/$QUOTE/$QUOTE$QUOTE/g;
$row = qq($QUOTE$row$QUOTE);
}
$row;
} @_
);
}


Perhaps I went to extremes to avoid the forest of quote marks.
Good Luck,
Bill

(This post was edited by BillKSmith on Apr 12, 2013, 7:23 AM)


Edit Log:
Post edited by BillKSmith (Veteran) on Apr 12, 2013, 7:23 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives