<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7779187331106757427</id><updated>2011-09-09T15:41:45.268-07:00</updated><category term='perl regex regular expressions'/><category term='perl template toolkit'/><category term='perl poetry'/><category term='character sets utf8 iso8859-1 ansi windows 1252'/><title type='text'>Cablechip Solutions</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-773898515481051168</id><published>2011-09-09T15:06:00.000-07:00</published><updated>2011-09-09T15:06:00.830-07:00</updated><title type='text'>OS Maps and GPS Data</title><content type='html'>GPS - the global open standard - use latitude and longitude. to identify a point.&lt;br /&gt;&lt;br /&gt;Ordnance Survey Maps use their own systen. The points (e.g. TZ123456), or sometimes given at 6 figure easting and northings (e.g.&amp;nbsp;123456,123456) while user friendly, and&amp;nbsp;easy to locate&amp;nbsp;on the grid superimposed on OS maps, can't easily be be used by satnavs.&lt;br /&gt;&lt;br /&gt;The maps to convert between the 2 systems is rather comples, but we can do it for you..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-773898515481051168?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/773898515481051168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=773898515481051168' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/773898515481051168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/773898515481051168'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2011/09/os-maps-and-gps-data.html' title='OS Maps and GPS Data'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-5740769477049033262</id><published>2008-10-06T07:45:00.000-07:00</published><updated>2008-10-07T01:30:18.432-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='character sets utf8 iso8859-1 ansi windows 1252'/><title type='text'>Character Sets</title><content type='html'>&lt;h1&gt;Definitions&lt;/h1&gt;Character Sets&lt;br /&gt;&lt;ul&gt;&lt;li&gt;A character set in a sequence of characters, each character is represented by a number.&lt;br /&gt;e.g. 65=A, 66=B, 67=C, ... 1234=£, ...&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Examples of character sets are:&lt;br /&gt;ASCII, ISO 8859-1, Windows 1252, ANSI&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Character Encoding&lt;br /&gt;&lt;ul&gt;&lt;li&gt;A character encoding is a means of representing a character set in a file. &lt;/li&gt;&lt;li&gt;For ASCII and Windows 1252 (or ANSI), its easy, 1 byte = 1 character.&lt;/li&gt;&lt;li&gt;For large character sets, with more than 256 characters, it is more complex, as more than 1 byte per character is used.&lt;/li&gt;&lt;li&gt;"UTF-8" uses 1, 2, 3 or 4 bytes per character.&lt;/li&gt;&lt;/ul&gt;Character References in HTML and XML&lt;br /&gt;&lt;ul&gt;&lt;li&gt;An entity reference is of the form:&lt;br /&gt;&amp;amp;quot; &amp;amp;euro; &amp;amp;copy;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;A numeric reference (in HTML and XML) for character 256 is of the form:&lt;br /&gt;&amp;amp;#255; (decimal) or &amp;amp;#xFF; (hexidecimal)&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;Character Sets&lt;/h1&gt;&lt;p&gt;ASCII&lt;/p&gt;&lt;ul&gt;&lt;li&gt;ASCII is the original Character Set, with 128 characters defined. &lt;/li&gt;&lt;li&gt;1 byte = 1 character.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ISO 8859-1&lt;/p&gt;&lt;ul&gt;&lt;li&gt;This is the ISO "Western European" character set. &lt;/li&gt;&lt;li&gt;It is the original "web" character set, and used as the default by older browsers.&lt;/li&gt;&lt;li&gt;ISO 8859-1 is a subset of the larger UCS/Unicode character set (not quite true, but almost)&lt;/li&gt;&lt;li&gt;It is now depreciated (obsolete) - use UTF-8 instead. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Unicode and UCS (Universal Character Set)&lt;/p&gt;&lt;ul&gt;&lt;li&gt;This is a very large character set. It is a combination of the ISO 8859-1 characters,&lt;br /&gt;plus mathematical and other symbols,&lt;br /&gt;plus the Chinese, Hebrew, Japanese, Greek, Thai, Persian and other alphabets.&lt;/li&gt;&lt;li&gt;Some special cases :&lt;br /&gt;- there are spaces reserved for 'user defined' characters,&lt;br /&gt;- some characters can be combined to make composite characters (e.g. Thai)&lt;/li&gt;&lt;li&gt;Unicode/UCS is a character set. It is encoded using UTF-8&lt;/li&gt;&lt;/ul&gt;Windows 1252 / ANSI Character Set&lt;ul&gt;&lt;li&gt;This is the Windows character set.&lt;/li&gt;&lt;li&gt;It is encoded using 1 bytes (0-255) per character.&lt;/li&gt;&lt;li&gt;From 0-127, its the same as ASCII&lt;/li&gt;&lt;li&gt;Between 0x80 and 0x9F there are differences. This is the problem area, as these character positions are 'not defined' in ISO 8859-1 and UTF-8&lt;/li&gt;&lt;li&gt;From 0xA0 and above, its "the same" as ISO 8859-1.&lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;Character Encoding&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;UTF-8&lt;/p&gt;&lt;ul&gt;&lt;li&gt;UTF-8 is actually a character encoding, not a character set. Colloquially, it is now used to mean "Unicode/UCS with the UTF-8 encoding"&lt;/li&gt;&lt;li&gt;Its a means of using 1, 2 , 3 or 4 bytes to store a very large character set.&lt;/li&gt;&lt;li&gt;ASCII characters (0-127) take up 1 byte, so its backwards compatible.&lt;/li&gt;&lt;li&gt;£, maths symbols, Chinese and Japanese characters take up 2, 3 or 4 bytes&lt;/li&gt;&lt;li&gt;Some Windows editors use a 'BOM', a character at the front of a file to indicate that the file contains UTF-8 encoded characters. (Actually, its a 2 byte character that's illegal in UTF-8). Not part of the spec.&lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;Character Set Conversion Problems&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;Whatever you've used in the past, UTF-8 (Unicode/UCS), is the thing to aim for. Google, Blogger etc all use it.&lt;/p&gt;&lt;p&gt;From Windows 1252 / ANSI to the ISO character sets&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If converting text from a Windows file to a web page in ISO format, you may have to map some 'hi byte' characters, e.g. the euro symbol, as the character numbers will not be the same.&lt;/li&gt;&lt;li&gt;If copy-and-past'ing, windows will take care of the conversion for you.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;From ISO 8859-1 to UTF-8/UCS/Unicode&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Viewing a ISO 885901 file in a web browser page set to UTF-8 will display any characters greater than 128 as illegal characters&lt;/li&gt;&lt;li&gt;In terms of character sets, the conversion is straight forward, as there are "no" differences you are likely to encounter.&lt;/li&gt;&lt;li&gt;The character encoding is the problem. Example: In ISO 8859-1, character(165) is stored as binary 165. In UTF-8, it should be 2 bytes. The single byte will be an illegal UTF-8 character.&lt;/li&gt;&lt;li&gt;The solution is programing language dependent or editor dependant. &lt;ul&gt;&lt;li&gt;For example, in the Notepad++ editor, there is a 'convert ANSI to UTF-8' option.&lt;/li&gt;&lt;li&gt;In perl: $string =~ s/ ( [\x80-\xff] ) / chr($1) /gxe;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;UTF-8 to ISO 8859-1&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Viewing a UTF-8 file in a web browser page set to ISO 8859-1 will display 2 (or more)characters for each UTF-8 'hi byte' character.&lt;br /&gt;e.g. For 2 byte UTF-8 characters, it will display an illegal character, followed by the character you want.&lt;/li&gt;&lt;li&gt;The solution: First, identify all characters in your input stream, that don't have ISO 8850-1 equivalents&lt;/li&gt;&lt;li&gt;Maybe convert &lt;ul&gt;&lt;li&gt;all the exotic utf-8 bullet points to &amp;#nn; &lt;/li&gt;&lt;li&gt;the exotic hyphens to - (minus sign)&lt;/li&gt;&lt;li&gt;the various 6, 66, 9, 99 style quotes to ' and "&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;For XML feeds with character codes greater than 255, consider &amp;#nn; escape sequences(rather than &amp;name; or the binary code, both of which will cause problems)&lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;Case Study&lt;/h1&gt;&lt;p&gt;A well known international newspaper has a publishing system that uses UTF-8, and a series of XML feeds that use ISO 8859-1&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Analyse an entire year's worth or newspaper articles.&lt;ul&gt;&lt;li&gt;Make a list of every unique characters used.&lt;/li&gt;&lt;li&gt;Cater for &amp;#nn; and &amp;name; style characters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Map all the UTF-8 characters found (with character code greater than 128) to ISO 8859-1 equivalents.&lt;/li&gt;&lt;li&gt;Flag up any UTF-8 characters encountered in the conversion process which are not covered by this mapping.&lt;ul&gt;&lt;li&gt;Again, cater for &amp;#name; and &amp;name; characters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Escape all characters greater than 128 with the XML &amp;#nn; escape sequence, so the output file is pure ASCII&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;h2&gt;Appendix : Differences between Windows 1252 and the ISO Character Sets&lt;/h2&gt;&lt;br /&gt;In practise, you may wish to map characters to ', ", and - rather then "left single quote" etc&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;0x80 0x20ac ;Euro Sign&lt;br /&gt;0x81 0x0081&lt;br /&gt;0x82 0x201a ;Single Low-9 Quotation Mark&lt;br /&gt;0x83 0x0192 ;Latin Small Letter F With Hook&lt;br /&gt;0x84 0x201e ;Double Low-9 Quotation Mark&lt;br /&gt;0x85 0x2026 ;Horizontal Ellipsis&lt;br /&gt;0x86 0x2020 ;Dagger&lt;br /&gt;0x87 0x2021 ;Double Dagger&lt;br /&gt;0x88 0x02c6 ;Modifier Letter Circumflex Accent&lt;br /&gt;0x89 0x2030 ;Per Mille Sign&lt;br /&gt;0x8a 0x0160 ;Latin Capital Letter S With Caron&lt;br /&gt;0x8b 0x2039 ;Single Left-Pointing Angle Quotation Mark&lt;br /&gt;0x8c 0x0152 ;Latin Capital Ligature Oe&lt;br /&gt;0x8d 0x008d&lt;br /&gt;0x8e 0x017d ;Latin Capital Letter Z With Caron&lt;br /&gt;0x8f 0x008f&lt;br /&gt;0x90 0x0090&lt;br /&gt;0x91 0x2018 ;Left Single Quotation Mark&lt;br /&gt;0x92 0x2019 ;Right Single Quotation Mark&lt;br /&gt;0x93 0x201c ;Left Double Quotation Mark&lt;br /&gt;0x94 0x201d ;Right Double Quotation Mark&lt;br /&gt;0x95 0x2022 ;Bullet&lt;br /&gt;0x96 0x2013 ;En Dash&lt;br /&gt;0x97 0x2014 ;Em Dash&lt;br /&gt;0x98 0x02dc ;Small Tilde&lt;br /&gt;0x99 0x2122 ;Trade Mark Sign&lt;br /&gt;0x9a 0x0161 ;Latin Small Letter S With Caron&lt;br /&gt;0x9b 0x203a ;Single Right-Pointing Angle Quotation Mark&lt;br /&gt;0x9c 0x0153 ;Latin Small Ligature Oe&lt;br /&gt;0x9d 0x009d&lt;br /&gt;0x9e 0x017e ;Latin Small Letter Z With Caron&lt;br /&gt;0x9f 0x0178 ;Latin Capital Letter Y With Diaeresis&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-5740769477049033262?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/5740769477049033262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=5740769477049033262' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5740769477049033262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5740769477049033262'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/10/character-sets.html' title='Character Sets'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-4576373799466239175</id><published>2008-10-06T07:26:00.000-07:00</published><updated>2008-10-06T07:41:45.227-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl template toolkit'/><title type='text'>How to Install Template Toolkit on Windows</title><content type='html'>&lt;p&gt;If using Activestate Perl on Windows XP, Windows Vista etc.: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Have a look at : &lt;a href="http://cpan.uwinnipeg.ca/PPMPackages/10xx/"&gt;http://cpan.uwinnipeg.ca/PPMPackages/10xx/&lt;/a&gt; &lt;/li&gt;&lt;li&gt;These modules are for Perl 5.10 (only). Use &lt;strong&gt;perl -v&lt;/strong&gt; to check you're using 5.10 &lt;/li&gt;&lt;li&gt;run ppm (activestate's perl packet manager)&lt;br /&gt;- can just type ppm at a dos prompt (in vista at least) &lt;/li&gt;&lt;li&gt;In ppm: Edit &gt; Preferences &gt; Add Repository&lt;br /&gt;- name = university of winnipeg&lt;br /&gt;- url = http://cpan.uwinnipeg.ca/PPMPackages/10xx/&lt;br /&gt;- this will then sync with the repository &lt;/li&gt;&lt;li&gt;In ppm: Select template toolkit (may have to do "view &gt; all packages" to see it) &lt;/li&gt;&lt;li&gt;In ppm: File &gt; Run Marked Actions &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;As a bonus, there's loads of other perl modules as well.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-4576373799466239175?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/4576373799466239175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=4576373799466239175' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4576373799466239175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4576373799466239175'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/10/how-to-install-template-toolkit-on.html' title='How to Install Template Toolkit on Windows'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-7324301381205374508</id><published>2008-09-30T06:24:00.000-07:00</published><updated>2008-09-11T09:49:00.493-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Tutorial</title><content type='html'>Regular expressions, or regex, are one of the best things about Perl. So good infact, that they been copied by most other programming languages.&lt;br /&gt;&lt;br /&gt;They are sadly let down however by Perl "man pages" and the chapter in the 'Programming Perl' camel book which in no way does them justice. It explains them, but only in a way a Computer Science PHD student would understand.&lt;br /&gt;&lt;br /&gt;So, here's my tutorial with lots of examples.&lt;br /&gt;&lt;br /&gt;NB 1: this is based on Perl, but you can use them in Javascript, Python etc.&lt;br /&gt;&lt;br /&gt;NB 2: once you understand this, you should be ready for the reference material&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-7324301381205374508?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/7324301381205374508/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=7324301381205374508' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7324301381205374508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7324301381205374508'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-1.html' title='Regex : Tutorial'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-5997365812692729505</id><published>2008-09-29T07:24:00.000-07:00</published><updated>2008-09-11T08:56:05.103-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Using a regular expression (perl specific).</title><content type='html'>There are 3 ways to call a regex:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use: $x =~ //&lt;/li&gt;&lt;li&gt;Use: $x =~ m//&lt;br /&gt;or m## or m"" or m{} or anything else you care to choose&lt;/li&gt;&lt;li&gt;Use: qr()&lt;br /&gt;or qr## or qr"" or qr{}&lt;/li&gt;&lt;/ol&gt;Why so many ways. First, that's Perl. But it helps with escaping, see examples below. Just choose the delimiters that don't appear inside the rege.&lt;br /&gt;&lt;br /&gt;The usual choices are // () ## and ""&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x =~ /andrew/;&lt;br /&gt;$x =~ m/andrew/;&lt;br /&gt;$x =~ m#andrew#;&lt;br /&gt;$x =~ qr(andrew);&lt;br /&gt;&lt;br /&gt;#matches speachmarks&lt;br /&gt;$x =~ m/"andrew"/;&lt;br /&gt;&lt;br /&gt;#matches HTML tags - there's no need to escape the / in &amp;lt;/b&amp;gt;&lt;br /&gt;$x =~ qr# &amp;lt;b&amp;gt;andrew&amp;lt;/b&amp;gt; #;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-5997365812692729505?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/5997365812692729505/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=5997365812692729505' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5997365812692729505'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5997365812692729505'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-1-specifying-regular-expression.html' title='Regex : Using a regular expression (perl specific).'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-7064104602273017885</id><published>2008-09-28T07:27:00.000-07:00</published><updated>2008-09-11T09:20:58.301-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Using whitepace and comments</title><content type='html'>The /x modifier&lt;br /&gt;&lt;br /&gt;Using whitespace and comments inside your regular expression is a brilliant idea, especially as regex often look like line noise, even to yourself a week later..&lt;br /&gt;&lt;br /&gt;If you need a space, you'll need to escape it as \  (that \ then a SPACE ) or \s (which means any whitespace character)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$x =~ / andrew /ix&lt;br /&gt;&lt;br /&gt;# these last 2 are the same&lt;br /&gt;$x =~ m# &amp;lt;b&amp;gt; \s* andrew \s* &amp;lt;/b&amp;gt; #ix;&lt;br /&gt;&lt;br /&gt;$x =~ qr"                 # " is the delimiter to start and end the regex&lt;br /&gt;      &amp;lt;b&amp;gt;&lt;br /&gt;        \s* andrew \s*  # allow optional whitespace (0+ chars) at start and end&lt;br /&gt;      &amp;lt;/b&amp;gt;&lt;br /&gt;   "ix;                 # ignore case&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-7064104602273017885?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/7064104602273017885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=7064104602273017885' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7064104602273017885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7064104602273017885'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-3-using-whitepace-and-comments.html' title='Regex  : Using whitepace and comments'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-1529662434406812040</id><published>2008-09-26T06:28:00.000-07:00</published><updated>2008-09-11T08:56:39.151-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Some simple examples</title><content type='html'>Some simple examples to start&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x = '&lt;b&gt;Andrew&lt;/b&gt;';&lt;br /&gt;&lt;br /&gt;print 'match' if $x =~ /rew/;&lt;br /&gt;match&lt;br /&gt;&lt;br /&gt;print 'match' if $x =~ /And/;&lt;br /&gt;match&lt;br /&gt;&lt;br /&gt;# no match as and doesn't match And&lt;br /&gt;print 'false' if $x =~ /and/;&lt;br /&gt;&lt;br /&gt;print 'true' if $x =~ /and/i; # the 'i' is ignore case&lt;br /&gt;match&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-1529662434406812040?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/1529662434406812040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=1529662434406812040' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1529662434406812040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1529662434406812040'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-1_11.html' title='Regex  : Some simple examples'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-4733478723759656886</id><published>2008-09-25T08:41:00.000-07:00</published><updated>2008-09-11T08:57:08.853-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : How many times to match?</title><content type='html'>Place these modifiers after a character:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;+ matches  1+ times&lt;br /&gt;&lt;/li&gt;&lt;li&gt;* matches 0+ times&lt;br /&gt;&lt;/li&gt;&lt;li&gt;{3} after a charater matches it 3 times&lt;/li&gt;&lt;li&gt;{2,3} after a charater matches it 2 to 3 times&lt;/li&gt;&lt;/ul&gt;Greedy and Not Greedy&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x = "&lt;p&gt; one &lt;/p&gt; &lt;p&gt; two &lt;/p&gt;";&lt;br /&gt;&lt;br /&gt;#.* is greedy, so this matches from the first &lt;p&gt; to the last &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;$x =~ m# &lt;p&gt; .* &lt;/p&gt; #x&lt;br /&gt;&lt;br /&gt;#.*? isn't greedy, so this matches &lt;span style="font-style: italic;"&gt;&lt;p&gt; one &lt;/p&gt;&lt;/span&gt; only&lt;br /&gt;&lt;br /&gt;$x =~ m# &lt;p&gt; .*? &lt;/p&gt; #x&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-4733478723759656886?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/4733478723759656886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=4733478723759656886' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4733478723759656886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4733478723759656886'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-5-how-many-times-to-match.html' title='Regex  : How many times to match?'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-2835036666206423821</id><published>2008-09-24T08:45:00.000-07:00</published><updated>2008-09-11T10:00:10.691-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Predefined Groups of characters</title><content type='html'>Groups of characters&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;/s matches a whitespace character&lt;/li&gt;&lt;li&gt;/S matches anything except a whitespace character&lt;/li&gt;&lt;li&gt;/w a word charaters (a-z, A-Z, 0-9, Persian, Greek, Chinese alphabets, etc)&lt;/li&gt;&lt;li&gt;/W anything except a word character&lt;/li&gt;&lt;li&gt;/d matches 0..9&lt;/li&gt;&lt;li&gt;/D matches anything EXCEPT 0..9&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-2835036666206423821?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/2835036666206423821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=2835036666206423821' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/2835036666206423821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/2835036666206423821'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-6-predefined-groups-of-characters.html' title='Regex  : Predefined Groups of characters'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-4078463695043501040</id><published>2008-09-23T08:47:00.000-07:00</published><updated>2008-09-11T09:55:12.478-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Groups</title><content type='html'>Use ( ) for groups.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$html =~ (andrew) &lt;br /&gt;# matches andrew&lt;br /&gt;&lt;br /&gt;((andrew)|(john)|(peter)) &lt;br /&gt;# matches andrew OR john or peter&lt;br /&gt;&lt;br /&gt;# the same, but with whhitespace&lt;br /&gt;# m# - use # as the delimiter&lt;br /&gt;# #x - allow whitespace&lt;br /&gt;$html =~ m#&lt;br /&gt; (&lt;br /&gt;   ( andrew   )  |&lt;br /&gt;   ( peter    )  |&lt;br /&gt;   ( john     )&lt;br /&gt; )#x;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-4078463695043501040?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/4078463695043501040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=4078463695043501040' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4078463695043501040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/4078463695043501040'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-7-groups.html' title='Regex  : Groups'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-591429815612368681</id><published>2008-09-11T10:12:00.000-07:00</published><updated>2008-09-11T10:34:34.394-07:00</updated><title type='text'>Perl Complex Variables</title><content type='html'>Perl has 3 types, scalar, array and hash. These can be combined to make complex variables. &lt;br /&gt;&lt;br /&gt;Unfortunately, the syntax isn't kind.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Defining Scalars, Arrays and Hashes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$name = 'andrew' ;&lt;br /&gt;&lt;br /&gt;# these 2 are the same, qw() is 'syntax sugar'&lt;br /&gt;@names = qw( andrew john peter );&lt;br /&gt;@names = ('andrew', 'john', 'peter');&lt;br /&gt;&lt;br /&gt;%age = (&lt;br /&gt; 'andrew' =&gt; 20,&lt;br /&gt; 'peter'  =&gt; 30,&lt;br /&gt; 'paul'   =&gt; 17,&lt;br /&gt; );&lt;br /&gt;&lt;br /&gt;# note the outside hash uses (&lt;br /&gt;# - but the inside hash uses {&lt;br /&gt;&lt;br /&gt;%names = (&lt;br /&gt; 'andrew' =&gt; { &lt;br /&gt;      'age'    =&gt; 20, &lt;br /&gt;      'height' =&gt; 1.76,&lt;br /&gt;      },&lt;br /&gt; 'peter'  =&gt; { &lt;br /&gt;      'age'    =&gt; 30, &lt;br /&gt;      'height' =&gt; 1.2, &lt;br /&gt;      'friends'=&gt; ['andrew', 'paul'], &lt;br /&gt;      }&lt;br /&gt; );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Scalars&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x =  $names{'andrew'}{'age'};&lt;br /&gt;# now $x = 20 &lt;br /&gt;&lt;br /&gt;$names{'andrew'}{'age'} = 35 ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Arrays&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Arrays are a bit more complex - use @{ } to access them and [ ] to set them&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;@x = @{ $names{'peter'}{'friends'} } ;&lt;br /&gt;&lt;br /&gt;$names{'peter'}{'friends'} = [ 'bill', 'john', 'fred' ] ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Hashes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Hashes are similar, use %{ } to access them and { } to set them&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;%hash = %{ $names{'andrew'} } ;&lt;br /&gt;&lt;br /&gt;$names{'andrew'} = { 'age' =&gt; 20, 'height' =&gt; 1.76 } ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Important Gotcha&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When using the %hash = %{} and @array = @{} syntax, you are making a reference to the data, NOT a copy of it;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;%hash = %{ $names{'andrew'} } ;&lt;br /&gt;# %hash is a reference, change %hash and you change %names, and visa versa&lt;br /&gt;&lt;br /&gt;%new_hash = %hash;&lt;br /&gt;# now safe&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-591429815612368681?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/591429815612368681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=591429815612368681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/591429815612368681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/591429815612368681'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/perl-complex-variables.html' title='Perl Complex Variables'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-2326231968181357185</id><published>2008-09-11T09:58:00.000-07:00</published><updated>2008-09-11T09:59:23.527-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Doesn't match</title><content type='html'>&lt;code&gt;&lt;br /&gt;# $x does not contain andrew&lt;br /&gt;$x !~ /andrew/&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-2326231968181357185?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/2326231968181357185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=2326231968181357185' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/2326231968181357185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/2326231968181357185'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-doesnt-match.html' title='Regex : Doesn&apos;t match'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-605355080229853690</id><published>2008-09-11T09:57:00.000-07:00</published><updated>2008-09-11T10:12:02.258-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Match on word Boundary</title><content type='html'>\b match on a word boundary&lt;br /&gt;&lt;br /&gt;\B matches on not a word boundary&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-605355080229853690?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/605355080229853690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=605355080229853690' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/605355080229853690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/605355080229853690'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/perl-regex-match-on-word-boundary.html' title='Regex : Match on word Boundary'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-1662306826173372474</id><published>2008-09-11T09:44:00.000-07:00</published><updated>2008-09-11T09:55:32.383-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : . and the /s modifier</title><content type='html'>A . matches anything except a newline&lt;br /&gt;&lt;br /&gt;To match a newline, use the /s modifer (treat as a Single line)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$x = qq(&lt;br /&gt;andrew&lt;br /&gt;was&lt;br /&gt;here&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;$x =~ /andrew .* here/xs;&lt;br /&gt;# matches as the /s carries the search over the newlines&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-1662306826173372474?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/1662306826173372474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=1662306826173372474' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1662306826173372474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1662306826173372474'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/and-s-modifier.html' title='Regex : . and the /s modifier'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-7411977576912705168</id><published>2008-09-11T09:24:00.000-07:00</published><updated>2008-09-11T09:55:44.937-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Anchors and the /m  modifier</title><content type='html'>Anchors&lt;br /&gt;^ matches at the start of a string&lt;br /&gt;$ matches at the end of a string&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x = /andrew/&lt;br /&gt;&lt;br /&gt;$x =~ /^a/ ;&lt;br /&gt;# matches as andrew starts with an a&lt;br /&gt;&lt;br /&gt;$x =~ /rew$/;&lt;br /&gt;# matches as andrew ends with a rew&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But what if you have a string containing several lines (e.g. a file with \n characters) ?&lt;br /&gt;&lt;br /&gt;The /m modifier.&lt;br /&gt;&lt;br /&gt;This treats the string as multiple lines, so ^ and $ will match the start and end of each line in the file&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x = qq(&lt;br /&gt;andrew&lt;br /&gt;john andrew&lt;br /&gt;andrew&lt;br /&gt;);&lt;br /&gt;$x =~ s/^andrew/ANDREW/mg;&lt;br /&gt;# will replace 1st and 3rd andrew&lt;br /&gt;# without the /m, it would only replace the third&lt;br /&gt;&lt;/pre&lt;br /&gt;This treats the string as a single line, so&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-7411977576912705168?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/7411977576912705168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=7411977576912705168' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7411977576912705168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7411977576912705168'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-anchors-and-m-modifier.html' title='Regex : Anchors and the /m  modifier'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-1526004455016464206</id><published>2008-09-11T09:21:00.001-07:00</published><updated>2008-09-11T09:56:02.265-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Global Replace</title><content type='html'>The /g modifier&lt;br /&gt;&lt;br /&gt;This repeats the regex until there are no more matches&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$x = /andrew andrew andrew/;&lt;br /&gt;&lt;br /&gt;$x = s/a/A/;&lt;br /&gt;# Andrew andrew andrew (1 replace)&lt;br /&gt;&lt;br /&gt;$x = s/a/A/g;&lt;br /&gt;# Andrew Andrew Andrew (all the 'a' get replaces)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-1526004455016464206?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/1526004455016464206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=1526004455016464206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1526004455016464206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/1526004455016464206'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-global-replace.html' title='Regex : Global Replace'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-5783497493872537430</id><published>2008-09-11T08:54:00.001-07:00</published><updated>2008-09-11T09:20:07.456-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Using expressions</title><content type='html'>This is the /e modifier&lt;br /&gt;&lt;br /&gt;Example: make HTML tags upper case&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;# ( ) - capture the text&lt;br /&gt;# .*? - match the least amount of text, i.e. an HTML tag&lt;br /&gt;# uc ($1) - make the matches text uppercase&lt;br /&gt;# gxe - g is global replace&lt;br /&gt;# gxe - x is allow whitespace and comments&lt;br /&gt;# gxe - the bit on the right is an expressions to be evaluates&lt;br /&gt;&lt;br /&gt;$html =~ s# ( &lt; .*? &gt; ) # print uc($1) #gxe ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Example : find hi byte characters&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;# find hi-byte characters in HTML&lt;br /&gt;# - and keep a record of all the hi byte chars found in %found&lt;br /&gt;my %found ;&lt;br /&gt;&lt;br /&gt;sub find {&lt;br /&gt; my ($char) = @_ ;&lt;br /&gt; $found{ $chars } ++; ## keep a record&lt;br /&gt; return '[' . ord( $chars ) . ']';&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;## this will find euro and £ symbols, but not &amp;euro;&lt;br /&gt;## \x80 is hex (ascii char 128)&lt;br /&gt;## \x80-\xffff is a range - if the file is utf8, it will match hi bytes chars as well&lt;br /&gt;## gxe - expression, whitespace, and global replace&lt;br /&gt;$html =~ s# [\x80-\xffff] # &amp;find( $1 ) #gxe;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-5783497493872537430?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/5783497493872537430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=5783497493872537430' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5783497493872537430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/5783497493872537430'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-11-using-expressions.html' title='Regex  : Using expressions'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-386062393101309358</id><published>2008-09-11T08:53:00.000-07:00</published><updated>2008-09-11T09:57:03.759-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex  : Substitutions</title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-386062393101309358?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/386062393101309358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=386062393101309358' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/386062393101309358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/386062393101309358'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-10-substitutions.html' title='Regex  : Substitutions'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-9004220507067950225</id><published>2008-09-11T08:52:00.000-07:00</published><updated>2008-09-11T10:06:54.842-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex : Capture Matched text</title><content type='html'>Use brackets to capture text, and $1, $2 ... to refer to it&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$x = 'andrew john';&lt;br /&gt;&lt;br /&gt;# swap the first and second word around&lt;br /&gt;&lt;br /&gt;$x=~ s/ (\w+) \s+ (\w+*)&lt;br /&gt;      / $2 $1&lt;br /&gt;      / x;&lt;br /&gt;&lt;br /&gt;# s/    - substitute&lt;br /&gt;# (\w+) - 1+ word charcters, captures as $1&lt;br /&gt;# \s+   - 1+ whitespace characters&lt;br /&gt;# (\w+) - 1+ word chars, captured as $2&lt;br /&gt;# /x    - use whitesapce and comments&lt;br /&gt;&lt;br /&gt;# $1 and $2 survive&lt;br /&gt;print $2;&lt;br /&gt;# prints john&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-9004220507067950225?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/9004220507067950225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=9004220507067950225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/9004220507067950225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/9004220507067950225'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-9-capture-matched-text.html' title='Regex : Capture Matched text'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-8945410048040517815</id><published>2008-09-11T08:51:00.000-07:00</published><updated>2008-09-11T10:11:08.608-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl regex regular expressions'/><title type='text'>Regex: Ranges</title><content type='html'>Use [ ] for ranges - match any 1 char inside the range&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$x =~ /[0-9]/;&lt;br /&gt;$x =~ /[a-z]/i;   # so match a..z and A..Z as /i is ignore case&lt;br /&gt;$x =~ /[\n\r]/;&lt;br /&gt;&lt;br /&gt;#match 1+ chars in the range 0..9 + - and .&lt;br /&gt;#\. escape the dot so it doesn't mean "any 1 char"&lt;br /&gt;$x=~ /[0-9+-\.]+/&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-8945410048040517815?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/8945410048040517815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=8945410048040517815' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/8945410048040517815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/8945410048040517815'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/regex-8-ranges.html' title='Regex: Ranges'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7779187331106757427.post-7074711904624585295</id><published>2008-09-11T06:20:00.000-07:00</published><updated>2008-09-11T06:24:21.232-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='perl poetry'/><title type='text'>Perl Poetry</title><content type='html'>This isn't mine, but its quite cool.&lt;br /&gt;&lt;br /&gt;$_ = reverse sort qw p ekca lre uJ reh ts&lt;br /&gt;p, $/.r, map $_.$", qw e p h tona e; print&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7779187331106757427-7074711904624585295?l=www.cablechipsolutions.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.cablechipsolutions.com/feeds/7074711904624585295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7779187331106757427&amp;postID=7074711904624585295' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7074711904624585295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7779187331106757427/posts/default/7074711904624585295'/><link rel='alternate' type='text/html' href='http://www.cablechipsolutions.com/2008/09/perl-poetry.html' title='Perl Poetry'/><author><name>Andrew</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
