[wellylug] Perl regular expression problem with literal $

Peter Davenport davenportnz at gmail.com
Sun Jun 1 11:50:38 NZST 2008


Not a direct Linux issue, but I do run this process under Linux.

I have a perl script to process some data with many records of the form -
'User xxxxxx transfered 123456kb of file yyyyyy at cost of $1,234.56 to
machine zzzzz'

This example is a bit made up but it illustrates the point. I am trying to
extract the numbers for the kb and $.

My perl RE to get the kb is m/ (\d+)kb / and this works as it gets the
leading/trailing blanks and the numeric kb item into $1 variable.
However, for the money item, I tried m/ $([\d,.]+) / but the $ gets used to
indicate the end of record. Escaping it with backslash dosn't work either as
it then seems to get interpreted as the start of a scalar variable. How do I
specify a literal $ in the RE?

This data extraction requirement must be a common one and been solved
before. I have not been able to locate a solution.
Can anyone help to resolve this please.

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wellylug.org.nz/pipermail/wellylug/attachments/20080601/4805f48d/attachment.html 


More information about the wellylug mailing list