<br><br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Date: Sun, 01 Jun 2008 12:51:35 +1200<br>From: Cliff Pratt &lt;<a href="mailto:enkidu@cliffp.com">enkidu@cliffp.com</a>&gt;<br>
Subject: Re: [wellylug] Perl regular expression problem with literal $<br>To: Wellington Linux Users Group &lt;<a href="mailto:wellylug@lists.wellylug.org.nz">wellylug@lists.wellylug.org.nz</a>&gt;<br>Message-ID: &lt;<a href="mailto:4841F297.7070409@cliffp.com">4841F297.7070409@cliffp.com</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br><br>&gt;Peter Davenport wrote:<br>&gt;&gt; Not a direct Linux issue, but I do run this process under Linux.<br>&gt;&gt;<br>&gt;&gt; I have a perl script to process some data with many records of the form -<br>
&gt;&gt; &#39;User xxxxxx transfered 123456kb of file yyyyyy at cost of $1,234.56 to<br>&gt;&gt; machine zzzzz&#39;<br>&gt;&gt;<br>&gt;&gt; This example is a bit made up but it illustrates the point. I am trying<br>&gt;&gt; to extract the numbers for the kb and $.<br>
&gt;&gt;<br>&gt;&gt; My perl RE to get the kb is m/ (\d+)kb / and this works as it gets the<br>&gt;&gt; leading/trailing blanks and the numeric kb item into $1 variable.<br>&gt;&gt; However, for the money item, I tried m/ $([\d,.]+) / but the $ gets used<br>
&gt;&gt; to indicate the end of record. Escaping it with backslash dosn&#39;t work<br>&gt;&gt; either as it then seems to get interpreted as the start of a<br>&gt;&gt; scalar variable. How do I specify a literal $ in the RE?<br>
&gt;&gt;<br>&gt;&gt; This data extraction requirement must be a common one and been solved<br>&gt;&gt; before. I have not been able to locate a solution.<br>&gt;&gt; Can anyone help to resolve this please.<br>&gt;&gt;</blockquote>

<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span id=""></span>&gt;</blockquote>
<div>&nbsp;</div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span id=""></span>&gt;It&#39;s not matching your RE. The RE should read:<br>&gt;/ \$([\d.]+ )/<br>&gt;<br>
&gt;Note, no comma.<br>&gt;<br>&gt;Here&#39;s my test snippet:<br>&gt;<br>&gt;#!/usr/bin/perl<br>&gt;<br>&gt;use strict ;<br>&gt;use warnings ;<br>&gt;<br>&gt;my $str = &#39;abcdef $1234.00 xyz&#39; ;<br>&gt;print &quot;$str\n&quot; ;<br>
&gt;$str =~ / \$([\d.]+ )/ ;<br>&gt;print &quot;$1\n&quot; ;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;Cheers,<br>&gt;<br>&gt;Cliff<br></blockquote>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span id=""></span>Thank you for this response. The escape of the $ character was part of the answer that I needed, but that did not fix it completely. The example cade worked so I knew what to persevere with that. I had a prior match statement with a &#39;g&#39; option for global and that seemed to swallow up the whole record and thus not match the bit I wanted to extract on the later statement. Removing the &#39;g&#39; from the prior statement fixed it. I had not expected such interaction between statements.</blockquote>
</div>
<div>Thanks again.</div>
<div>&nbsp;</div>
<div>Regards</div>
<div>Peter</div>
<div>&nbsp;</div>
<div>&nbsp;</div></div>