in reply to Re^2: Find duplicate digits
in thread Find duplicate digits

BrowserUk,

Thank you for this.

This is the message I got:

syntax error at ns.pl line 1, near "-le" Execution of ns.pl aborted due to compilation errors.
?

Replies are listed 'Best First'.
Re^4: Find duplicate digits
by BrowserUk (Patriarch) on Apr 07, 2010 at 13:29 UTC

    The solution I posted is a one-line perl command, to be run from a command shell prompt, not to be embedded within a perl source file.

    If you're running under *nix, then you'll have to exchange the quotes like so:

    perl -le'%h=(), undef @h{split"",$_}, keys %h == 3 and print for "0000 +".."9999"'

    The following will run as a script:

    #!/usr/bin/perl -lw use strict; for ( '0000'..'9999' ) { my %h; undef @h{split'',$_}; keys %h == 3 and print; }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Thank you sir - that did it :)
      Hooray . . . now on to the next step of my Evil Masterplan ;-)

      Cheers,
      M.ROMAN
Re^4: Find duplicate digits
by Anonymous Monk on Apr 07, 2010 at 13:14 UTC
    perldoc perlrun
    $ perl -MO=Deparse -le"%h=(), undef @h{split'',$_}, keys %h == 3 and + print for '0000'..'9999'" BEGIN { $/ = "\n"; $\ = "\n"; } ; (%h) = (), undef @h{split(//, $_, 0)}, keys %h == 3 and print $_ forea +ch ('0000' .. '9999'); -e syntax OK
    $ indicates a command prompt (a shell, like bash/csh/cmd...)
      Anonymous Monk,

      Thank you for this. I did as you kindly suggested and here is what happened:

      mrh@workstationmachine:~$ BEGIN { $/ = "\n"; $\ = "\n"; } bash: syntax error near unexpected token `}' mrh@workstationmachine:~$ ; bash: syntax error near unexpected token `;' mrh@workstationmachine:~$ (%h) = (), undef @h{split(//, $_, 0)}, keys +%h == 3 and print $_ forea bash: syntax error near unexpected token `=' mrh@workstationmachine:~$ +ch ('0000' .. '9999'); bash: syntax error near unexpected token `'0000'' mrh@workstationmachine:~$ -e syntax OK bash: -e: command not found
      ?