in reply to A Tagcloud For Cory Doctorow

As an alternative to:

my @words = split; my @tags = (); # tags found at the end of this note while (my $tag = pop @words) { last if $tag !~ /^\@/; # Not a tag, bail $tag =~ s/^@//; # Trim the "@" push @tags, $tag; push (@{$lines{$tag}}, \$this_line); }

You could do it like this:

my @tags; # tags found at the end of this note for my $tag ( reverse split ) { last unless $tag =~ s/^\@//; # Not a tag, bail push @tags, $tag; push @{ $lines{ $tag } }, \$this_line; }

Replies are listed 'Best First'.
Re^2: A Tagcloud For Cory Doctorow
by McD (Chaplain) on Aug 28, 2008 at 14:01 UTC
    Yup, that's much cleaner. Nice!