Sex is a very essential part of life. Its a basic need like food. One can live without food and sex, but not for ever.
You are just 23 and you are in sexual prime of life, so you are bound to have more sexual feelings. These feelings have habit of cropping up at odd times like during studies, in libraries, during conversations with friends etc.
Rather than getting distracted by it, talk to your body and say : i respect that my body has a desire for sex, but NOW it is not the right time, and i will look at this need when the right time and place if available" This will take your mind off the erection and you will be able to get on with your work or study.
When you are alone in your room, try NOT to use the porn for sexual arousal. Human mind can fantasize and this can cause arousal and erection. rather than making porn give you erections, have erections thinking of sex, by fantasy.
Porn has a big problem of "hedonistic adaptation" A typical porn watcher, sees porn when it s available or when he is alone, and this makes him see porn when he is NOT desirous of sex. This causes clashes and makes the person slowly dependent on porn for arousal.
Porn also makes a person get used to it soon and the pleasure that it brings then makes the person hunt for more exotic varieties of porn from multi partner sex to group sex, to pissing, fisting etc.....thus unknowingly the person sets a higher bar for his arousal and this may create problem with his REAL sex life as our partners are NOT porn starts and they don't do things which porn stars do.
Next Steps
Dont avoid masturbation. Use fantasy to get aroused, or masturbation when you have sexual feelings and privacy. Dont make it a habit to masturbate daily before sleeping or at bathing. This will make you habitual to it. Masturbate 2-3 times a week with gaps between them so as to not "Binge" on it and keep sex alive in your mind by fantasy and not porn