lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: website search box


From: Andrew Wilson
Subject: Re: website search box
Date: Fri, 8 Jan 2010 01:37:04 +0000
User-agent: Mutt/1.5.18 (2008-05-17)

On Thu, Dec 17, 2009 at 09:58:32PM +0000, Graham Percival wrote:
> 1)  Do we ever have blah.html#foo ?  I thought that the first anchor
> was always foo.html#foo   (possibly with some weirdness if there's a
> space, parenthesis, or whatever in the node name)
> 
> 2)  If not, a dictionary would work:
>    if (%filenames[anchor_name] == 1) {
>       link .= '#' + anchor_name;
>    } else {
>       %filenames[anchor_name] = 1;
>    }
> 
> that's probably not proper perl syntax, but the basic idea should be
> solid.  %filenames is a global variable, of course.
> (is % the symbol for dictionary?)

That depends what you want to do with it.

#!/usr/bin/perl

use strict;
use warnings;

use v5.10;

# declare it
my %filenames;

# assign all of it - use %
%filenames = ("foo", 1, "bar", 37, "baz", 89, "qux", 91);

# access one value by key - use $
say $filenames{foo};

my $foo = $filenames{foo};

# access multiple values by key- @
my ($bar, $qux) = @filenames{"bar", "qux"};

say "$foo, $bar, $qux";

for your code snippet:

  if (exists $filenames{$anchor_name}) {
     $link .= "#$anchor_name";
  } else {
     $filenames{$anchor_name}++;
  }

would be more usual.

andrew




reply via email to

[Prev in Thread] Current Thread [Next in Thread]