Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: one-line split file sequence checker

by wdef2 (Acolyte)
on Jan 22, 2008 at 22:31 UTC ( #663709=note: print w/replies, xml ) Need Help??

in reply to Re^2: one-line split file sequence checker
in thread one-line split file sequence checker

perl -e 'for $c (sort {$a<=>$b} map(/.(\d+)$/, <*[0-9]>)){ ++$n == $c || print map("$_\n", $n...$c-1) ; $n=$c }'

Ah, that's getting closer to the line noise effect I was looking for, thanks ;=) Time to read up on that map command and why <> is globbing filenames in the current dir. I'm almost pleased to see there's no offered improvement to the basic idea. There's no way to get rid of that 'for' iterator, or the 'print'? -lane ? Any shorthand for sort {$a<=>$b}? Just wondering.

Replies are listed 'Best First'.
Re^4: one-line split file sequence checker
by kyle (Abbot) on Jan 22, 2008 at 23:08 UTC

    If you're just golfing, you can throw away a few characters:

    perl -e 'for$c(sort{$a<=>$b}map/(\d+)$/,<*[0-9]>){++$n==$c||print map" +$_\n",$n..$c-1;$n=$c}'

    If you want to get rid of the sort, try an array:

    perl -le '@f=map/(\d+)$/,<*[0-9]>;@x[@f]=@f;for(1..$#x){$x[$_]||print} +'

    Note that if you have a file named '0', it will basically ignore it, but that was the original behavior too. This may eat more memory, but I doubt that will be an issue until you're working with millions of files.

      You can golf that a bit more:
      perl -le '@x[@f]=@f=map/(\d+)$/,<*[0-9]>;$x[$_]||print for+1..$#x'
        That @x[@f]=@f had me puzzled for a while, but it seems it is the same as:


        So just @f is always expanded into a list without (), and () is not necessary when defining an array from a list?

        I'm still looking at the next one.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://663709]
[stevieb]: ohhh, aaaand, I just learned that you can power an Arduino (Uno at least) by connecting any single analog pin to 5v on the Pi GPIO! That's bloody handy

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-06-22 23:05 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.