m/ and s/

i would like to take each element in @commands replace xxx in $fileName, and store that new value in $newFileName.
Then use  $newFileName to create a new empty file in the current directory.
example: komlaaa.1.regularFile.xxx.input -----------> komlaaa.1.regularFile.td.input  -----means xxx is td
               komlaaa.1.regularFile.xxx.input -----------> komlaaa.1.regularFile.tdc.input  -----means xxx is tdc
and so on...


===================== I START IT AND THEN I STOCK ==========================
#!/usr/local/bin/perl

$fileName = komlaaa.1.regularFile.xxx.input;
@commands =  qw/ l t d c lt lc td tc dc ltd ldc tdc ltdc /;
foreach $com (@command){
    ($file=$_) =~ m/xxx/$fileName/
komlaaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
use strict;
my $fileName = 'komlaaa.1.regularFile.xxx.input';
my @commands =  qw/ l t d c lt lc td tc dc ltd ldc tdc ltdc /;
foreach my $com (@commands){
    (my $file=$fileName) =~ s/xxx/$com/;
    print $file,"\n";
}
0
rj2Commented:
#!/usr/local/bin/perl

$fileName = 'komlaaa.1.regularFile.xxx.input';
@commands =  qw/ l t d c lt lc td tc dc ltd ldc tdc ltdc /;
foreach $com (@commands){
    $newFileName=$fileName;
    $newFileName=~s/xxx/$com/;
    print "Creating file $newFileName\n";
    open(FILE,">$newFileName") || die("Can not open file $newFileName because $!");
    print FILE "";
    close(FILE);
}    
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manav_mathurCommented:
komlaa

#!/usr/local/bin/perl
use strict;
use warnings;
my $fileName = "komlaaa.1.regularFile.xxx.input" ;
my @commands =  qw/ l t d c lt lc td tc dc ltd ldc tdc ltdc /;
my $com ;
foreach $com (@commands){
      my $tempfile = $fileName ;
                $tempfile =~ s/xxx/$com/g ;
      system ("touch $tempfile") ;
}

Should work for you

Cheers
Manav
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ITcrowCommented:
Manav, touch is not going to work for windoz. I instead used open for write and close.

======================================================
$prefix = "komlaaa.1.regularFile";
$suffix  = "input";
my @commands =  qw/ l t d c lt lc td tc dc ltd ldc tdc ltdc /;
open(F, ">$prefix.$_.$suffix") && close(F) foreach( @commands );
======================================================
0
ITcrowCommented:
Manav, Just noticed original poster has used /usr/local/bin/perl which gives an indication that question poster may be on *nix. So your solution works as good. Mine is a bit portable, considering that it works the same way on *nix and windoze.
0
manav_mathurCommented:
ITcrow,
Actually I did use touch because of the #!/usr/local/bin/perl :) (Nice way you spell "windoze")
Where's the author of the question??

Ozo, you forgot to open the file.............;)

Manav
0
ITcrowCommented:
Isn't it called Windoze, hmm... it's been a while may be I should go check M$ again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.