Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

super simple expression

Status
Not open for further replies.

EchoCola

Programmer
Apr 13, 2004
48
US
just trying to test if there is an "@" in a string but it doesn't seem to be working because no matter what i put the ouput in the if gets displayed.

Code:
print "Please enter the sender address: \n";
$mailaddy = <STDIN>;
chomp($mailaddy);


if ($maildaddy !~ /\@/){
  	print "The e-mail address entered is $mailaddy\n ";
 
the crux of your problem is mailaddy then mail[red]d[/red]addy

Code:
#!/usr/bin/perl

print "Please enter the sender address: ";

chomp ($mailaddy = <STDIN>);

if ($mailaddy =~ /@/) {
  print "The e-mail address entered is $mailaddy\n";
}


Kind Regards
Duncan
 
EchoCola,

Change your code to the to the following:

Code:
print "Please enter the sender address: \n";
$mailaddy = <STDIN>;
chomp($mailaddy);

if ([COLOR=red][b]$mailaddy[/b][/color] =~ /\@/){
      print "The e-mail address entered is $mailaddy\n ";
}
 
also notice we both changed:-

!~

to

=~

... I guess that's what you need - i.e. surely you would not want to negate this as you are checking for an @ to verify being an email address?


Kind Regards
Duncan
 
This is the sort of error that using 'strict' and warnings help you to avoid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top