K Pfeiffer wrote: > > Hi y'all, Hello,
> I have a little script that lets me test some regexes. For example at the > prompt I type in: "\b(The|the)\b". I thought it would be better if I could > also include the slashes and then modifiers such as 'g' and 'i': > "/\bthe\b/i" (for example). > > So I modified it as below: > ----------- > my ($count, $linenumber) = 0; > print "Enter regex (/regex/ ): "; > chomp (my $regex = <STDIN>); > while (<>) { > chomp; > $linenumber++; > if ($regex) { > print "\033[32mLine $linenumber: > \033[2;37m$`\033[00m«\033[1;33m$&\033[00m\033[00m»\033[2;37m$'\033[00m\n"; > $count++ > } > } > print "Matches found: $count\n"; > ----------- > > BUT it doesn't work. I get the "use of uninitialized value in concatenation > or string..." error for each line and an empty search result «». > > The old code was simply "if (/$regex/)..." and that works fine. But if I > take the slashes out and then type them in on the command line with the > rest of the regex it fails. $regex is just a string unless you use the // delimiters or use it in a context that will convert it to a regular expression. if ( $regex ) { # is the string true in a boolean context? if ( /$regex/ ) { # convert the string to a regex and bind it to $_ if ( $_ =~ $regex ) { # convert the string to a regex and bind it to $_ If you want to include options like /i you will have to use an extended pattern like "\b(?i:the)\b" or "\b(?i)the\b". John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]