Re: writing get_script()



Franken Sense wrote:
In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:

What I want it to do is join the first through the ultimate words in s.
If you don't know what $#s means, then maybe you could ask? If you don't
know what (1..$#s) means, then maybe you could ask? Using code fragments
that you picked up somewhere without knowing their meaning an throwing
them together rarely produces useful code.

$@s is the highest index in the array @s, i.e. a number.
(1..$#s) is the list of numbers from 1 to the highest index of @s.
Nowhere does it relate to the content of @s.

What you want is maybe @s[1..$#s]
which is a slice of the array @s, containing the elements from index 1
to the highest index. However I would probably use shift() instead to
remove the first element from an array.


C:\MinGW\source>perl m9.pl
44:005:017 Then the high priest rose up, and all they that were with him,
(which
is the sect of the Sadducees,) and were filled with indignation,
44:005:018 And laid their hands on the apostles, and put them in the common
pris
on.
44:005:019 But the angel of the Lord by night opened the prison doors, and
broug
ht them forth, and said,
44:005:020 Go, stand and speak in the temple to the people all the words of
this
life.

C:\MinGW\source>type m9.pl
#!/usr/bin/perl
# perl m9.pl
use warnings;
use strict;

local $/="";
while ( <DATA> ) {
my @s = split /\s+/, $_;
my $verse = $s[0];
my $script = join(' ', @s[1..$#s]);
print "$verse $script\n";
}

local $/ = '';
while ( <DATA> ) {
my ( $verse, @s ) = split;
my $script = join ' ', @s;
print "$verse $script\n";
}




John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
.



Relevant Pages

  • Re: Get the results in reverse order
    ... I need to get the first element, that is the newest, and then the rest ... How do i get the rest of the rows in reverse order? ... Store everything in an array. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.php)
  • Re: is there a compiler warning for this piece of code ?
    ... Thanks for your thoughts - I think your speculation as to the history of the ... An element of a char array cannot be NULL; ... > _address_ of the first element. ... >> Incorrect. ...
    (microsoft.public.vc.language)
  • Re: Fast lookup of ranges
    ... I have a peculiar (atleast to me) problem before my hand. ... big table with numeric ranges in each row. ... and the first element is always less than ... Chose an array length N, the larger the faster we can search. ...
    (comp.programming)
  • Re: Invisible Array Loop Counter?
    ... What we see here is that in the first method, the first element you tried ... and the third element became a reference ... from the array. ...
    (comp.lang.perl.misc)
  • Re: Please, I am going insane: First element access causing ArrayIndexOutOfBoundsException:0
    ... I have an array created that has ... I feed the results of the query into the array... ... same error when i try to access the first element. ... its own prepared statement and resultset and it fixed the problem. ...
    (comp.lang.java.programmer)