in reply to Re^2: Parse data from a line to get 2 variables
in thread Parse data from a line to get 2 variables

He actually gave you the answer, more or less:

my ($lot,$prod) = m/(\S+)\s+(\S+)/;
instead of:
$Info=$_; $lotNumber=substr($Info, 0,8); $productName=substr($Info, 9);
I'm not sure what you are doing with the if(m%E%), but I presume that is for testing...


Replies are listed 'Best First'.
Re^4: Parse data from a line to get 2 variables
by Sunnmann (Acolyte) on May 13, 2006 at 01:10 UTC
    First of all, I want to thank you all for your help. This is awesome!
    You guys have come through for me every time I have asked for help and I
    appreciate it! So thank you very much and I am tipping my hat to all of

    And, yes it was for testing purposes, and at first I thought I may need
    to parse it by the type of lot# it was. But that was for nought. The
    main thing I do with Perl right now is change stuff I have to work in
    new situations, I get stuck alot while trying to learn. My mentor here
    at work left a while back and we dont use perl as much anymore so there
    has been no need for this until now when I write simple scripts to do
    some mundane stuff. I kind fo wish there was more need and i had the
    time to really get down and learn it.

    Anyways, enough of that, I did have another question. Could one of you
    write out in words what the below line is saying? Or point me to a good
    site that will tell me?


      \S+ matches one or more non-whitespace characters
      \s+ matches one or more whitespace chars


      my ($lot,$prod) = m/(\S+)\s+(\S+)/;

      is matching the lotnumber and putting it into $lot,
      matching the tab and throwing it away,
      then matching the product code and putting it into $prod