Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Ok, this isn't that tricky if you disect the command line switches one at a time:

-e

This means essentially "execute the following code". As you can see, in this particular case, the following code is nothing at all; zilch.

-p

This means wrap the -e code in the following loop:

while( <> ) { # -e code goes here (nothing, in this case) print $_; }

Now for the -i: That means do an in-place edit. Whatever characters immediately follow -i will be appended to the input file's name for the purpose of creating a backup file. Often you'll see -i.bak which means take file foo and create a backup named foo.bak. Well, in your case, instead of .bak you're using ~, so it creates a backup named foo~.

Now put it all together:

  1. -i~ Do an in-place edit, but first create a backup file named "inputfile~" (or in your case, foo~).
  2. -p loop over the input file (foo), and after executing the -e code, print the line to the output file (which is the same filename as the original input file, because you're doing in-place editing thanks to -i
  3. -e Execute the following code within the while loop: '' (in other words, do nothing inside the loop except the -p loop's default; print.

I hope this helps, but if it doesn't, see perlrun for more detail. Also (shameless plug), I wrote a node awhile back that went into greater detail on the subject of learning how to compose Perl one liners. The node is here: Re: One Liners. I think you'll find it to be a pretty easy introduction to Perl's command line switches and Perl one-liners. Good luck!


Dave


In reply to Re: perl's command line snippet which I read from a perl article ( perl tutrous ) by davido
in thread perl's command line snippet which I read from a perl article ( perl tutrous ) by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (2)
    As of 2020-02-22 04:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (98 votes). Check out past polls.

      Notices?