I'd suggest you use the
map function.
Properly, MAP allows you, amongst other things, to cast a regexp on $_ for each list element (I'd call it ARRAY in this case).
Please refer to previous posts about regexp, whereas with map here you can simplify all syntax needed in one line.
#!usr/bin/perl
### Search through the users
@vararray= ('andrew', 'andrews', 'test', 'AnDre', 'HAHAhahAndrEXXXSh
+owtonite', 'AndreaLovesPr0n','Tony', 'Perlmonks');
=comment
foreach $user (@list) {
if(param('search') =~ /$user/) {
print "$user<br>";
}
}
=cut
$varregexp= 'andre';
#this is just for finding the number of matches
$varmapresults= 0;
$varmapresults= map (/$varregexp/i, @vararray);
#get the actual values. A simple regexp returns the NUMBER of matche
+s, hence the IF statement between brackets
@varmapresultsarray= map {$_ if $_=~ /$varregexp/i} @vararray;
print "\nHell-llo n-nurse!: $varmapresults times";
print "\nDo what you want with me!: @varmapresultsarray";
The slickness of the MAP function will be very useful in your future!
____________________
$ i |\/| |° £ i f '/
I know MU, hence I can only learn
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.