tracer has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have data in the form of a text file and i need to extract numerical information from it.One of the lines in the text file is as follows

66.411716: ABCDE:M WALL 0x0164764a, RX 0x03bb9d42, TS 5.

How do I extract the values 66.411716, 0x0164764a and 5 into three different variables without using the substr function?

Thank you in advance.

.

Replies are listed 'Best First'.
Re: Extracting numerical information
by ww (Archbishop) on Jun 27, 2013 at 19:01 UTC

    Your first post basicly asked us to code for you. (- - ! )
    Someone obliged ( For shame! )

    One can hope that folks who do that will refrain this time, until you show some effort of your own; post some code you've written to solve your problem; and tell us, verbatim, about any errors/warnings generated.

    We're here to help you learn. We are NOT (intended to be) code-a-matic. Please see this site's guidelines, faqs, etc. for wanna-be participants... including On asking for help and How do I post a question effectively?


    If you didn't program your executable by toggling in binary, it wasn't really programming!

      Even worse, the phrase "without using the substr function" strongly suggests "Do my HOMEWORK for me." If there were some technical reason for this spec, I am sure it would be explained.
      Bill
Re: Extracting numerical information
by hdb (Monsignor) on Jun 27, 2013 at 18:55 UTC

    Extracting all four numbers.

    use strict; use warnings; my $string = "66.411716: ABCDE:M WALL 0x0164764a, RX 0x03bb9d42, TS 5" +; my @numbers = $string =~ /(0x[0-9a-f]+|\d+\.?\d*)/g; print "@numbers\n";
Re: Extracting numerical information
by AnomalousMonk (Archbishop) on Jun 28, 2013 at 01:57 UTC

    Yeah, "without using the substr function" and the further specification exemplars of this do kinda emit a homeworky odor. But in any event, a possibly useful module might be Regexp::Common for various kinds of numbers (decimal, hex, etc.).

Re: Extracting numerical information
by frozenwithjoy (Priest) on Jun 27, 2013 at 18:45 UTC
    Can you give a few more line examples so we can know what patterns there may be? And just to make sure, you don't want to extract the 4th stretch of characters that contains numbers (0x03bb9d42)?

      There are a number of lines like the one I have given as an example.

      66.411709: TDSCDMA:M tfw_stmr.c:697 | tfw_walltime_isr: WALL 0x0164761a, status=0x00000001

      Extract: 66.411709 and 0x0164761a

      66.411736: TDSCDMA:L tfw_ce_proc.c:1484 | CE: sfn 955, slot 5 has 1 CE calls scheduled.

      Extract: 66.411736 and 1.

      66.411737: TDSCDMA:L tfw_ce_event_queue.c:196 | CE: Enqueue pending event 113 (type 12, sfm 955, slot 5, dvga=6)

      Extract: 66.411737 and 113.

      66.411720: TDSCDMA:L tfw_ulc.c:370 | ULC: Processing (start:end) 0x0164766c : 0x01647683, Subframe: 0x03bb, TS: 0x5

      extract: 66.411720, 0x0164766c and 0x01647683

        What are your criteria?

        IOW, in the first sample, why aren't "697" and "0x00000001" just as much "numerical information" as those values you're seeking to extract?

        For future reference, I know what I mean. Why don't you?


        If you didn't program your executable by toggling in binary, it wasn't really programming!