Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: I should've known better!

by vitoco (Friar)
on Sep 10, 2009 at 22:32 UTC ( #794659=note: print w/replies, xml ) Need Help??


in reply to I should've known better!

When I got your post, I was reading (again) perlsub to check that it's the same to pass an array by reference than by value to save memory, because of aliasing magic built in @_.

Fortunately, shifting or directly assigning values into my variables, breaks that internal linking, so modifying them won't alter the source of the parameters as in foreach, but it exists the possibility power to do that by touching @_ directly.

Unfortunately, assigning @_ to a local variable just to write clear code, all the parameters array will be duplicated.

A test on this topic...

#!perl -w use strict; use warnings; use Data::Dumper; my @a = (1, 2, 3); my @b = (4, 5, 6); my @s = foo(@a, @b); print Dumper(\@a, \@b, \@s); sub foo { my ($t, $u) = (@_); # $t = 1 ; $u = 2 $u = undef; # $a[1] == 2 my $i = shift; # $i = 1 my $j = shift; # $j = 2 $_[0] = undef; # $a[2] = undef my $k = shift; # $k = undef $_[0] = undef; # $b[0] = undef my $x = $_[0]; # $x = undef $k = $i + $j; # $k = 1 + 2 ; $a[2] == undef $x = $i - $j; # $x = 1 - 2 ; $b[0] == undef my $y = shift; # $y = undef my @z = @_; # @z = [5, 6] $z[0] = undef; # @z = [undef, 6] ; $b[1] == 5 return $t,$u,$i,$j,$k,$x,$y,@z; } __END__ $VAR1 = [ 1, 2, undef ]; $VAR2 = [ undef, 5, 6 ]; $VAR3 = [ 1, undef, 1, 2, 3, -1, undef, undef, 6 ];

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794659]
help
Chatterbox?
[stevieb]: james28909: what's the problem/question?
[james28909]: it is not an absolute date like "27" or "31". sometimes it is like wednesday or friday
[james28909]: and i need to format those special instances into an absolute date instead of "yesterday"
[stevieb]: ask a question on SoPW, and include at least a half-dozen examples of the input, and at least one example of expected output
[davido]: Exactly: SoPW. This isn't going to be solved easily in the CB.
[james28909]: in need "yesterday" and so on, to be absolute like "1" or "31"
[stevieb]: ...and throw some of your existing code into the equation as well, just so readers know you've given a try at it ;)
[james28909]: ok
[stevieb]: davido thanks for the link ;) I was being the typical lazy
[davido]: date parsing is hard. The more examples you can provide of the input (within reason) and expected output, the better.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-04-29 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.