Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Removing digits until you see | in a string

by quester (Vicar)
on Jan 08, 2007 at 05:07 UTC ( [id://593477]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593477]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-19 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found