parsing a string

M

marie

I have a string for example "perl878juio"

I want to cut off everthing beginning with the first number, so I would
be left with "perl"

Is there a simply way to do this?
 
P

Paul Lalli

marie said:
I have a string for example "perl878juio"

I want to cut off everthing beginning with the first number, so I would
be left with "perl"

Is there a simply way to do this?

Yes.

Use a regular expression and the s/// operator. Search for a digit
followed by "anything", and replace with nothing.

Read `perldoc perlretut` to get you started with doing this. Once you
make your attempt, feel free to post a short-but-complete script here
if it does not work to your satisfaction.

Paul Lalli
 
J

John W. Krahn

marie said:
I have a string for example "perl878juio"

I want to cut off everthing beginning with the first number, so I would
be left with "perl"

Is there a simply way to do this?

$ perl -le'$_ = q[perl878juio]; print; s/\d.*//; print'
perl878juio
perl



John
 
T

Tad McClellan

marie said:
I have a string for example "perl878juio"

I want to cut off everthing beginning with the first number, so I would
be left with "perl"

Is there a simply way to do this?


Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top