Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: perl one-liner doesn't autochomp input

by bronto (Priest)
on Sep 07, 2004 at 10:20 UTC ( [id://388980]=note: print w/replies, xml ) Need Help??


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

Oh, damn! How I would like to front-page this! So GREAT!

Update: apart that it adds a trailing ":", which I don't like to be there :-(

Update: so do also tachyon's and keszler's solutions: the trailing ":" should not be there

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
Re^3: perl one-liner doesn't autochomp input
by tachyon (Chancellor) on Sep 07, 2004 at 12:40 UTC
    ls|xargs|perl -pe 'y/ /:/' fixes the trailing ':' issue as xargs converts the ls output into a nice space separated stream.
      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.

      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... ;)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found