Thanks! I "get it" now! deb
At 21:37:06, on 07.10.03: Cracks in my tinfoil beanie allowed Rob Dixon to seep these bits into my brain:, > Deb wrote: > > Rob, you were very helpful in showing me how the split and join > > work, but > > since I wasn't looking to change anything in $line except to > > replace the character separating the email addrs, I used what you > > gave me, and rebuilt > > the $line. I think it's kinda ugly, though, and I'm wondering if > > there > > is a better way. Here's what I did: > > > > $line = 'units = [EMAIL PROTECTED] > > [EMAIL PROTECTED]:[EMAIL PROTECTED]'; > > > > next unless $line =~ /^units/; > > (my $units, my $rest) = split (/=\s+/,$line); > > my @addrs = split /[:;\s]+/, $rest; > > my $tmpline = join ',', @addrs; > > $line = $units . " = " . $tmpline . "\n"; > > > > This accomplishes the task, but I'm using a lot of temporary > > variables. Is there a better way? > > I thought you were looking for an explanation of the > > next unless $line =~ s/// > > line. > > 'join' is (almost) the exact opposite of 'split' and, > given a separator and a list will return a string with > the elements of the list delimited by the separator. > Example > > join '#', 1, 2, 3, 4; > > returns > > '1#2#3#4' > > Your code above can be simplified, but it looks now like > you're just wanting to rebuild the original data with > commas in place of the colon, semicolon separators > than you started with. Here's a variation on my original > code which reads in your @lines array from the DATA > handle. Lets work from this to try to get where you want > to be. Depending on what you actually need it can be be > reduced further. > > Rob > > > > use strict; > use warnings; > > my @lines = <DATA>; > chomp @lines; > > foreach my $line (@lines) { > > next unless $line =~ s/^units\s+=\s+//; > > my @emails = split /[:;\s]+/, $line; > $line = 'units = ' . join ',', @emails; > print $line, "\n"; > } > > __DATA__ > units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED] > units = [EMAIL PROTECTED] > units = [EMAIL PROTECTED] [EMAIL PROTECTED] > > > OUTPUT > > units = [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED] > units = [EMAIL PROTECTED] > units = [EMAIL PROTECTED],[EMAIL PROTECTED] > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _< \_ _>(_) (_)/<_ \_| \ _|/' \/ (_)>(_) (_) (_) (_) (_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]