Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to call a function on each item after a split?

by aaron_baugher (Deacon)
on Oct 09, 2012 at 03:41 UTC ( #997914=note: print w/ replies, xml ) Need Help??


in reply to How to call a function on each item after a split?

You could change your clean sub so it takes an array and returns an array. Then you can 'pipe' your data through it:

#!/usr/bin/env perl use Modern::Perl; sub clean { for (@_){ s/^\s+//; s/\s+$//; # this includes chomp } return @_; } my $str = 'The | quick | brown | fox | jumped| over | the | lazy | do +g. '; say for clean split /\|/, $str;

Aaron B.
Available for small or large Perl jobs; see my home node.


Comment on Re: How to call a function on each item after a split?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997914]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-08-20 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (108 votes), past polls