Groups Home | Help | Sign in
Go to Google Groups Home   
Web    Images    Groups    News    Froogle    Local    more ยป
  Advanced Groups Search
  Preferences
comp.lang.perl > Perl problem, possible bug?
Fixed font - Proportional font
Jim Dawson
Aug 14 2003, 3:59 am   show options
Newsgroups: comp.lang.perl
From: jimdaw...@myrealbox.com (Jim Dawson) - Find messages by this author
Date: 13 Aug 2003 20:59:07 -0700
Local: Thurs, Aug 14 2003 3:59 am
Subject: Perl problem, possible bug?
Reply to Author | Forward | Print | View Thread | Show original | Report Abuse

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.

Google Home - Terms of Use - Privacy Policy - Jobs, Press, & Help

©2005 Google