Ittiam Systems Interview Question for Software Trainees


Team: dsfgfds
Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

re.compile("^[a-zA-Z][\w]*@[\w]+\.[a-zA-z]+$")

- gnahzy August 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is a "return function" in perl?

- Anonymous August 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The return value of any block, including those used in subroutines, is taken as the value of the last evaluated expression. For exampl,e the return value here is the result of the calculation.:

sub myfunc
{
$_[0]+$_[1];
}

You can also explicitly return a value using the return keyword:

sub myfunc
{
if (@_)
{
return $_[0]+$_[1];
}
else
{
return 0;
}
}

When called, return immediately terminates the current subroutine and returns the value to the caller. If you don't specify a value then the return value is undef.

- Anonymous August 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simplest way is to [a-zA-Z0-9][a-zA-Z0-9\.\-_]*@[a-zA-Z0-9]\.(com|ca|com\.uk|...)

Validating email addresses isn't easily verifiable using regex. Even if it's considered invalid according to the RFC standard, the rules on some SMTP/IMAP servers vary so much, it's much easier just to send a email verification link to that email. (Which is what most software does. OAuth mitigates this terribly inconsistent protocol somewhat.)

- Anonymous September 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actually, while I agree the parsing of email addresses is complex, most of the complexity is in the local part of the name. Also, using \p{IsWord} will match UNICODE characters which are valid in email addresses as well. So, \p{IsWord} is probably prefered over \w or [a-zA-Z] forms. When addressing this kind of problem, I would recommand:

my %extmap = (
com => '',
edu => '',
...,
)
if(! emailValidate("someone@somewhere.somplace") ) {
print "email is not valid\n";
} else {
print "email is vaild\n";
}

sub emailValidate {
my ($email) = @_;
my ($rpt,$hsn) = (split(/\@/,$email);

# email is not valid if there is not a localname and hostname seperated by @
# note, I don't test for multiple @
return (0) if( ! defined $rpt || ! defined $hsn );

# rpt@[1.1.1.1] is valid for email to an IP. However, the regex I provide does not
# really make sure the IP is valid, only that it follows the pattern.
if( $hsn !~ m/^\[(\d{1,3}\.){3}\d{1,3}\]$/ ) {
return(0);
} else {
my $ext;
foreach(split(/\./,$hsn) {
# not perfect, but allows for h@(comment)blah.com or h@blah.com
# also invalidates h@blah..com
if( $_ !~ m/^\w[\w|\d]*$/g || $_ !~ m/^\([\w|\d]+\)\w[\w|\d]*$/ ) {
return(0);
}
$ext = $1; # save last result
}
if( ! exist $extmap{$ext} ) {
return(0);
}
}

# \W is imprecise, but () # \ {} and a host of other character marks are valid.
# A fairly detailed understand of either the RFC or the standards set by
# The local MTA would really be necessary. Things like .. are not allowed but . is.
if( $rpt !~ m/^\p{IsWord}[\p{IsWord}|\d\W]*$/ || $rpt !~ m/^\p{IsWord}[\p{IsWord}|\d\W]*(\(\w\))*$/) {
return(0);
}
return(1);

}

- Henry January 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Below regular expression tested more than 10k email ids

#Assumption emaild id should be start with a letter

print if m/^[a-zA-Z]{1,9}[a-zA-Z0-9]{1,10}([._])?[a-zA-Z0-9]{1,10}@([a-zA-Z]{2,10}\.){1,2}([a-zA-Z]{1,3})$/;
}

- pawan kumar June 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$email = @ARGV[0];

if($email =~ /\w+\@\w+\.\w+|[-]\w+$/)
{
        print "$email is valid\n";
}
else
{
        print "$email is NOT valud\n";
}

- Anonymous June 28, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More