Perl split and join

Hi,

I have tried the split and join functions but stuck with unexpected results. Any help appreciated. I pass multiple values at command line like perl test.pl -type java,xml . This works good for me but i am not sure how to print it in the required format.

Here is the code i tried:

@file_type = split(/,/,join(" ",@file_type));
print @file_type;

The required output is "\.java \.xml" but it just gives java.

Thanks in advance,
nmattam

Take a look at Getopt::Std for option switch parsing. When you've got the value, all you need is something like this:

$opt_val = 'java,xml';
@out = map { "\\.".$_ } split (/,/, $opt_val);
print "@out\n";
use strict;
use warnings;

my @file_type = split(/,/, $ARGV[1]);
foreach (@file_type) {
    $_ = "\\.".$_;
}

print join(" ", @file_type), "\n";

pludi,

Your solution works good for me. I would request you if the output can be "\.java \.xml". I want " " to be included in the output and not just \.java \.xml

Thanks much for the help.

nmattam

Honestly, that question goes beyond "I need help with a problem" and enters the "I don't want to think for myself" realm. Experiment! Try things! That's the best way to learn.