in reply to Re: Copying files from one file to another file
in thread Copying files from one file to another file

What is the name of the files you want the values saved to ?

#!/usr/bin/perl use strict; use warnings; my %hash=(); # input my $inputfile = 'nv.txt'; open IN, '<',$inputfile or die "Could not open $inputfile : $!"; while (<IN>) { my ($key, $val) = split (/:/,$_,2); $hash{$key} .= $val; } # output for my $key (keys %hash){ my $outputfile = "output_$key"; $outputfile =~ s{/}{-}g; print "Writing to $outputfile\n"; open OUT,'>',$outputfile or die "Could not open $outputfile : $!"; print OUT $hash{$key}; close OUT; } __DATA__ test/right/case1:12: //comment test/right/case1:344: //comment test/wrong/case3:123: //comment
poj

Replies are listed 'Best First'.
Re^3: Copying files from one file to another file
by harishnv (Sexton) on Feb 20, 2018 at 11:03 UTC

    I want to save each key in one text file having the key-value's in each text file.

      key-value's in each text file.

      Yes but what is the name of that text file, is it the same as the key ?

        if I can give different names, tel me or else key will do it. I want to save these output files in one directory also. how to do it? I checked with your code, it worked thanks a lot.

      how to create only "right" or "wrong" as filenames? and save them in one directory? thanks for the help