D
D
DimDimuch2018-05-23 11:18:54
Perl
DimDimuch, 2018-05-23 11:18:54

How to delete everything after the last character in a text file?

Can you please tell me how to delete everything after the last character (.) in a text file using perl?
For example, there is a file 1.txt
In it:
gkjgklgn.jmnmmm.44444.55555.66666\hyjjkjmh
total should be:
gkjgklgn.jmnmmm.44444.55555

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2018-05-23
@pcdesign

$string = "gkjgklgn.jmnmmm.44444.55555.66666\hyjjkjmh";
print substr($string, 0, rindex($string, "."));

D
DimDimuch, 2018-05-23
@DimDimuch

And if the line "gkjgklgn.jmnmmm.44444.55555.66666\hyjjkjmh";
is in the file itself 1.txt
How to specify the file in the Perl script, and not the line?
Since the contents of the 1.txt file may change

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question