Domanda

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...

È stato utile?

Soluzione

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

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

Altri suggerimenti

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top