pattern matching with a string variable? 
Author Message
 pattern matching with a string variable?

# Hello,
#
#   question: if  $string  is a string variable for  pattern matching  
#                i.e. $string = "/x/ && /y/"
#             How I use $string for test pattern matching?
#                i.e. if ($_ =~ $string) {....} ????
#
# Small example:
# =============
# Input line
  $_ = "cat dog bird";

# Suppose a logical structure for construct a pattern matching
# here example: /dog/ && /bird/


  $pat1 =~ s/\/\//\/ && \//;                         # substitute // by / && /
  print "pattern 1: ",$pat1,"\n";

# other pattern


  $pat2 =~ s/\/\//\/ && \//;                         # substitute // by / && /
  print "pattern 2: ",$pat2,"\n";

# test for pattern matching
# here, I don't understand: How I use "$pat1" and "$pat2"?

  if ($pat1) {print $_,"\n";}  # ????

  if ($pat2) {print $_,"\n";}  # ????

# Thank you
#
# Gilles Ratel



Thu, 12 Oct 1995 20:04:28 GMT  
 pattern matching with a string variable?

Quote:
>   if ($pat1) {print $_,"\n";}  # ????

>   if ($pat2) {print $_,"\n";}  # ????

Should evaluate the value of $pat1:

if (eval($pat1)) {print $_,"\n";}  # ????

if (eval($pat2)) {print $_,"\n";}  # ????



Wed, 25 Oct 1995 02:36:36 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. pattern matching with string variable?

2. Pattern Match - substitute a string after the match

3. RE match for negative variable pattern

4. Help on pattern matching, string size

5. Variable inside pattern matching

6. pattern matching with non-existence of a string

7. Matching variable patterns

8. Using a variable in pattern matching operator

9. pattern matching with variables

10. Variable matching patterns

11. Pattern matching using variable ...

12. Pattern matching with variables

 

 
Powered by phpBB® Forum Software