David Gilden wrote:
Hello,

Hello,

In the following I was thinking it would just print out: "Hello"

#!/usr/bin/perl -w

$S = "Hello, Perl!";

($R) = grep {/\w+/} $S;

grep() filters lists so if an element of the list on the right contains \w+ it will be passed through to the left but other elements will be filtered out. Since you are dealing with scalars you want something like:


my ( $R ) = $S =~ /(\w+)/;

Or:

my $R;
$R = $1 if $S =~ /(\w+)/;

Or:

$S =~ /(\w+)/ and my $R = $1;


print "$R\n";


I am trying for some sort of inline filtering so I can do the following:

#!/usr/bin/perl -w use CGI qw/:standard/;
use strict;


my $page =  grep {/\w{1,50}/i} param('page');
# only allow $page to contain 1-50 of [a-z0-9_]

my ( $page ) = param( 'page' ) =~ /(\w{1,50})/;



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to