in reply to wrap contents of an array in single quotes separated by comma
The key is to chomp your data to eliminate trailing newlines. You can also use join to concatenate the array elements with a specified separator. Here's how I might do it:
#!/usr/bin/perl use strict; use warnings; use feature qw/say/; chomp(my @fields = <DATA>); my $table_fieldname_array = "('" . join("','", @fields) . "')"; say $table_fieldname_array; __DATA__ FIELD1 FIELD2 FIELDN
This outputs:
$ perl 1117442.pl ('FIELD1','FIELD2','FIELDN') $
Which I gather is what you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: wrap contents of an array in single quotes separated by comma
by perl197 (Novice) on Feb 21, 2015 at 17:57 UTC |