Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scalar value @results[$i] better written as $results[$i]

Status
Not open for further replies.

JackTheRussel

Programmer
Joined
Aug 22, 2006
Messages
110
Location
FI
Hi.

I have little problem:

If I try to do like this:
Code:
for (my $i=0; $i<@table; $i++){

@results[$i] = split /\./, $table[$i];
}

I get error:
Scalar value @results[$i] better written as $results[$i] at ./test.pl line 12.

And If I try to do like complier proposes

Code:
$results[$i] = split /\./, $table[$i];

Then I get error:

Use of implicit split to @_ is deprecated at ./test.pl line 12.

So what I must do that I don't get any errors ?

Thanks !
 
Firstly, those are warnings rather than errors. That means that they won't stop your script functioning, but they're telling you that things may not be happening quite as you're expecting them to.

What are you trying to do, exactly?

The first version will split up your $table[$i] variable (using a dot as the delimiter) and put the first element from the split into @results[$i].

The second will split $table[$i] in the same way, put the number of elements that result into $results[$i] and put the elements themselves into the special @_ array. This behaviour is no longer encouraged because of the other uses for @_.

Is one of these what you're aiming for or is it something else?
 
Hi Ishnid.

Ishnid wrote:
The first version will split up your $table[$i] variable (using a dot as the delimiter) and put the first element from the split into @results[$i].

This is what I want, and my program works fine.
I just want to get part of this warnings.

Is it possible ?
 
Code:
$results[$i] = ( split /\./, $table[$i] )[0];
 
Thanks Ishnid.. again!

Could you tell me what this line do ?

I don't fully understand it ?
 
The "split" function produces a list. The [0] indicates that you want to take a "slice" from that list (a sub-list, effectively). This slice consists of just the first element of the list. So the right hand side returns just the first element of the list, which is then stored in $results[$i].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top