Gossamer Forum
Home : General : Perl Programming :

Help with Regular Expression

Quote Reply
Help with Regular Expression
I need help with a regular experssion.
I have my DBman set up so that when users browse by Country from a drop down list it displays a graphic relating to that country.
I'm using the search terms as a reference, which are written to %in, and accessed by $in{'Country'}, so I need to format the country string to call the correct graphic.
By the way, this is my first attempt at a regular expression.
Now i've tried to use $in{'Country"} like this,
$graphic = $in{'Country'}=~regular expression;
the expression being the one I havn't worked out yet, but I carn't seem to return the string no matter what expression I try, only a numeral.
How can I return the Country string from $in{'Country'}.
Also if you can help me out with the regular expression. I,ll give you an example.
Say they select - Antigua & Barbuba, what I need the expression to do is,

1. Remove the blank spaces, if there are any - Antigua&Barbuba
2. Remove the & if there is one - AntiguaBarbuba
3. Return the string in lowercase - antiguabarbuba
4. Return say no more then 10 charactors - antiguabar

thanks
Bob
Quote Reply
Re: Help with Regular Expression In reply to
Code:
$string =~ s, ,,g;
$string =~ s,&,,g;
$string = lc $string;
$string = substr(0,10,$string) if (length($string) > 10);

jerry
Quote Reply
Re: Help with Regular Expression In reply to
Jerry, thanks for your help.
This almost works,
Code:
$in{'Country'} =~ s, ,,g;
$in{'Country'} =~ s,&,,g;
$in{'Country'} = lc $in{'Country'};
$in{'Country'} = substr(0,10,$in{'Country'}) if (length($in{'Country'}) > 10);
print qq|$in{'Country'}|;
but It will only return strings of less than 10 charactors.
if you change > to < it will only print strings of more than 10 charactors.
Is there another way to limit the string to 10 charactors that you know of.

Thanks
Bob
Quote Reply
Re: Help with Regular Expression In reply to
an equal sign does work ==, or =
Quote Reply
Re: Help with Regular Expression In reply to
Perhaps try something like this:
Code:
$ic = lc($in{'Country'});
$ic =~ s/[ &]//g;
$ic = substr($ic, 0, 10) if (length($ic) > 10);

-- Gordon --


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);

Quote Reply
Re: Help with Regular Expression In reply to
Thanks Gordon, that works.

Bob