Are the line-numbers part of the data? If so, your regex will never match as you anchor your regex to the beginning of the line and don't take the line number into account.

The following will work with or without line-numbers:

use strict; use warnings; while (<DATA>) { next unless m/EUR\/USD/; chomp; my ($currency, $amount, $time) = split /\s*,\s*/; $currency =~ s/\d*\s*//g; print "$currency: $amount at $time\n"; } __DATA__ 1 EUR/USD ,1.35590 ,13:09:31 2 EUR/JPY , 129.872 ,13:09:29 3 GBP/JPY , 138.009 ,13:09:32 4 AUD/JPY , 65.939 ,13:09:30 5 EUR/USD ,1.35592 ,13:09:35 6 EUR/JPY , 129.866 ,13:09:35 7 GBP/JPY , 137.999 ,13:09:35 8 AUD/JPY , 65.938 ,13:09:35 9 EUR/USD ,1.35592 ,13:09:35 10 EUR/JPY , 129.866 ,13:09:35 11 GBP/JPY , 137.999 ,13:09:35 12 AUD/JPY , 65.938 ,13:09:35 13 EUR/USD ,1.35592 ,13:09:35 14 EUR/JPY , 129.866 ,13:09:35 15 GBP/JPY , 137.999 ,13:09:35 16 AUD/JPY , 65.938 ,13:09:35 17 EUR/USD ,1.35592 ,13:09:35 18 EUR/JPY , 129.866 ,13:09:35 19 GBP/JPY , 137.999 ,13:09:35
output:
EUR/USD: 1.35590 at 13:09:31 EUR/USD: 1.35592 at 13:09:35 EUR/USD: 1.35592 at 13:09:35 EUR/USD: 1.35592 at 13:09:35 EUR/USD: 1.35592 at 13:09:35

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: a little REGEX help by CountZero
in thread a little REGEX help by Conal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.