in reply to Re^2: perl one-liner doesn't autochomp input
in thread perl one-liner doesn't autochomp input

ls|xargs|perl -pe 'y/ /:/' fixes the trailing ':' issue as xargs converts the ls output into a nice space separated stream.

Replies are listed 'Best First'.
Re^4: perl one-liner doesn't autochomp input
by halley (Prior) on Sep 07, 2004 at 13:39 UTC
    As having been bitten by the spaces-in-filenames issue (again) this weekend on Mac OS X, I would like to point out that scripts need to handle filenames with spaces correctly.

    Don't require a space-delimited stream of filenames, or if you must, then properly handle all names by way of double-quoting and/or escaping.

    Sure, you can put newlines in filenames on some filesystems, too, but it is *far* less prevalent. Spaces occur in user files (and system files) all the time, thanks to Win95 and MacOS guis which encourage human-descriptive filenames.

    --
    [ e d @ h a l l e y . c c ]

      As having been bitten by the spaces-in-filenames issue (again) this weekend on Mac OS X, I would like to point out that scripts need to handle filenames with spaces correctly.

      Or you Mac and Windows people need to stop getting creative with filenames. :)

      As an actual solution, you can try using xargs -0 in such situations on OS X. Get a copy of ppt's (Gr. That should link to PPT, not to some search results!) xargs if you're on a Windows machine.

Re^4: perl one-liner doesn't autochomp input
by Jasper (Chaplain) on Sep 07, 2004 at 13:39 UTC
    ls|perl -p0le 's/\n\b/:/g' is the same length using perl.
      This one is quite nice! - I guess someone did his regex homework... ;)