Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Perl problem, possible bug?

Path: archiver1.google.com!postnews1.google.com!not-for-mail
From: jimdaw...@myrealbox.com (Jim Dawson)
Newsgroups: comp.lang.perl
Subject: Perl problem, possible bug?
Date: 13 Aug 2003 20:59:07 -0700
Organization: http://groups.google.com/
Lines: 31
Message-ID: <e1f9bda.0308131959.6475e474@posting.google.com>
NNTP-Posting-Host: 209.16.201.185
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1060833547 30100 127.0.0.1 (14 Aug 2003 03:59:07 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 14 Aug 2003 03:59:07 GMT

I was writing a subroutine to extract fields from lines of text when I
ran into an issue. I have reproduced this error on Perl 5.8 on AIX,
5.8 on Linux and 5.6 on Windows.

############### CUT HERE ###############
#!/usr/bin/perl -w

my @list = ("field1       field2 field3");

sub stripws($)
{
    $_[0] =~ s/\s//g;
    return $_[0];
}

foreach (@list)
{
    my $x = stripws(substr($_,10,10));
    print "$x\n";
}
############### CUT HERE ###############

Here 'field2' represents a variable-length field. I want to strip out
that column, remove whitespace from it, and assign it to $x. You would
expect $x to be equal to 'field2', but instead $x is 'field2fiel', as
if it is stripping the whitespace before calling the stripws()
function.

Is there something I am missing here or is this a bug?

Thanks in advance.