in reply to text extraction question

Hi echoangel911,

Is the following something like what you're looking for...?

use strict; use warnings; use Data::Dumper; my $templateformat = 'w<NM>b<NM>cm<CH>sw<SW>'; my $inputexample = 'w8b8cm512swno'; my @first_array = ($templateformat =~ /<([^>]*)>/g); my @second_array = ($inputexample =~ /\d+/g); printf "First array = %s\n", Dumper(\@first_array); printf "Second array = %s\n", Dumper(\@second_arrayt); # Displays: # # First array = $VAR1 = [ # 'NM', # 'NM', # 'CH', # 'SW' # ]; # # Second array = $VAR1 = [ # '8', # '8', # '512' # ];

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: text extraction question
by johngg (Canon) on Dec 05, 2006 at 19:51 UTC
    From the op

    and 8 8 512 no in another array

    I think you may have missed extracting the "no" in the second array, although from the scanty problem description it's not at all clear that it might be wanted.

    Cheers,

    JohnGG

      Whoops ... you're absolutely right!

      My brain directly converted it from "no" to "number(s)" on input (as in and 8 8 512 numbers), so I didn't even look to see if it was part of the string.

      I guess that validates blue_cowdawg's comments all the more, as far as the original question being a little bit vague.


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        Yes, very vague and somewhat counterintuitive. To me, NM suggests numbers and CH suggests characters. However, the example given seems to suggest that NM is a single digit and CH is two or more digits; yes|no seems a reasonable guess for SW if it means switch. blue_cowdawg definitely hit the nail on the head.

        It would be nice if echoangel911 clarified what was meant.

        Cheers,

        JohnGG