Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • <hex> I went for my $foo = 0; foreach ($bar, $baz, $honk) { $foo = 1 if $_ ne 'foonly'; }

    Is that really what you mean? With it, the value of $foo depends only on $honk; the values of $bar and $baz don’t come into play at all, even though you test these variables.

    Also,

    <avar> if ("foonly" ~~ @vars) { $foo = 1 }

    I think that could be just $foo = "foonly" ~~ @vars;.

    But the solution I’d use is

    $foo = 1 if grep $_ ne 'foonly', $bar, $baz, $honk;

    I don’t consider tha

    • Is that really what you mean? With it, the value of $foo depends only on $honk; the values of $bar and $baz don’t come into play at all, even though you test these variables.

      Are you sure?

      #!/usr/bin/perl

      my $foo = 0;

      my $bar = 'foo';
      my $baz = 'foonly';
      my $honk = 'foonly';

      foreach ($bar, $baz, $honk) {
        $foo = 1 if $_ ne 'foonly';
      }

      print "$foo\n";

      That produces "1" for me, as I expected.

      The "if grep" isn't an idiom I'd previously heard. I'll bear it in mind in future.

      • Are you sure?

        Err, d’oh. Somehow I read the code as if you were resetting the variable on each iteration, which is clearly not the case. My bad.