<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 <<a href="mailto:enkidu@cliffp.com">enkidu@cliffp.com</a>><br>
Subject: Re: [wellylug] Perl regular expression problem with literal $<br>To: Wellington Linux Users Group <<a href="mailto:wellylug@lists.wellylug.org.nz">wellylug@lists.wellylug.org.nz</a>><br>Message-ID: <<a href="mailto:4841F297.7070409@cliffp.com">4841F297.7070409@cliffp.com</a>><br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br><br>>Peter Davenport wrote:<br>>> Not a direct Linux issue, but I do run this process under Linux.<br>>><br>>> I have a perl script to process some data with many records of the form -<br>
>> 'User xxxxxx transfered 123456kb of file yyyyyy at cost of $1,234.56 to<br>>> machine zzzzz'<br>>><br>>> This example is a bit made up but it illustrates the point. I am trying<br>>> to extract the numbers for the kb and $.<br>
>><br>>> My perl RE to get the kb is m/ (\d+)kb / and this works as it gets the<br>>> leading/trailing blanks and the numeric kb item into $1 variable.<br>>> However, for the money item, I tried m/ $([\d,.]+) / but the $ gets used<br>
>> to indicate the end of record. Escaping it with backslash dosn't work<br>>> either as it then seems to get interpreted as the start of a<br>>> scalar variable. How do I specify a literal $ in the RE?<br>
>><br>>> This data extraction requirement must be a common one and been solved<br>>> before. I have not been able to locate a solution.<br>>> Can anyone help to resolve this please.<br>>></blockquote>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span id=""></span>></blockquote>
<div> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><span id=""></span>>It's not matching your RE. The RE should read:<br>>/ \$([\d.]+ )/<br>><br>
>Note, no comma.<br>><br>>Here's my test snippet:<br>><br>>#!/usr/bin/perl<br>><br>>use strict ;<br>>use warnings ;<br>><br>>my $str = 'abcdef $1234.00 xyz' ;<br>>print "$str\n" ;<br>
>$str =~ / \$([\d.]+ )/ ;<br>>print "$1\n" ;<br>><br>><br>><br>><br>>Cheers,<br>><br>>Cliff<br></blockquote>
<div> </div>
<div> </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 'g' 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 'g' from the prior statement fixed it. I had not expected such interaction between statements.</blockquote>
</div>
<div>Thanks again.</div>
<div> </div>
<div>Regards</div>
<div>Peter</div>
<div> </div>
<div> </div></div>