Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
chomp returns whatever is chomped off, not the line, so $a, will end up being a bunch of delimiters.

Well, actually chomp() returns the number of "characters" that were chomped - not the delimiters. So the OP's code is not going to work or I will admit that I am having a hard time understanding what this thing it supposed to do.

A short demo of chomp() on my Windows machine:

#!usr/bin/perl -w use strict; #chomp demo #running on Windows XP 32 bit... # chomp... "It removes any line ending that corresponds # to the current value of $/ (also known as # $INPUT_RECORD_SEPARATOR in the English module)." # # chomp() returns the total number of "characters" removed. # The "number of characters" depends.... my $count; print "Count\t Text\n"; my $x ="blah...with CRLF (Windows)\n"; $count = chomp ($x); print "$count \t\t $x\n"; print "setting \$/ to \\r\n"; $/ = "\r"; my $y ="blah...with CR (like Old Mac)\r"; $count = chomp ($y); print "$count \t $y\n"; print "This won't work...An \"extra new line\" remains...\n"; my $z ="blah again with CRLF (Windows)\n"; $count = chomp ($z); print "$count \t\t $z\n"; print "set \$/ back to \\n \n"; $/ = "\n"; $z ="blah again with CRLF (Windows) but 2 CRLF's\n\n"; $count = chomp ($z); print "only one of the \\n's is chomped\n"; print "$count \t\t $z\n"; print "end of demo\n"; __END__ Count Text 1 blah...with CRLF (Windows) setting $/ to \r 1 blah...with CR (like Old Mac) This won't work...An "extra new line" remains... 0 blah again with CRLF (Windows) set $/ back to \n only one of the \n's is chomped 1 blah again with CRLF (Windows) but 2 CRLF's end of demo

In reply to Re^2: using function output ananymous array vs. named array in foreach by Marshall
in thread using function output ananymous array vs. named array in foreach by ISAI student

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!
  • 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 about the Monastery: (15)
    As of 2015-07-06 18:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (80 votes), past polls