And having given you two fish, let me suggest at this point that it would be well worth your while learning to fish.
 
A great place to start is perldoc.com, which should contain just about everything you could need.
 
How you could have found out how to do what you wanted.
 
First, typing "split" into the search engine, sends you to
 
 
which explains in detail how split works. At a stretch, you might realise that you could split on the commas, and spaces.
 
perlre - http://perldoc.com/perl5.6.1/pod/perlre.html would help you find a split pattern to do what you require.
 
Of course, that wouldn't QUITE do what you need. You need to "get rid of whitespace".
 
Looking at the index for the Frequently Asked Questions, you see that perlfaq4 http://perldoc.com/perl5.6.1/pod/perlfaq4.html covers "Data Manipulation".
 
Looking through you see "How do I strip blank space from the beginning/end of a string?", clicking on the link takes you to.
 
 
of which my favourite version is the simple
 
$string =~ s/^\s+//;
$string =~ s/\s+$//;
 
So, you would do your split as normal, and then remove leading and trailing space.
 
Once you had read a bit of perlre to see how the FAQ result worked, you would have more confidence to do something like
 
$record =~ s/\s//g; before you do the split, once you knew that there wasn't supposed to be any spaces anywhere ( if that was true ).
 
I hope this example will get you where you want to go faster, without having to waste time asking a linux mailing list.
 
A great alternative if you are really stuck would be to go to what is arguably the "main" perl channel.
 
irc://irc.rhizomatic.net/#perl   ( assumes you have mozilla ).
 
Don't ask perl questions here, ask meta-questions. "Where could I find docs about xxxxxxx". They will usually be more than happy to answer THAT sort of questions. Other perl channels will usually suffice as well, although poilcies on helping people can vary.
 
Adam
 
----- Original Message -----
From: henry
Sent: Monday, March 04, 2002 6:58 PM
Subject: [SLUG] ask perl

Dear List:
    I use split to parse string
as follows:
 
     #!/usr/bin/perl -w
     $record ="Pacific:ocean"
     my($a,$b)=split(/:/,$record);
     print "$a\n";
     print "$b\n";
 
    My problem is :
        In practical use , I usually get
                                    $record = "             a :        b" ;
 
    How do I  take out those blanks ?
   
BestRegards
Henry

Reply via email to