문제

I have a string like this $data = .|abc|bcd|cde|.

I need the string like this : abc|bcd|cde.

So I do :

$data =~ s/\|$//; # trim the last '|' out... $data =~ s/^\.| +//gm ; #trim '.' in the begining $data =~ s/^\|//; # trim '|' in the begining

But the problem I am facing is, the script is taking too long to execute. Is there any way to complete the whole operation with a single command ??

(Also tried chop($data) but that takes out only the last |)

Please suggest...

도움이 되었습니까?

해결책

$data =~ s/(^[.|]*)|([.|]*$)//g;

That said, I don't assume that this will speed up your script significantly.

다른 팁

Another way: $data =~ s/^\.\|(.*)\|/$1/

But as Rene said, your speed bottleneck is probably somewhere else in your script.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top