in reply to Re^2: Extract varibles from 2 text files and make a report
in thread Extract varibles from 2 text files and make a report

If your goal is to discard everything following "AAA" or "BBB", and so on, you could modify the split statement to look like this:

@prods = split(/\s[^\n]+\n/, $prod);

This will remove everything following the first whitespace character in each of the lines following "Product Name:". Is that what you were trying to do?

May the Force be with you

Replies are listed 'Best First'.
Re^4: Extract varibles from 2 text files and make a report
by Anonymous Monk on Oct 26, 2004 at 19:26 UTC
    That is what I want. Thanks. But if there is some spaces infront of AAA and BBB what should I do?
    Thank you!!!

      For info on using split see split.

      Hmmm... Spaces at the begining of the line... At this point it may be better to simply split on "\n" and then parse the line... This is a confusing line of code:

      @prods = map({/(\S+)/} split(/\n/, $prod));

      So I'll also give it to you in a more broken out way.

      @prods = split(/\n/, $prod); foreach my $line (@prods){ $line =~ s/^\s*(\S+).*$/$1/; }

      But it might be better to do it like this:

      @prods = ($prod =~ m/(?:\A|\n)\s*(\S+)/g);

      Yeah, I think I like the last way the best. It is probably faster too, but I haven't tested that.

      May the Force be with you
        Thank You! It works great!!!
Re^4: Extract varibles from 2 text files and make a report
by Anonymous Monk on Oct 26, 2004 at 19:36 UTC
    But if there are some spaces before "AAA" or "BBB" what should I do. How do you find the reference on using "split"? Thank you!