using Perl to find string..

S

seanjao

Hi there:

I would like to use Perl to search a file containing data like the
following.
aaa01234 99.99 99.99 99.99
bb0567 99.99 99.99 99.99
ccccc89101 99.99 99.99 99.99

How can I let perl to match the first column if I type "bb567" without
the zero between "bb" and "567"?

Thanks
Sean
 
J

Josef Moellers

Glenn said:
At said:
Hi there:

I would like to use Perl to search a file containing data like the
following.
aaa01234 99.99 99.99 99.99
bb0567 99.99 99.99 99.99
ccccc89101 99.99 99.99 99.99

How can I let perl to match the first column if I type "bb567" without
the zero between "bb" and "567"?


Based on these requirements:

my $wanted = 'bb567';

while (<DATA>) {
if (/^$wanted\b/) {
print 'exact match >> ';
}
elsif (/^([a-z]+)0+(\d+)/ and $wanted eq "$1$2") {

Based on the requirements "without *the* zero", that would be
elsif (/^([a-z]+)0?(\d+)/ and $wanted eq "$1$2") {

Personally, I would have made that
elsif (/^([a-z]+)0*(\d+)/ and $wanted eq "$1$2")

Josef
 
S

seanjao

Josef said:
For what?


What helps?

Please quote whatever you are replying to!

Thank you,

Josef
Hey Josef:

I think I am polite enough to express my appreciaton to all the
thoughts I got.
Of course, including your thought.
Why do I need to specifically to quote anything?
Think about it, man.
For what?
For their time and efforts to help someone he/she does not know.
Understand?

Sean
 
P

Paul Lalli

Hey Josef:

I think I am polite enough

.... there's some irony...
to express my appreciaton to all the thoughts I got.
Of course, including your thought.
Why do I need to specifically to quote anything?
Think about it, man.

Please do some thinking of your own. Not everyone reads a newsgroup
with threadding enabled. Even those of us who do are not guaranteed to
have seen the post to which you are replying. It's entirely possible
that your "thanks" showed up before the posts to which you're replying,
or that the posts to which you're replying simply never showed up at
all. That's how Usenet works. And that's why it's been standard
convention to quote material to which you're replying for *decades*.

Please do a bit of reasearch into what you're talking about before
accusing someone far more familiar with the medium of not thinking.

Paul Lalli
 
S

seanjao

And that's why it's been standard
convention to quote material to which you're replying for *decades*.

If so, please let an experienced user, like you to show me how to
express my appreciation
to all of the thoughts posted for this topic.

Thank you.
Sean Jao
 
T

Ted Zlatanov

If so, please let an experienced user, like you to show me how to
express my appreciation to all of the thoughts posted for this
topic.

Next time you reply with "thanks" make sure to quote enough so that a
random person could look at your message by itself and understand
what's happening. Welcome to comp.lang.perl.misc :)

Ted
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top