Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You've proved quite a few times that chomp is not a good choice, in your case. Your case however does not represent everyone else's common uses. By your own definition here, a new line could exist and there could still be an error. In that case shouldn't your code be looking at the structure of the data it is attempting to load and relying on some other input other than the newline to mean your data is valid?

You've also mentioned chop several times but unless you (chop() eq $/ ) or die chop doesn't do you any more good than chomp did. I also believe it has been pointed out that your chop construct will actualy fail if $/ is more than one line, and in addition chomp isn't mean to remove record seperators, it is meant to portable remove a new line. As a feature chomp doesn't fail if there is no new line, but few of perls functions will die if they fail.

You attack everyone here as following groupthink and yet you can't seem to accept a new point of view yourself. I havn't seen anyone claim that chomp is ALWAYS the right choice, yet you claim it is ALWAYS the wrong choice. That flies in the face of the facts before you, chomp is quite often exactly what people want it to be, and when it isn't, then don't use it. Don't through it (and the people who use it) out simply because you have had a bad experience with it. Can it be misused? Of course it can, and is, but that realy doesn't mean it is always a bad choice.

If you want to use it as a measure of skill then fine, but be sure to make your requirements such that chomp alone is the wrong choice. Maybe something like "Write a script to parse a data file removing line endings and verify that each line ends with a terminator. Assume the files are provided on the command line and output them to STDOUT". That is my first attempt writing such a problem so please don't be too critical ;)

#!/usr/bin/perl use strict; use warnings; while (<>) { chomp or die "Record is missing terminating new line."; print; }


___________
Eric Hodges

In reply to Re^7: chop vs chomp by eric256
in thread chop vs chomp by Moron

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-18 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found