Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Creating comma-delimited lists

by BlaisePascal (Monk)
on Aug 24, 2000 at 00:56 UTC ( [id://29320]=note: print w/replies, xml ) Need Help??


in reply to Creating comma-delimited lists

You could use join ',',@list, but that wouldn't get you the "and" at the end...

Untested code:

@thingsicouldknow = ('this','that','the other','the last thing'); @iknowthat = (0,1,3); #this, that, and last thing # now print the things I know... @thingsiknow = @thingsicouldknow[@iknowthat]; print "I know about " print join(', ',@thingsiknow[0..@thingsiknow-2]); print ", and", @thingsiknow[-1] if @thingsiknow > 1; print ".\n".
It's probably not the best, but it might work. Update:Fixed some off-by-one errors caused by using $#foo

This version should not print the "and" if you only know one thing.

Replies are listed 'Best First'.
RE: Re: Creating comma-delimited lists
by myocom (Deacon) on Aug 24, 2000 at 01:09 UTC

    I'm not sure I realized, for some reason, that you could do @thingsiknow = @thingsicouldknow[@iknowthat]. Sure beats the heck out of doing a foreach...push deal as I was doing in my script beforehand.

    Thanks for the tip!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found