hary536 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Friends, This is my first post and I just recently started coding in Perl.
I am trying to remove some characters from a file in a pattern described below. I have accomplished the goal, but it takes two lines of code. I am wondering, if this can be reduced to a single line.
I have a file with a single line in it as follows: /Users/name/Desktop/Reprocess_120509_171210/Name1/Name2/RDLy_XXXX_2012_03_25_1850.ruv I am trying to modify this line so that I have only RDLy_XXXX_2012_03_25_1850 remaining, which I am then going to use as a name for a picture file by appending .png to the above name. Here is what I did:I am wondering, can the above substitution task(of 2 lines) be accomplished in a single line? If yes, how? Thanks a lot in advance.open (FIDR, "< $radFile"); chomp($basename = <FIDR>); $basename =~ s/\S*RDL/RDL/; ## this removes everything before RDL but +has ".ruv"extension $basename =~ s/.ruv$//; ##this removes the .ruv extension.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Substitution or removing characters from a file
by NetWallah (Canon) on May 10, 2012 at 03:19 UTC | |
by hary536 (Novice) on May 17, 2012 at 22:59 UTC | |
Re: Substitution or removing characters from a file
by JavaFan (Canon) on May 10, 2012 at 06:37 UTC | |
by Anonymous Monk on May 17, 2012 at 22:58 UTC | |
by hary536 (Novice) on May 17, 2012 at 23:02 UTC | |
Re: Substitution or removing characters from a file
by jwkrahn (Abbot) on May 10, 2012 at 04:02 UTC | |
by hary536 (Novice) on May 17, 2012 at 23:01 UTC |