Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Retain first 4 characters of a string

by perlnoobster (Sexton)
on Aug 24, 2012 at 13:49 UTC ( #989540=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Retain first 4 characters of a string
in thread Retain first 4 characters of a string

Sagar, I have changed the requirement slightly, basically the colours below:

baby blue baby pink black dark blue brown dark purple green orange hot pink light purple red white yellow
If the space between them exists then how do i retain just the first letter of the words e.g hot pink would be hp and light purple would be lp? I can't figure out how to do it with the split and join if there is no space between two words then simply retain the colour i.e. red would be red Thank you :)


Comment on Re^4: Retain first 4 characters of a string
Download Code
Re^5: Retain first 4 characters of a string
by Anonymous Monk on Aug 24, 2012 at 14:04 UTC
    Really? When you specify the number of times to match, enter 1
Re^5: Retain first 4 characters of a string
by johngg (Abbot) on Aug 24, 2012 at 19:00 UTC
    $ perl -Mstrict -Mwarnings -E ' > open my $inFH, q{<}, \ <<EOF or die $!; > baby blue > baby pink > black > dark blue > brown > dark purple > green > orange > hot pink > light purple > red > white > yellow > light powder blue > EOF > > say for > map { > @$_ > 1 > ? join q{}, map { substr $_, 0, 1 } @$_ > : $_->[ 0 ] > } > map { [ split ] } > <$inFH>;' bb bp black db brown dp green orange hp lp red white yellow lpb

    Cheers,

    JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-08-29 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls