in reply to Removing digits until you see | in a string

I can't think of a way to do it with tr, but s will do it:
$index = $str; $index =~ s/\|.*//; $data_hash{$index} = $str;

Replies are listed 'Best First'.
Re^2: Removing digits until you see | in a string
by MaxKlokan (Monk) on Jan 08, 2007 at 09:29 UTC
    The same, but one line shorter :-)
    ($index = $str) =~ s/\|.*//; $data_hash{$index} = $str;
Re^2: Removing digits until you see | in a string
by kevyt (Scribe) on Jan 08, 2007 at 05:18 UTC
    It worked. Thanks
Re^2: Removing digits until you see | in a string
by Animator (Hermit) on Jan 08, 2007 at 12:04 UTC

    That solution is wrong.

    What if the string contains a newline? Or multiple newlines? Anything that follows after the newline will not be removed.

    I could suggest using s/...//s but I'm not going to do that. This code will be slower then it has to be - and it doesn't give the information you want. It just starts removing text from a | until a newline.

    My suggestion is the same as ysth's: Re: Removing digits until you see | in a string