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
-
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.
|