Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: extract words from specific location

by torres09 (Acolyte)
on Jun 07, 2013 at 05:13 UTC ( #1037576=note: print w/ replies, xml ) Need Help??


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

No +1 does no work either , but I got the answer we can do it like  $words[++$tst_num_temp[$c2] instead of $words[$tst_num_temp[$c2]+$1] . It works . thanks anyways


Comment on Re^2: extract words from specific location
Select or Download Code
Re^3: extract words from specific location
by smls (Friar) on Jun 07, 2013 at 06:01 UTC

    "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
Node Status?
node history
Node Type: note [id://1037576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-21 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (105 votes), past polls