CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Binary x repitition operator

 



kencl
User

Sep 2, 2001, 3:16 PM

Post #1 of 2 (386 views)
Binary x repitition operator Can't Post

Just wondering if I can:

Code
shift (@ResultPointer) x 3;  # remove top 3 array rows

or would

Code
splice(@ResultPointer, 0, 3);

be more efficient?

Would there be a problem with either method if the array contained only 3 elements? IE would the result be the same as if I'd simply gone:

Code
@ResultPointer = ();  # only do this if there is exactly 3 elements!!!

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


mhx
Enthusiast / Moderator

Sep 3, 2001, 11:11 AM

Post #2 of 2 (381 views)
Re: Binary x repitition operator [In reply to] Can't Post


In Reply To
Just wondering if I can:

Code
shift (@ResultPointer) x 3;  # remove top 3 array rows


No. This would shift the first element off the array @ResultPointer, repeat it 3 times in string context and return a string that isn't used. Perl would yield

Code
Useless use of repeat (x) in void context

if run with -w.

In Reply To
or would

Code
splice(@ResultPointer, 0, 3);

be more efficient?

I think it's the most efficient way. Using three shifts wouldn't be as efficient. splice is about 40 percent faster in this case.

In Reply To
Would there be a problem with either method if the array contained only 3 elements?

No, except for the fact that the first method wouldn't work for the above reason.
Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives