Re: writing get_script()
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Mon, 11 May 2009 11:17:49 -0700
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
.
- References:
- writing get_script()
- From: Franken Sense
- Re: writing get_script()
- From: Franken Sense
- Re: writing get_script()
- From: Ben Morrow
- Re: writing get_script()
- From: Franken Sense
- Re: writing get_script()
- From: Uri Guttman
- Re: writing get_script()
- From: Franken Sense
- Re: writing get_script()
- From: Uri Guttman
- Re: writing get_script()
- From: Franken Sense
- Re: writing get_script()
- From: Jürgen Exner
- Re: writing get_script()
- From: Franken Sense
- writing get_script()
- Prev by Date: Re: FAQ 6.15 How can I print out a word-frequency or line-frequency summary?
- Next by Date: FAQ 7.12 How can I tell if a variable is tainted?
- Previous by thread: Re: writing get_script()
- Next by thread: Re: writing get_script()
- Index(es):
Relevant Pages
|