Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
Replies are listed 'Best First'.
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 exploiting the Monastery: (12)
As of 2015-07-30 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls