On Fri, Nov 23, 2001 at 12:03:08PM +0900, David Alan Black wrote:
> On Thu, 22 Nov 2001, Jos Backus wrote:
> >     x, ext, ext2 = mbox.split('-')
> >
> > to do this. But I'm looking for a replacement in the succinct
> >
> >     ($ext) = $mbox =~ /.*?-(.+)$/;
> >     ($ext2) = $ext =~ /.*?-(.+)$/;
> Isn't your #split version shorter than the Perl version?

Yes, but it does not do the same thing. I do like the Ruby version better than
the Perl version, mind you.

What it boils down to is that I am looking for a way to do the Ruby equivalent
of

    ($ext) = $mbox =~ /.*?-(.+)$/;

Now,

    ext = mbox[/RE/]

doesn't work because RE can't be anchored and thus ext is assigned all of what
RE matches in mbox. It would be _really_ great if one could say

    ext = mbox[/-(.+)/]

but that doesn't dtrt.

    ext = mbox.scan(/-(.+)/)[0]

sort of works but returns an Array;

    ext = mbox.scan(/-(.+)/)[0][0]
    ext = mbox.scan(/-(.+)/).pop.pop

works only when the scan matches, but throws a NameError on nil otherwise.

-- 
Jos Backus                 _/  _/_/_/        Santa Clara, CA
                          _/  _/   _/
                         _/  _/_/_/             
                    _/  _/  _/    _/
josb / cncdsl.com     _/_/   _/_/_/            use Std::Disclaimer;