Hi I am ABHI
i want to substitute 19-13-10-456765 to 19*10 + 13*5 + 10 is equal to (265) in file
i want to know the exact code to do that
this is the file content xyz.txt

19-10-13-400922 TID1-3039 1RequestREGISTER
19-10-13-405432 TID1-3039 1Response100
19-10-13-410015 TID1-3039 1Response401
19-10-13-415481 TID1-3039 2RequestREGISTER
19-10-13-419800 TID1-3039 2Response100
19-10-13-426400 TID2-3039 1RequestREGISTER
19-10-13-463320 TID3-3039 1RequestREGISTER
19-10-13-514112 TID4-3039 1RequestREGISTER

here my code but i dont know where i m doing mistake ,,,plz your early help welcome

#!perl -w

use strict;
use warnings;

open(INPUT, "<time.txt");



while (<INPUT>) {

    s/(\d\d)-(\d\d)-(\d\d)-(\d\d\d\d\d\d)/ $1*3600 + $2*60 + $3/e;    
##print OUT "$n: $line";
    }

close INPUT;

thanks in advance

use strict;
use warnings;

open (FIN, "time.txt")|| die "Cannot Open the input file : $!";
read FIN, my $file, -s FIN;
close (FIN);

$file=~s/(\d+)-(\d+)-(\d+)/$1*3600 + $2*60 + $3/ge;

open (FOUT, ">Out_time.txt") || die "Cannot create the output file : $!";
print FOUT $file;
close (FOUT);

thanks for your early response
but its not working .....after compilation no error but the time.txt is not modified
:(

use strict;
use warnings;

open (FIN, "time.txt")|| die "Cannot Open the input file : $!";
read FIN, my $file, -s FIN;
close (FIN);

$file=~s/(\d+)-(\d+)-(\d+)/$1*3600 + $2*60 + $3/ge;

open (FOUT, ">Out_time.txt") || die "Cannot create the output file : $!";
print FOUT $file;
close (FOUT);

this code highlighting in pink color as i mentioned as bold

open (FOUT, ">Out_time.txt") || die "Cannot create the output file : $!";

The updated contents are having the 'Out_time.txt' file. Check the file. if you want to update the contents in the same file, change the file filename in the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.