Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Parse data from a line to get 2 variables

by turo (Friar)
on May 13, 2006 at 00:11 UTC ( [id://549146]=note: print w/replies, xml ) Need Help??


in reply to Parse data from a line to get 2 variables

I think you want something like this
#!/usr/bin/perl use Dumpvalue; open (LABELS, "labellist.txt") or die "I could not get at labellist.tx +t as input"; my %info; while (<LABELS>) { my ($lot,$prod) = m/(\S+)\s+(\S+)/; $info{$lot} = $prod; } my $dumper = new Dumpvalue; $dumper->dumpValue(\%info);
Anyway, i don't know what is exactly what you wanted to do with your code, it doesn't seem the same as the problem you're telling.
perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Replies are listed 'Best First'.
Re^2: Parse data from a line to get 2 variables
by Sunnmann (Acolyte) on May 13, 2006 at 00:32 UTC
    Sorry if I was not clear :)

    I have been approached by one of my customers to make an application
    (script) that will take input from a file and print labels for them so
    they do not have to enter them into the label printing program already
    made, one by one. It gets tedious for them to do this for 100 lots for
    instance.

    What I need to do then is get LOT1 into the variable $lot and PRODUCT1
    into the variable $prod. So while I have the loop going. I will then
    take these variables and put them into another string of code I have to
    output to a printer so they will print labels in a certain format with
    the lotnumber and productname on them.

    The format I will put this into to send to the printer is as follows:

    printCode = printCode & "^XA^LH30,30" & _ "^FO110,65^A0,N,100^FD" & _ lotNumber & "^FS" & _ "^FO150,160^BY2,3.0^B3N,N,125,N,N^FD" & _ lotNumber & "^FS" & _ "^FO75,375^A0,N,50,30^FD" & _ productName & "^FS" & _ "^FO30,425^BY2,2.0^B3N,N,50,N,N^FD" & _ productName & "^FS" & _ "^XZ" & vbNewLine

    I took this from teh main printing program that prints labels one at a
    time. I believe this was either written in VB or C something. I will
    have to substitute lotNumber for $lot and productName for $prod. Then
    find teh correct syntax to send this to the printer and I have what I
    need.

    I have been working on thsi still while waiting on a reply. Do you think
    this does it? (Gotta love it when you find the right words you were
    looking for to search on google) LOL

    #!c:\perl\bin my $printCode = ""; my $lotNumber; my $productName; my $Info; open (LABELS, "labellist.txt") or die "I could not get at labellist.tx +t as input"; while (<LABELS>) { chomp; if (m%E%) { # print "$_\n"; # print "\n"; $Info=$_; $lotNumber=substr($Info, 0,8); $productName=substr($Info, 9); # print "$lotNumber\n"; # print "$productName\n"; $printCode = "$printCode & \"\^XA\^LH30,30\" & _ \"\^FO110,65\ +^A0,N,100\^FD\" & _ $lotNumber & \"\^FS\" & _ \"\^FO150,160\^BY2,3.0\ +^B3N,N,125,N,N\^FD\" & _ $lotNumber & \"\^FS\" & _ \"\^FO75,375\^A0,N +,50,30\^FD\" & _ $productName & \"\^FS\" & _ \"\^FO30,425\^BY2,2.0\^B +3N,N,50,N,N\^FD\" & _ $productName & \"\^FS\" & _ \"\^XZ\" & vbNewLin +e"; print $printCode; } }

    Now I am not sure that the syntax to the $printCode is correct, but I
    will get that down to a T sooner or later.
      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
        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+)/

      You might do well to ask your customer if they have the Programmer's Reference Manual for the printer. Some manufacturers ship one with every box; others sell them separately or make them available on their web site. In order to find this in the latter case, you'll need the exact make and model of the printer on which the labels will be printed.

      Of course, if the manufacturer regards this as a trade secret or something, you'll probably be going back to the reverse-engineering approach you've outlined above.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found