Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: perl one-liner doesn't autochomp input

by Anonymous Monk
on Sep 07, 2004 at 10:13 UTC ( [id://388979]=note: print w/replies, xml ) Need Help??


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

$ ls -1 | perl -l72pe1

Replies are listed 'Best First'.
Re^2: perl one-liner doesn't autochomp input
by bronto (Priest) on Sep 07, 2004 at 10:20 UTC

    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
      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 ]

        ls|perl -p0le 's/\n\b/:/g' is the same length using perl.
Re^2: perl one-liner doesn't autochomp input
by jbullock35 (Hermit) on Sep 07, 2004 at 13:02 UTC
    $ ls | perl -l72pe1

    This works and seems equivalent to

    $ ls | perl -l72pe "{}"

    But I don't understand the role of "1" (or digits in general) at the end of the command line, and I can't find any explanation in perlrun. I thought that they might affect the way that arguments are processed, but that doesn't seem right. Can someone clarify?

    Thanks,
    --John

      The 1 is there because you have to supply some Perl code to -e, but in this case you don't care to do anything, you just want the side effects of the other switches. Using a 1 by itself as your "script" is just like having 1; on a line by itself in a script — it does nothing.

      This can be used for such funny command lines as

      perl -please textfile # print the contents of the textfile perl -deal # fire up the debugger for interactive fiddling

      These are equivalent to

      perl -p -l -e '"ase"' textfile perl -d -e '"al"'

      where you simply have a string on a line by itself as the only statement in your "code", resulting in a no-op.

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found