I have two pieces of code. The first one is what I wanted. BUt why is it the second one is giving me 1’s and 0’s (is my english correct, or is it “1s and 0s”) and not “johnchrismandy”.
foreach (@data) {
print ;
}
//output
john
chris
mandy
foreach (@data) {
print chomp ;
}
//output
110
UPDATE::
Thank you guys, I understand it more now.
But I don't understand the last part of the doc.
=>
You can actually chomp anything that's an lvalue, including an assignment:
chomp($cwd = pwd);
This is documented behaviour: “It returns the total number of characters removed from all its arguments.” You want
Note that
$_is aliased to the element of@data, so@datais getting modified too. If you don’t want that to happen.About the last line of the docs:
my $item = $_;returns$itemas an lvalue (a value suitable for the left-hand side of an assignment). As such,can be written as