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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repetition operators: do {} five times... 1

Status
Not open for further replies.

darkreaper00

Technical User
Aug 5, 2002
23
US
this:

Code:
($_=shift(@tony)) x5;

doesn't do what I want it to do: namely, go to the fifth value after the current one, and trash all the others. I know that this generally pertains to strings, but with perl being so intuitive-friendly, I'd like it to intuit me telling it to do something five times. You see what I'm trying to do, now tell me how to do it :c)

...And to answer before you ask, yes, i know I could write a for loop* to do that, but I want to know how to do it this way (as usual...), if I can.

* (or
Code:
$_=shift(@tony);
$_=shift(@tony);
$_=shift(@tony);
$_=shift(@tony);
$_=shift(@tony);
, even)


Thanks!
 
Great idea justice41 !
I just look at splice documentation and I think you could even just do:
Code:
$_ = splice(@tony, 0, 5);
From perldoc -f splice:
[tt]
In list context, returns the elements removed from the array. In scalar context, returns the last element removed, or undef if no elements are removed
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top