RE: Perl Script

by "Shaun L. Sides" <arch(at)charter.net>

 Date:  Wed, 28 Jun 2000 17:09:28 -0400
 To:  hwg-languages(at)hwg.org
 In-Reply-To:  network
  todo: View Thread, Original
-----BEGIN PGP SIGNED MESSAGE-----

On 28 Jun 2000, at 11:25, Peter Benoit wrote:

> so....
> 
> s/(\d{3})(\d{3})(\d{4})/\($1\)-$2-$3/;
> 
> s/ stuff to split / format to present /  ??

Close.  s/// is substitute, though, not split.  split() is for splitting.

> would be split the stuff according to the rules within?  IE
> (\d{3}) is the first three digits?  Would \d{3} work as well?  What
> are the parens for? 

The parens allow the enclosed portion of the pattern to be stored in 
a built-in variable, so that they can be referenced later.  The first () 
in a regex can be referenced as $1, the second as $2, and so on.

> I'm assuming after the second / the \( with the "\" being an
> escape character?  If it's an escape character, are parans special
> chars that need escaping when used literally? 

Yes, that's right.  Several characters ((, ), \, $, ^, and others) have 
to be escaped before they can be used literally in a pattern.

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.2 -- QDPGP 2.61a
Comment: http://community.wow.net/grt/qdpgp.html

iQCVAwUBOVppiCEw9uEAOtM/AQEq1AP+LsvzPO/SApqfLUWs40fqpeuUfxdBINt5
lEMFm31vJ6kL3iWE3a4Trcg1N1KGBYCALfmTbuE2C5MtwJO6mC17qgTtfLe0Wfec
2rmINfDKlA34ZhChjOwpD4Q3idyuQRTVpB3R/+tq52c8GCuGxX73TCp3zDaBmm3c
dkHDPeFjMrc=
=kEb4
-----END PGP SIGNATURE-----

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.