Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Assigning the Length of an Array to a Variable (INDEX)

by AnomalousMonk (Archbishop)
on Aug 26, 2013 at 07:20 UTC ( [id://1050908]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Assigning the Length of an Array to a Variable (INDEX)
in thread Assigning the Length of an Array to a Variable

Some ways (by no means every possible way) to do what I understand you to want done:

>perl -wMstrict -le "my @t = ('A' .. 'M'); ;; my @ra = @t; print qq{@ra}; ;; my $start = 5; for my $i (0 .. $#ra) { if ($i < $start) { $ra[$i] = 'N'; } } print qq{@ra \n}; ;; @ra = @t; print qq{@ra}; ;; my $end = ($start <= $#ra) ? $start - 1 : $#ra; for my $i (0 .. $end) { $ra[$i] = 'N'; } print qq{@ra \n}; ;; @ra = @t; print qq{@ra}; $_ = 'N' for @ra[ 0 .. $end ]; print qq{@ra \n}; ;; @ra = @t; print qq{@ra}; @ra[ 0 .. $end ] = ('N') x ($end + 1); print qq{@ra \n}; " A B C D E F G H I J K L M N N N N N F G H I J K L M A B C D E F G H I J K L M N N N N N F G H I J K L M A B C D E F G H I J K L M N N N N N F G H I J K L M A B C D E F G H I J K L M N N N N N F G H I J K L M

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1050908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-18 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found