My question to you perl experts is this: would it be possible to assign a particular result if it doesnt find a match? Would it be better to use something else besides the matching operator? Is there an operator to state if nothing matches? I have a list of users stored in an array called @names(20 names) in this format "MANDERSON/Anderson MikeD|MikeD.Anderson\\". @cdwv_list has a list of 10 names stored with this format "MANDERSON". Here is an example of the code:
for ($j = 0; $j < @cdwv_list; $j++) {
$user_id = $cdwv_list[$j];
foreach $names(@names) {
if ($names =~ $user_id) {
#if match I want it to grab name
$names =~ /\/([\w\s]+)\|/;
$name = $1;
}
#So what do I put here or somewhere else if
#the 1st $name doesnt match any of the 10
#users from @cdwv_list? I tried:
else {
#But it only prints this 10 times
#even thought only 1 name doesnt
#match between the two list
print "Name does not exist\n";
}
}
}
Thanks in advance....
Thomas
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|