Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Adding to variable with sprintf()

by eXile (Priest)
on Apr 28, 2005 at 01:06 UTC ( [id://452187]=note: print w/replies, xml ) Need Help??


in reply to Adding to variable with sprintf()

$page_data = "the cow jump over the moon"; $new = join(" ", grep { length($_) > 3} split(/\s/, $page_data)); print $new;
See perlfunc manpages of split,join and grep for how this works, basically:
  • 1. split makes an array of the original line
  • 2. grep filters for elements longer than 3 chars
  • 3. join glues them together

Replies are listed 'Best First'.
Re^2: Adding to variable with sprintf()
by trammell (Priest) on Apr 28, 2005 at 04:01 UTC
    Slightly cleaner:
    $new = join ' ', grep length > 3, split ' ', $page_data;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-20 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found