Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > print chop; VS chop; print;

Reply
Thread Tools

print chop; VS chop; print;

 
 
yusufm
Guest
Posts: n/a
 
      03-09-2006
Why does this work (prints out expected strings):

cat somefile | perl -ne 'chop; print;'

while this just prints out blank lines:

cat somefile | perl -ne 'print chop;'

thanks.

 
Reply With Quote
 
 
 
 
plalli@gmail.com
Guest
Posts: n/a
 
      03-09-2006
yusufm wrote:
> Why does this work (prints out expected strings):
>
> cat somefile | perl -ne 'chop; print;'
>
> while this just prints out blank lines:
>
> cat somefile | perl -ne 'print chop;'


Because that's what it's supposed to do.

Have you read the Perl built-in documentation for the function you're
using?

perldoc -f chop

chop does not return the chop'ed string - it returns the character that
was chopped. In your case, that's the newline character.

Paul Lalli.

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      03-09-2006
yusufm <(E-Mail Removed)> wrote:
> Why does this work (prints out expected strings):
>
> cat somefile | perl -ne 'chop; print;'



Because print() with no arguments prints $_


> while this just prints out blank lines:
>
> cat somefile | perl -ne 'print chop;'



print() prints the return value from chop().

What is the return value from chop()?

perldoc -f chop




But you probably should be using chomp() instead, or maybe
even the -l command line switch...


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
Can't print to print server =?Utf-8?B?cGVjaw==?= Wireless Networking 2 02-03-2005 02:41 PM
How to make use of "print to file" option by print =?Utf-8?B?enljZ3M=?= MCSE 1 01-04-2005 06:50 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments