Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Parse data from a line to get 2 variables

by devnul (Monk)
on May 13, 2006 at 00:48 UTC ( #549151=note: print w/ replies, xml ) Need Help??


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...

Devnul


Comment on Re^3: Parse data from a line to get 2 variables
Select or Download Code
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
    you.

    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?

    m/(\S+)\s+(\S+)/


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

      So

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://549151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2015-07-31 11:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls