Computing.Net > Forums > Programming > Perl Search, small script - Help ??

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl Search, small script - Help ??

Reply to Message Icon

Name: The Right DJ
Date: April 27, 2002 at 13:24:14 Pacific
Comment:

I am using a small perl script function, where the following values exist:

$SEARCH - user input to search for
$RECORD - A line of data in a flat text file
$FIELD - Each Record line has delimited fields, fname, lname, add, phone, etc.

I know this is a simple function, but can't seem to find the right syntax.

What "IF" statement do I use to find out if ($FNAME = "Michael";) contains ($SEARCH = "M";)

I don't care WHERE the string maybe found, just that it's in somewhere in $FNAME.

Can someone please show me the "IF" statement I would write for this ?

Thank YOU very MUCH in advance~!

- Michael McKenzie
Please email michael@therightdj.com



Sponsored Link
Ads by Google

Response Number 1
Name: Tom
Date: April 27, 2002 at 13:46:44 Pacific
Reply:

if($FNAME =~ /$SEARCH/)


0

Response Number 2
Name: The Right DJ
Date: April 27, 2002 at 13:57:37 Pacific
Reply:

THANK YOU SO MUCH~!

Works like a charm. I knew it had something to do with /$SEARCH/ but couldn't get the right syntax.

Thanks again.

Michael


0

Response Number 3
Name: The Right DJ
Date: April 27, 2002 at 14:14:05 Pacific
Reply:

Next Search Question :0

Thanks for you help and I appreciate your response, I had just one more question.

If I search for a Full Name the values are added together with the "+" example:

$FULLNAME = "michael+mckenzie";

This will not match any of my data in $RECORD or $FIELD as everything is input without "+" signs. How do either add the "+" to my data on the fly as it searches, or REMOVE the "+" from my $SEARCH as it looks for the comparison ?

Thanks again~!

- Michael McKenzie


0

Response Number 4
Name: Tom
Date: April 27, 2002 at 16:43:53 Pacific
Reply:

$FULLNAME =~ s/\+/\s/g;
That will substitute all occurences of + with a space. The g at the end means global, and will cause it to substitute all +'s, rather than just the first one it finds.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl Search, small script - Help ??

Script help - New line and character removal? www.computing.net/answers/programming/script-help-new-line-and-character-removal/19883.html

Perl, inefficient script.HELP! www.computing.net/answers/programming/perl-inefficient-scripthelp/14807.html

perl script help www.computing.net/answers/programming/perl-script-help/7901.html