Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why does chomping a list remove all its elements

Reply
Thread Tools

why does chomping a list remove all its elements

 
 
Lowell Kirsh
Guest
Posts: n/a
 
      02-11-2004
Why does the following not work?

open(FILES, "< musiclist2.txt");
@files = <FILES>;
print "unchomped\n";
print @files;
print "chomped\n";
chomp @files;
print @files;

It gives:

unchomped
(Cream) - the very best of cream
(Janis Joplin) - Greatest Hits
(Jethro Tull) - Heavy Horses
(Jethro Tull) - Thick As A Brick
chomped


Lowell
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-11-2004
Lowell Kirsh wrote:
> Subject: why does chomping a list remove all its elements


It doesn't.

Please post a *complete* script that people can copy and paste, and
that, unlike the code you posted, illustrates the problem you say you
have.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
 
Jon Landenburer
Guest
Posts: n/a
 
      02-11-2004
Interesting . When I did:
#!/bin/perl
@files = ("AAAAA", "BBBBB", "CCCCC", "DDDDDD");
print @files;
print "chomped\n";
chomp @files;
print @files;

print "test2\n";
@files = ("AAAAA\n", "BBBBB\n", "CCCCC\n", "DDDDDD\n");
print @files;
print "chomped\n";
chomp @files;
print @files;

I got:
AAAAABBBBBCCCCCDDDDDDchomped ##No reult of chomp because no CR
AAAAABBBBBCCCCCDDDDDDtest2
AAAAA
BBBBB
CCCCC
DDDDDD
chomped
AAAAABBBBBCCCCCDDDDDD[Hit return to continue] ## Yesiree it removed all the \n'
I learned something today.
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-11-2004

Lowell Kirsh <(E-Mail Removed)> wrote:
> Why does the following not work?
>
> open(FILES, "< musiclist2.txt");
> @files = <FILES>;
> print "unchomped\n";
> print @files;
> print "chomped\n";
> chomp @files;
> print @files;
>
> It gives:
>
> unchomped
> (Cream) - the very best of cream
> (Janis Joplin) - Greatest Hits
> (Jethro Tull) - Heavy Horses
> (Jethro Tull) - Thick As A Brick
> chomped


Chances are that your prompt is overwriting the last line of output:
it won't have a newline at the end, remember. Try adding
print "\n";
on the end.

Ben

--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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
Webrick Servlet: 'chomping' ? Is this slowing it down? John Pritchard-williams Ruby 0 08-28-2008 07:35 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Chomping and stomping John Maclean Ruby 16 02-02-2006 09:03 PM
chomping $@ jemptymethod@gmail.com Perl Misc 5 01-22-2006 09:57 PM
"chomping" an array at read time Victor Reyes Ruby 5 01-10-2006 07:54 PM



Advertisments