home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _1ada04b8dda68f596ae638b090b62a6c < prev    next >
Text File  |  2000-03-23  |  5KB  |  108 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>re - Perl pragma to alter regular expression behaviour</TITLE>
  5. <LINK REL="stylesheet" HREF="../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> re - Perl pragma to alter regular expression behaviour</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25. </UL>
  26. <!-- INDEX END -->
  27.  
  28. <HR>
  29. <P>
  30. <H1><A NAME="name">NAME</A></H1>
  31. <P>re - Perl pragma to alter regular expression behaviour</P>
  32. <P>
  33. <HR>
  34. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  35. <UL>
  36. <LI>Linux</LI>
  37. <LI>Solaris</LI>
  38. <LI>Windows</LI>
  39. </UL>
  40. <HR>
  41. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  42. <PRE>
  43.     use re 'taint';
  44.     ($x) = ($^X =~ /^(.*)$/s);     # $x is tainted here</PRE>
  45. <PRE>
  46.     $pat = '(?{ $foo = 1 })';
  47.     use re 'eval';
  48.     /foo${pat}bar/;                # won't fail (when not under -T switch)</PRE>
  49. <PRE>
  50.     {
  51.         no re 'taint';             # the default
  52.         ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here</PRE>
  53. <PRE>
  54.         no re 'eval';              # the default
  55.         /foo${pat}bar/;            # disallowed (with or without -T switch)
  56.     }</PRE>
  57. <PRE>
  58.     use re 'debug';                # NOT lexically scoped (as others are)
  59.     /^(.*)$/s;                     # output debugging info during
  60.                                    #     compile and run time</PRE>
  61. <PRE>
  62.     use re 'debugcolor';           # same as 'debug', but with colored output
  63.     ...</PRE>
  64. <P>(We use $^X in these examples because it's tainted by default.)</P>
  65. <P>
  66. <HR>
  67. <H1><A NAME="description">DESCRIPTION</A></H1>
  68. <P>When <CODE>use re 'taint'</CODE> is in effect, and a tainted string is the target
  69. of a regex, the regex memories (or values returned by the m// operator
  70. in list context) are tainted.  This feature is useful when regex operations
  71. on tainted data aren't meant to extract safe substrings, but to perform
  72. other transformations.</P>
  73. <P>When <CODE>use re 'eval'</CODE> is in effect, a regex is allowed to contain
  74. <CODE>(?{ ... })</CODE> zero-width assertions even if regular expression contains
  75. variable interpolation.  That is normally disallowed, since it is a 
  76. potential security risk.  Note that this pragma is ignored when the regular
  77. expression is obtained from tainted data, i.e.  evaluation is always
  78. disallowed with tainted regular expresssions.  See <A HREF="../lib/Pod/perlre.html#({ code })">(?{ code }) in the perlre manpage</A>.</P>
  79. <P>For the purpose of this pragma, interpolation of precompiled regular 
  80. expressions (i.e., the result of <CODE>qr//</CODE>) is <EM>not</EM> considered variable
  81. interpolation.  Thus:</P>
  82. <PRE>
  83.     /foo${pat}bar/</PRE>
  84. <P><EM>is</EM> allowed if $pat is a precompiled regular expression, even 
  85. if $pat contains <CODE>(?{ ... })</CODE> assertions.</P>
  86. <P>When <CODE>use re 'debug'</CODE> is in effect, perl emits debugging messages when 
  87. compiling and using regular expressions.  The output is the same as that
  88. obtained by running a <CODE>-DDEBUGGING</CODE>-enabled perl interpreter with the
  89. <STRONG>-Dr</STRONG> switch. It may be quite voluminous depending on the complexity
  90. of the match.  Using <CODE>debugcolor</CODE> instead of <CODE>debug</CODE> enables a
  91. form of output that can be used to get a colorful display on terminals
  92. that understand termcap color sequences.  Set <CODE>$ENV{PERL_RE_TC}</CODE> to a
  93. comma-separated list of <CODE>termcap</CODE> properties to use for highlighting
  94. strings on/off, pre-point part on/off.  
  95. See <A HREF="../lib/Pod/perldebug.html#debugging regular expressions">Debugging regular expressions in the perldebug manpage</A> for additional info.</P>
  96. <P>The directive <CODE>use re 'debug'</CODE> is <EM>not lexically scoped</EM>, as the
  97. other directives are.  It has both compile-time and run-time effects.</P>
  98. <P>See <A HREF="../lib/Pod/perlmodlib.html#pragmatic modules">Pragmatic Modules in the perlmodlib manpage</A>.</P>
  99. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  100. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  101. <STRONG><P CLASS=block> re - Perl pragma to alter regular expression behaviour</P></STRONG>
  102. </TD></TR>
  103. </TABLE>
  104.  
  105. </BODY>
  106.  
  107. </HTML>
  108.