CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
slices

 



TedW
Deleted

Nov 23, 2000, 8:33 PM

Post #1 of 3 (329 views)
slices Can't Post

This was supposed to change "The cat is on the roof" to "The dog is in the house"

@array = ('The ','cat ','is ','on ','the ','roof.');
@array1 = ('dog ','in ','house');
@array[2,4,6]=@array1;
print("@array");

Instead I got "The cat dog on in roof house"
Any input?


perlplexer
Deleted

Nov 24, 2000, 5:34 AM

Post #2 of 3 (329 views)
Re: slices [In reply to] Can't Post

Let's see here:

'The' 'cat' 'is' 'on' 'the' 'roof'
0 1 2 3 4 5

@array[2,4,6] is then: ('is','the',undef)

you tell Perl to replace those words with
@array1 = ('dog','in','house');

Replace them and see what you get. You get exactly what you asked for: 'The cat dog on in roof house'.

Computers do whatever you tell them to do not what you want them to do. :)

So, if you want to get 'The dog is in the house' then you need to say:

@array[1,3,5] = @array1;

__perlplexer


TedW
Deleted

Nov 24, 2000, 4:37 PM

Post #3 of 3 (329 views)
Re: slices [In reply to] Can't Post

Gee Golly...

That 0 realy demands attention, doesn't it!? Thanks _perlplexer.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives