-5

I want to compare a string in perl below is detail description

original string

../db/proj/upload/1/22352/eng_wall_paper.jpg

I need to extract the file name eng_wall_paper.jpg from the string and compare it with variable and append the new variable to the string.

new required string

../db/proj/upload/1/22352/new string.jpg

how can it be done, thanks in advance .

Syntax Error
  • 4,475
  • 2
  • 22
  • 33
rss
  • 23
  • 8
  • 5
    First put what code you have done or what research you have done. – Praveen Nov 08 '14 at 05:01
  • This is a fairly straightforward regular expression task. However the purpose of SO is not to do it for you, but help you do it for yourself. To that end, and example of what you've got so far is important - and ideally some detailed specifications of what you're expecting to change. – Sobrique Nov 08 '14 at 08:08

1 Answers1

0

Now as you can see in the comment in your question that you really need to be specific about where you are actually stuck in to ask a question in SO. However, after looking at your other questions in SO it looks like you are completely new in programming world and need serious helping hand. Hence I think it would be helpful for you to get some useful reference to solve your problem.

If I breakdown your main problem statement I can see three parts

1. Need to extract the file name, Most recommended way to do it is using File::Basename. However, its possible to use regex too. You need to learn how to write regex and how to capture a group. This link should be really helpful.

2. Compare it with variable, Whichever method you use from above you should get the filename in a variable or in $1. Just compare that whatever you want to compare with. Make sure to use eq instead of ==. Find more details here.

3. Append the new variable to the string, By now you should have the old filename in a variable, say $oldname, from first step and the new filename in another variable, say $newfilename. This question is already answered several times in SO, like this one. Hope that helps.

The actual solution is merely a 3 or 4 lines of code which I want you to figure out. Good luck.

Community
  • 1
  • 1
Samiron
  • 5,169
  • 2
  • 28
  • 55