Jonathan, et al --

...and then Jonathan E. Paton said...
% 
%  --- Ned Cunningham <[EMAIL PROTECTED]> wrote: > Snip
% > 
...
% > @data = split(/\|/,$line);
% > $newnum=$newnum+1;
% > printf WRFILE ("0%9d",$newnum);
% > 
% > print WRFILE ";", @data, ";";
...
% > 
% > I want to write to a file all of the array(@data), except the first
% > field????
% 
% @data[1..-1]
% 
% means the array @data from element 1 to the last element.

Hey, that's pretty slick.  For this case it's certainly nicer than

  ($junk,@data) = split(/\|/,$line);

but I typically to use that when I know that I won't need the first
element(s) of an input.

Hmmm...  Of course, I can't get it to work for me under 5.6.1 on Linux:

  [zero] [10:01am] ~>  echo "1|2|3|4" | perl -e ' chomp ($line = <>) ; @data = split 
(/\|/,$line) ; print "l = $line\n" ; print "D = @data[1..-1]\n" ; print "d = @data\n" 
;'
  l = 1|2|3|4
  D =
  d = 1 2 3 4
  [zero] [10:02am] ~>  echo "1|2|3|4" | perl -e ' chomp ($line = <>) ; @data = split 
(/\|/,$line) ; print "l = $line\n" ; print "D = @data[1..3]\n" ; print "d = @data\n" ;'
  l = 1|2|3|4
  D = 2 3 4
  d = 1 2 3 4

For peeling off N items from the back end I suppose one does something
like

  @data[0..($#data-N)]

as in

  [zero] [10:06am] ~>  echo "1|2|3|4" | perl -e ' chomp ($line = <>) ; @data = split 
(/\|/,$line) ; print "l = $line\n" ; print "D = @data[0..($#data-2)]\n" ; print "d = 
@data\n" ;'
  l = 1|2|3|4
  D = 1 2
  d = 1 2 3 4

Hmmm...  Why isn't that (N-1) above?  Oh, $# is not the length but the
index of the last element, or (length - 1); how convenient.

Anyway, is that the recommended way to print all but the last N elements?


% 
% Jonathan Paton


TIA & HAND

:-D
-- 
David T-G                      * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

Attachment: msg25208/pgp00000.pgp
Description: PGP signature

Reply via email to