Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Converting an index record array into a comma-separated array.

by krujos (Curate)
on Jul 15, 2002 at 15:21 UTC ( #181812=note: print w/ replies, xml ) Need Help??


in reply to Converting an index record array into a comma-separated array.

you could do something like

foreach $element (@array) { $var = $var . $element . ","; }
The dot operator appends, just like the + in java on strings. My example would give you an extra comma, but you could remove it with
$array[@array -1]="";

update added the part about the extra comma


Comment on Re: Converting an index record array into a comma-separated array.
Select or Download Code
Re: Re: Converting an index record array into a comma-separated array.
by Abigail-II (Bishop) on Jul 15, 2002 at 15:49 UTC
    $array[@array -1]="";
    doesn't remove a trailing comma. What it does is replacing the last element of the array with an empty string.

    It's much better to not use an explicite loop, but to use join. Then you don't have to remove any trailing commas either.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://181812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-07-25 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (171 votes), past polls