You do not see the single scalar because all arguments passed into a subrutine are flatened into a list. So when you call your sub cog_class(@somearray, $somescalar); the $somescalar variable and @somearray all became @_ in the subrutine.
If you only need one array and one scalar just switch them places cog_class($somescalar,@somearray); and if you need more complex data structures unchanged I suggest passing it by reference.
And another thing, you can't use those scalars by name in the sub unless you take them out of @_, you can do it like this:
#!/usr/bin/perl
use warnings;
use strict;
my $scalar = 'a';
my @array = qw(1 2 3);
some_sub($scalar,@array);
sub some_sub {
my $scalar = shift; # take the first element out of @_
# and the first element in this case is $scalar with 'a'
# inside
my @array = @_; # pass all the remaining arguments into
# @array so it now contains 1,2,3
}
I suggest that you read more about subrutines in the:
perldoc perlsub
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.