moderated >> perl 5.8.6 and chomp behavior

by jerry davis » Tue, 11 Oct 2005 12:01:24 GMT

I have been doing this for years, but I just tried it with 5.8.6
Can anyone try this using 5.8.6 to confirm my error.

open WP, "< $myfile" or die "can't open $myfile, $!\n";
my @wpts = <WP>;
close WP;
chomp @wpts;

I went in the debugger, and just before the chomp I had a number of elements,
after the chomp, I have only the last element.

I know I have done this same thing for years.

Jerry
--
Registered Linux User: 275424
Today's Fortune: Ninety percent of everything is crap.
-- Theodore Sturgeon

moderated >> perl 5.8.6 and chomp behavior

by Yitzchak Scott-Thoennes » Wed, 12 Oct 2005 08:09:19 GMT



Works just fine for me:

$ cat foo
hello
there
how
are
you
I
am
fine
thanks
$ perl5.8.6 -w
my $myfile="foo";
open WP, "< $myfile" or die "can't open $myfile, $!\n";
my @wpts = <WP>;
close WP;
chomp @wpts;
print join ":",@wpts;
__END__
hello:there:how:are:you:I:am:fine:thanks

Similar Threads

1. SOLVED - perl 5.8.6 and chomp behavior

On Monday 10 October 2005 11:01 pm, jerry davis wrote:

I really didn't expect anything from this.
It was a fluke.

I did an od -c on the input file and there were MSDOS type line endings in it.
When I chomped, it effectively, got rid of all the new lines but left the \r's 
in there, which caused only the last line to show up.

Whew!!! I couldn't imagine something so basic as chomp breaking.
Sometimes I hate cross-platform stuff.

Jerry


> I have been doing this for years, but I just tried it with 5.8.6
> Can anyone try this using 5.8.6 to confirm my error.
>
> open WP, "< $myfile" or die "can't open $myfile, $!\n";
> my @wpts = <WP>;
> close WP;
> chomp @wpts;
>
> I went in the debugger, and just before the chomp I had a number of
> elements, after the chomp, I have only the last element.
>
> I know I have done this same thing for years.
>
> Jerry

-- 
Registered Linux User: 275424
Today's Fortune: It took me fifteen years to discover that I had no talent 
for writing,
but I couldn't give it up because by that time I was too 
famous.
		-- Robert Benchley

2. equivalent of chomp from perl in C

3. equivalent of chomp in perl

Hi,
Is there an equivalent to the perl command chomp in C? And if there is
no exact equivalent command, how would I go about removing the "\n" at
the end of a stdin?

Thank you,
Natalie

4. Perl style chomp() - PHP

5. [PHP] Perl style chomp()

On 11/1/07, Jim Lucas < XXXX@XXXXX.COM > wrote:
> I noticed, while perusing the chop() manual page, that some people were giving examples of Perl's
> chop() and chomp() functions.  Comments made about both said the examples were good, but not correct.

what about trim(), rtrim() and ltrim() ? seems unnecessary to reinvent
the wheel. if you want an array one, just make it recurse like you
did.

- mike

6. Inconsistent behavior between SQL*Plus and Perl DBI - Oracle

7. net use and perl (wierd behavior)

I need some assitance. Let me first tell you what I have. 

I have a unix network drive that I need access to using perl under
cygwin on our win 2000 server. This network drive is password
protected so I have decided to use the net use system command to
access it.

Here is my problem:

when I first issue the command in the script

`net use q:"\\\\\\\\xxx.xx.xx.xxx\\home\\status\\lists" password\!
\/USER:user \/persistent:no`;
 
This works like a champ. I am able to view contents of flat files and
everything. Here is my problem. It seems that the drive timesout or
something after about ten minutes of inactivity and the I get errors
like

device in use
Cannot find the drive

I have already tried to use net use delete to delete the drive letter
before I issue the command above and that returns telling me "Cannot
find drive"

here is a snippet of the complete code (obvious changes to protect
information)

## process the list for sites

`net use q: /delete /yes`;
if (!-e "q:site.XX")  {
`net use q:"\\\\\\\\xxx.xx.xx.xxx\\home\\status\\lists" password\!
\/USER:user \/persistent:no`;
} 
$stuff = `ls -al q\:`;
print "-- $stuff --\n";

Any help would be appreciated

8. Asian-font behavior on Solaris-Linux Perl/Tk versus Win32's