Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: string manipulations.

by holli (Abbot)
on Nov 23, 2006 at 08:32 UTC ( [id://585684]=note: print w/replies, xml ) Need Help??


in reply to string manipulations.

somewhat similar to davido's solution, but using split:
use strict; use warnings; my $str="A: Gold, Black, Purple, Blue, Red B: Black, Neon Pink, Ne +on Yellow, Neon Green, Neon Purple, Red, White, Neon Orange, Navy"; # create a hash using the A:, B: parts as keys and the following strin +gs as values my %str = grep { $_ } map { s/^\s+//; s/\s+$//; $_; } split /([A-Z]:)/, $str; # iterate the hash and make the value strings to # arrayrefs for ( sort keys %str ) { $str{$_} = [ split /, /, $str{$_} ]; } # output for ( sort keys %str ) { print "Array $_ ", join (", ", @{$str{$_}}), "\n"; }


holli, /regexed monk/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-28 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found