If you're trying to figure out a command, write a tiny script. Run it in the debugger: perl -d myscript.pl; You can also run the debugger without any script, to experiment with a command. I use perl -demo because it's memorable, though the 'mo' don't mean anything useful.

chomp() will remove a trailing newline, but not other characters. If passed an array, it will process each element of the array. So if you care, you can use it to determine whether there used to be a newline in the variable. I don't remember ever seeing anyone care, but the potential is there.

DB<1> $a = "a \n" DB<2> x $a 0 'a ' DB<3> print chomp $a 1 DB<4> x $a 0 'a ' DB<5> print chomp $a 0 DB<6> x $a 0 'a ' DB<7> @a = ( "abc\n", "def\n", "ghi\n" ) DB<8> x \@a 0 ARRAY(0x8406258) 0 'abc ' 1 'def ' 2 'ghi ' DB<9> print chomp @a 3 DB<10> x \@a 0 ARRAY(0x8406258) 0 'abc' 1 'def' 2 'ghi'

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: Chomp Command by TomDLux
in thread Chomp Command by sarathi.mh

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, details, 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, summary, 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.