Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RE: Creating comma-delimited lists

by Boogman (Scribe)
on Aug 24, 2000 at 00:55 UTC ( [id://29318]=note: print w/replies, xml ) Need Help??


in reply to Creating comma-delimited lists

Hows this...
sub iknow { if ( @_ > 1 ) { print "I know about ", join( ', ', @_[0 .. @_ - 2] ), ", and $_[-1].\n"; } elsif ( @_ == 1 ) { print "I know about @_.\n"; } else { print "I don't know bout nuthin.\n"; } }
Update: Oh, and if you just wanted to have it print certain elements, just pass it an array slice. For example,
my @array = ( one, two, three, four, five ); iknow( @array[1, 3, 5] );
should print out "I know about one, three, and five."

Replies are listed 'Best First'.
Aha!
by myocom (Deacon) on Aug 24, 2000 at 01:05 UTC

    Hey, now, that's the stuff! It was the @_ - 2 and $_[-1] that I couldn't quite pull out of the recesses of my brain.

    Thanks much!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found