Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Removing digits until you see | in a string

by inman (Curate)
on Jan 08, 2007 at 09:31 UTC ( #593492=note: print w/replies, xml ) Need Help??


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

A couple of suggestions. The following uses a substituation and removes the index from the rest of the data (i.e. the original data is changed).
$data_hash{$1}= $str if $str =~ s/(\d+)\|//;
This uses matches the index and remaing data without altering the original.
$data_hash{$1}= $2 if $str =~ /(\d+)\|(.*)$/;
I have used a conditional to assess the validity of the assignment beforehand. This is useful for data processing where the quality of the data is variable.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://593492]
help
Chatterbox?
[1nickt]: watcha marto
[Discipulus]: good morning marto, 1nickt for you the sky is still black, no?
[Corion]: Hi all ;)
[1nickt]: just turning grey
[virtualsue]: likely to be grey here all day judging by the forecast
[1nickt]: The deer are in the back garden looking for corn left over from yesterday; the birds are not yet making a commotion. There is frost on the ground.
[1nickt]: virtualsue how's the retatching going?
[1nickt]: rethatching

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-11-21 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (297 votes). Check out past polls.

    Notices?