Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: extract words from specific location

by smls (Friar)
on Jun 07, 2013 at 06:01 UTC ( [id://1037587]=note: print w/replies, xml ) Need Help??


in reply to Re^2: extract words from specific location
in thread extract words from specific location

"No +1 does no work either"

Sure it does:

use warnings; use strict; # 0 1 2 3 4 5 6 7 # ' ' ' ' ' ' ' ' my @words = qw(aaa bbb ccc ddd eee fff ggg hhh); my @tst_num_temp = qw(0 4 6); my $c2 = 0; my @tst_num; while ($c2<=$#tst_num_temp) { $tst_num[$c2]=$words[$tst_num_temp[$c2]+1]; $c2++; } print "@tst_num\n";

...prints:

bbb fff hhh


"but I got the answer we can do it like $words[++$tst_num_temp[$c2]"

You can, and it will get you the exact same result for @tst_num as the +1 method. But in addition to that it will also modify @tst_num_temp, which you should be aware of in case the following code continues to use that variable.

In any case, consider using a for loop like 2teez suggested, it's much nicer compared to a while loop with manually incremented index.

Log In?
Username:
Password:

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

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

    No recent polls found