in reply to ignoring the first element of an array


Here are three possible ways:
# Use a sentinel variable my $first; foreach my $well (@derivative) { next unless $first++; # Do something } # Use an array slice foreach my $well (@derivative[1..$#derivative]) { # Do something } # Use the array indices foreach my $i (1..$#derivative) { my $well = $derivative[$i]; # Do something }

--
John.

Replies are listed 'Best First'.
Re: Re: ignoring the first element of an array
by Anonymous Monk on Feb 03, 2003 at 12:56 UTC

    The fourth way! (sounds like a book title:)

    my $tmp = shift@derivative; for my $well (@derivative) { # } unshift @derivative, $tmp;

      The destructive way...

      for my $well (splice @derivative, 1, @derivative) { # }

      Cheers,

      -- Dave :-)


      $q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print
      or the destructive and funky version of your code ;-)
      for ( do {shift @derivative; @derivative} ) { # }

      -- Hofmator