marcelo.magallon has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow Monks,
this one has me baffled...
I have the following code which reads files like http://oss.sgi.com/projects/ogl-sample/registry/APPLE/client_storage.txt
sub read_spec($) { my $filename = shift; local $/; open(my $fh, "<$filename") or die "Can't open filename"; my $content = <$fh>; $content =~ s{\s+$}{}m; # ... }
If you take a look at the file I mentioned above, you'll notice it has this:
Name
APPLE_client_storage
<tab here>
Name Strings
...
Running the above code on this file leaves the tab character in place.
Adding:
$content =~ s{\s+$}{}m; $content =~ s{\t+$}{}m;
has the desired effect. As well as this:
$content =~ s{[ \t]+$}{}m;
Ideas? My understanding of \s is flawled somewhere. After following manpages around, is ended up in isspace(3), which makes me beleive that the code should work as I expect it to.
Marcelo
Update: Fixed formatting...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: \s vs \t
by ikegami (Patriarch) on Jan 05, 2005 at 17:15 UTC | |
by dragonchild (Archbishop) on Jan 05, 2005 at 17:58 UTC | |
by ikegami (Patriarch) on Jan 05, 2005 at 18:17 UTC | |
by marcelo.magallon (Acolyte) on Jan 05, 2005 at 17:39 UTC |