You will have to change trains in Perpingnan because Spanish and French trains use different gauges. It is a LONG train ride - around 20 hours (I've done it). If you really enjoy the train and have the excess time or can do overnight (saves you youth hostel cost for a night) go that way. Otherwise, fly. There are lots of low cost airlines