in reply to a q-n-d csv_join function
However, you can only use \@ if your parameters are arrays. If hardcoded lists are used as parameters, e.g. csv_join('a','b','c') instead of arrays, e.g. csv_join(@aFields), then you will need to use the version that passes the entire array. The \@ prototype would complain about extra parameters and failed attempts to take references of constant items.
With revisions (using the \@ protoype)p>
sub csv_join(\@) { join ',', map {s/"/""/g || /[\s,]/ ? qq{"$_"} : $_} (my @x=@{$_[0]}); }
With revisions (passing the entire array):
sub csv_join { join ',', map { s/"/""/g || /[\s,]/ ? qq{"$_"} : $_} (my @x=@_); }
Best, beth
Update: Re-added my @x. Thanks, jwkrahn. I had overlooked the effect of s/// on the elements of @_.
Update 2: Added an alternative if the function needs to be called with hard coded lists, e.g. csv_join('a','b','c')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: a q-n-d csv_join function
by jwkrahn (Abbot) on Mar 02, 2009 at 01:44 UTC | |
|
Re^2: a q-n-d csv_join function
by perl5ever (Pilgrim) on Mar 02, 2009 at 01:42 UTC | |
by ELISHEVA (Prior) on Mar 02, 2009 at 02:39 UTC | |
|
Re^2: a q-n-d csv_join function
by GrandFather (Saint) on Mar 02, 2009 at 02:26 UTC |