# New Ticket Created by Leon Brocard # Please include the string: [perl #21588] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21588 >
Well, it's more of a new file than a patch. I'm aware that we're in a code freeze, so I don't mind if this doesn't get it right now, but it'd be nice ;-) I've attached an example "uniq" implementation in pasm, which takes options. It's not very fast compared to GNU uniq atm, but hey. I'd suggest putting this in examples/assembly/ (don't forget the MANIFEST). Cheers, Leon -- Leon Brocard.............................http://www.astray.com/ scribot.................................http://www.scribot.com/ ... What if there were no hypothetical questions? -- attachment 1 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/53714/40460/cda411/uniq.pasm
# $Id$ # uniq - Remove duplicate lines from a sorted file # # % ./assemble.pl uniq.pasm -o uniq.pbc # % ./parrot uniq.pbc data.txt # % ./parrot uniq.pbc -c data.txt # # Takes options and a filename as argument: # # -c # Precede each output line with the count of the number of times the # line occurred in the input, followed by a single space # # -d # Don't output lines that are not repeated in the input # # -u # Don't output lines that are repeated in the input # # By Leon Brocard <[EMAIL PROTECTED]> set S0, P0[1] if S0, SOURCE set S0, P0[0] print "usage: parrot " print S0 print " [-cdu] filename\n" end SOURCE: # do some simple option parsing ne S0, "-c", NOTC set I10, 1 # count mode set S0, P0[2] NOTC: ne S0, "-d", NOTD set I11, 1 # duplicate mode set S0, P0[2] NOTD: ne S0, "-u", GO set I12, 1 # unique mode set S0, P0[2] GO: # S2 is the previous line set I1, 1 # count # Read the file into S1 open I0, S0 readline S2, I0 SOURCE_LOOP: readline S1, I0 eq S1, S2, MATCH # different line unless I10, NOTC2 # count mode # we go to some lengths to make the count pretty set S3, I1 length I2, S3 sub I2, 7, I2 set S3, " " repeat S3, S3, I2 print S3 print I1 print " " print S2 branch RESET NOTC2: unless I11, NOTD2 # show duplicates mode eq 1, I1, RESET print S2 branch RESET NOTD2: unless I12, NOTU2 # don't show lines that are duplicated mode ne 1, I1, RESET print S2 branch RESET NOTU2: # default mode print S2 branch RESET RESET: set I1, 1 branch LOOP MATCH: inc I1 # fall through LOOP: set S2, S1 if S1, SOURCE_LOOP close I0 end