Which statement is "better", and why?

T

Trebor A. Rude

I'm new to Perl (although I have about 7 years of C++ experience), and I was
just wondering which of these two equivalent statements the group thinks is
"better", and why:

push @command, map {exists $options{$_} ? ($options{$_}, $comments{$_}) :
()} keys %comments;

push @command, map {($options{$_}, $comments{$_})} grep exists $options{$_},
keys %comments;

What I'm doing: I have a hash (%comments) of comments from an ogg file and I
want to construct a command to pass to system() that will set the same tags
in an mp3 file (using the "id3v2" command-line program). The ogg will
typically have more tags in it than id3v2 can handle, so I need to select
just those comments that have equivalents in id3v2 tags (I've set them up
in the %options hash, with the ogg tag as the key and command-line switch
for the id3v2 program as the value). Both statements above do just that,
but I was wondering what the advantages and disadvantages of each are.

Trebor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top