Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: (Golf) unique

by insensate (Hermit)
on Apr 24, 2003 at 16:14 UTC ( [id://252940]=note: print w/replies, xml ) Need Help??


in reply to Re: (Golf) unique
in thread (Golf) unique

In the same manner even:
01 234567890123 perl -ne "$$_++||print" < infile > outfile

Replies are listed 'Best First'.
Re: Re: Re: (Golf) unique
by jmcnamara (Monsignor) on Apr 24, 2003 at 16:51 UTC

    Very nice. ++

    But it will fail if the infile looked like this: ;-)

    $ cat infile here comes trouble 1 2

    --
    John.

      Have you tried your input? It works fine for me. As $_ isn't chomp()'d, it escapes the problem of modifying a readonly $1.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Have you tried your input?

        Yes I tried the input.

        I test everything before I post it here. I have a test directory full of files called file, file1, file2, numfile, bigfile, blankfile, etc.

        Nevertheless, it is difficult to test for every eventuality. It looks like the behaviour changes between 5.6 and 5.8:

        $ perl5.005_03 -ne '$$_++||print' infile here comes trouble Modification of a read-only value attempted at -e line 1, <> chunk + 4. $ perl5.6.1 -ne '$$_++||print' infile here comes trouble Modification of a read-only value attempted at -e line 1, <> chunk + 4. $ perl5.8.0 -ne '$$_++||print' infile here comes trouble 1 2

        --
        John.

Re: Re: Re: (Golf) unique
by sauoq (Abbot) on Jun 04, 2003 at 17:07 UTC

    Here's a version which shouldn't rely on 5.8:

    01 2345678901234567 perl -ne '${_.$_}++||print'

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found