"chomp,chop" usage i.e. chop immediately after chomp

Discussion in 'Perl Misc' started by martin, Apr 15, 2006.

  1. martin

    martin Guest

    Hi, I have been reading the postings on chopm and chop. I am wondering
    if one would use

    while <INPUTFILE>
    chomp;chop;
    .....
    ....

    what is the use of this, doesn't chomp already remove the end of line
    delimiter whatevere that happens to be.


    Thanks, Martin
    martin, Apr 15, 2006
    #1
    1. Advertising

  2. martin wrote:
    > Hi, I have been reading the postings on chopm and chop. I am
    > wondering if one would use
    >
    > while <INPUTFILE>
    > chomp;chop;


    Well, sure, if for some odd reason you want to remove the last character of
    the string...

    >
    > what is the use of this,


    Nothing particularly useful.

    > doesn't chomp already remove the end of line
    > delimiter whatevere that happens to be.


    Yeah, but chop() removes any trailing character, not just a \n.

    jue
    Jürgen Exner, Apr 15, 2006
    #2
    1. Advertising

  3. martin <> wrote:
    > Hi, I have been reading the postings on chopm and chop. I am wondering
    > if one would use
    >
    > while <INPUTFILE>



    Please do not post pseudocode, post real Perl code, with parenthesis
    and curlies and whatnot.


    > chomp;chop;


    > what is the use of this,



    It removes the line ending sequence if one is present, and then
    removes one more character from the end of $_.

    ie. it doesn't appear to be of much general use at all.


    > doesn't chomp already remove the end of line
    > delimiter whatevere that happens to be.



    Yes. (but newline is not a "delimiter")

    Then chop() does what chop() does, namely removes whatever character
    is now at the end.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 15, 2006
    #3
  4. martin

    Joe Smith Guest

    martin wrote:
    > Hi, I have been reading the postings on chopm and chop. I am wondering
    > if one would use
    >
    > while <INPUTFILE> {
    > chomp;chop;


    That only makes sense if the input file is in DOS format and being
    processed on a Unix-style system. Then chomp() would remove the
    "\n" and chop() would remove the "\r". There are better ways.
    -Joe
    Joe Smith, Apr 15, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ram
    Replies:
    0
    Views:
    575
  2. Guadala Harry
    Replies:
    4
    Views:
    1,498
    =?Utf-8?B?aGFyaSBwcmFzYWQ=?=
    Jun 15, 2004
  3. Johnathan Smith

    chop and chop!

    Johnathan Smith, Jan 8, 2008, in forum: Ruby
    Replies:
    2
    Views:
    125
    darren kirby
    Jan 8, 2008
  4. yusufm

    print chop; VS chop; print;

    yusufm, Mar 9, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    108
    Tad McClellan
    Mar 9, 2006
  5. zoomcart.com

    Chop vs Chomp

    zoomcart.com, Apr 1, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    156
    Tad J McClellan
    Apr 2, 2008
Loading...

Share This Page