Nice, Bob, very elegant indeed!

I do have a question, I notice you use "and" like an if..then.  What if you
wanted to do two things if that =~ held true?  Is that possible?

Thanks.

- Bryan




> Bryan Harris wrote:
>> One of my favorite things about perl is that long and tedious
>> solutions can often be replaced by incredibly elegant and concise
>> ones. 
>> 
>> I'm writing a sequence generator.  I've got most of it handled, but
>> this part bugs me.  I want it to take the variable $field containing,
>> e.g.: 
>> 
>> 4.3:8.3
>> 
>> And turn it into an array:
>> 
>> 4.3  5.3  6.3  7.3  8.3
>> 
>> Here's what I've got:
>> 
>>      if ($field =~ /^(\S+(\.(\d*))):(\S+(\2))$/) {
>>          ($a,$b) = ($1,$4);
>>          while ($a <= $b) { push @vector, $a++; }
>>      }
>> 
>> I guess it just feels really sloppy, like I should be able to do the
>> last two lines in a single map command or something.
>> 
>> Obviously it's not urgent, I just like seeing how the masters do this
>> kind of thing.  =)
> 
> I don't claim to be a master, but you can do something along the lines of:
> 
> $range = '4.3:8.3';
> $range =~ /(\d+).(\d+).(\d+).\2/ and print map "$_.$2 ", $1 .. $3;
> 
> Since it appears you require that the fractional part be the same for both
> ends of the range, I'm just capturing the integer parts and using Perl's
> range operator to build the list to feed to map()



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to