What does chop do?

Posted on 2007-11-20
Medium Priority
Last Modified: 2012-06-21
ddump is a utility that dump Debugging Information from elf file to TEMP.    What do the last two lines in below code snippet exactly do?

open TEMP, "$ddump -D $elf|" or die("\nError dumping file!\n");
$line = <TEMP>;
Question by:naseeam
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 480 total points
ID: 20322468
LVL 85

Assisted Solution

ozo earned 560 total points
ID: 20322476
perldoc -f chop
       chop VARIABLE
       chop( LIST )
       chop    Chops off the last character of a string and returns the char-
               acter chopped.  It is much more efficient than "s/.$//s"
               because it neither scans nor copies the string.  If VARIABLE is
               omitted, chops $_.  If VARIABLE is a hash, it chops the hash's
               values, but not its keys.

               You can actually chop anything that's an lvalue, including an

               If you chop a list, each element is chopped.  Only the value of
               the last "chop" is returned.

               Note that "chop" returns the last character.  To return all but
               the last character, use "substr($string, 0, -1)".

               See also "chomp".
LVL 39

Assisted Solution

Adam314 earned 320 total points
ID: 20322560
In the code you have above, it would probably be safer to use chomp
LVL 48

Accepted Solution

Tintin earned 640 total points
ID: 20322671
$line = <TEMP>;

Reads one line from the filehandle TEMP, ie: the output of the ddump command


Removes the last character from value of $line.


Author Closing Comment

ID: 31410195
Quick response.  Great Answers!

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question