Why is Perl squashing my array?

Here's a short test program:

sub foo($;@) {
  my $sql = shift;
  my @params = @_;

  print "sql: $sql\n";
  print "params: " . join(",", @params);
}

sub bar($;@) {
  foo(@_);
}

bar("select * from blah where x = ? and y = ?",2,3);
print "\n";

Why is the output this:

sql: 3
params: 

Rather than this?

sql: select * from blah where x = ? and y = ?
params: 2,3

Answers


It's because when you call foo(@_), the prototype for foo() forces the first parameter (which is an array) to be converted into a scalar (which is the number of elements in @_).

See answers to my previous question asking "Why are Perl Function Prototypes Bad"?

FWIW, you can keep the prototypes in place if you change bar thus:

sub bar($;@) {
    foo(shift, @_);
}

Need Your Help

cant get fancybox to work when using link in image

jquery css fancybox

So, I am trying to have this image show up in the fancy box view and then when u click on the image it will download a file. But! When i have the images have anchors around the img tag the fancy box

LibGDX sprite batch font bad scale rendering

java fonts libgdx scale spritebatch

I am facing an issue while trying to put a text/dialog system in my game project. When I create a font and call the draw method on it passing the camera updated spriteBatch, each pixel of the font ...