Basic Question

I need assistance in passing an array to a subroutine that is located in a package. Below, you will find code examples.

Package

package SomePackage; BEGIN { print "Beginning package ".__PACKAGE__." Error code: $?.\n"; } sub new() { my $self = {}; return bless $self; } sub DESTROY() { my $self = shift; warn "DESTROYING $self"; } sub print_filename() { my $object = {}; $object{FILES} = $_[1]; $object{PARAMETER_TWO} = $_[2]; $object{PARAMETER_THREE} = $_[3]; while(($key,$value) = each(%object)) { print "$key => $value\n"; } } END { print "Ending package ".__PACKAGE__ ." Error code: $?.\n"; } return 1;
Package Call

require "SomePackage.pl'; $SP = new SomePackage; @array = qw(one.txt two.txt three.txt); $SP->print_filename(@array,$arg1,$arg2);
In-depth Question

How can I format the array so that I can be passed to the package's subroutine so that key PARAMETER_TWO does not equal two.txt and PARAMETER_THREE does not equal three.txt? How can I convert the array into a scalar before passing it to the package? Note: I just wrote this code on-the-fly.

Any help would be greatly appreciated! Thanks in advance.

LA


In reply to Passing Array to Package Subroutine With Hash Paramter List by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.