Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: extract words from specific location

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


in reply to extract words from specific location

+$1 should be +1. Other than that, the code should work.

If it still doesn't, the error is probably in the preceding part that you have not shown (where you initialize the variables).

Replies are listed 'Best First'.
Re^2: extract words from specific location
by torres09 (Acolyte) on Jun 07, 2013 at 05:13 UTC

    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

      "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://1037573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-24 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found