On Wed, 20 Apr 2005 17:04:50 +0300
Offer Kaye <[EMAIL PROTECTED]> wrote:

> On 4/20/05, Paul Kraus wrote:
> > Why does this work....
> > my $date = 'one   |  two   |three      |';
> > my @record = map ( whitespace($_), (split /\|/,$_) );
> 
> No, it won't work - you need to replace the $_ at the end with $date
> 
> > sub whitespace {
> >   my $string = shift;
> >   $string =~ s/^\s+|\s+$//g;
> >   return $string;
> > }
> > 
> > but this does not ....
> > my @record = map ( $_=~ s/^\s+|\s+$//g,(split /\|/,$_) );
> > 
> 
> 1. Again, the $_ at the end needs to be $date
> 2. This doesn't work because the s/// returns the number of
> subtitutions made, not the string it changed, so that is what map gets
> and passes (a list of numbers). See "perldoc perlop" for details. You
> can use the block form of map, as follows:
> my @record = map {s/^\s+|\s+$//g; $_} split /\|/,$date;
> This works because the $_ statement at the end of the block now
> constitutes the return value.
> 3. But there's an even easier way, without having to use map:
> my @record = split /\s*\|\s*/,$date;

------>this seems it cant delete spaces of the last element.

> HTH,
> -- 
> Offer Kaye
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


-- 
Whatever you do will be insignificant,but 
the important is you do it!

It doesn't matter who you are, it's what 
you do that takes you far!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to