PDA

View Full Version : grep question


skipion
03-23-2006, 09:21 PM
I use these lines:

#!/usr/bin/perl
@list=("this is","my","text");
$find="t";
@found=grep(/$find/,@list);
print @found;


to check if the content of $find occurs in the array @list. It seems to work fine. Now I wanna do the following:

The visitor of a site fills in a textbox with words seperated by comma's..like this:

hello, my name, is mark, nice, to meet, you

then I want my script to place all those words in the array @list (see script). But I havent got a clue how to do this.

nkrgupta
03-24-2006, 06:03 AM
#!/usr/bin/perl

use CGI qw(:standard);
use strict;

print "(anti-spam-(anti-spam-content-type:))text/htmlnn"; ## Replace the header with the correct one -- security measures of vB

my $list=param('text');

my @list=("this is","my","text");

if ($list) {
push @list, $list;
print "@list";
}
else{
print qq{<form method='post' action="$ENV{'SCRIPT_NAME'}"><input type='text' name='text'><input type='submit' value='Submit'></form>};
}

FishMonger
03-24-2006, 09:23 AM
@list = split ",", param('text');

nkrgupta
03-24-2006, 10:09 AM
Ohh!! I just overlooked the comma part..