in reply to Split on 2nd Occurence

Just to be different:

my $ipaddr = "192.168.0.11"; my ($prefix) = join('.',@{[split(/\./,$ipaddr)]}[0,1]);

Replies are listed 'Best First'.
Re: Re: Split on 2nd Occurence
by chip (Curate) on Jan 11, 2002 at 23:48 UTC
    Even this different approach would be clearer with a list slice:

    my $prefix = join '.', (split /\./, $ipaddr)[0,1];

        -- Chip Salzenberg, Free-Floating Agent of Chaos

Re: Re: Split on 2nd Occurence
by blakem (Monsignor) on Jan 12, 2002 at 00:21 UTC
    That seems like a lot of punctuation:
    my ($prefix) = join('.',@{[split(/\./,$ipaddr)]}[0,1]);
    Can also be written like this:
    my $prefix = join '.', (split /\./, $ipaddr)[0,1];
    Update: Oops.... much like the other "dup" in this thread this was wholly unintentional, and not blatent copying.

    -Blake