You are welcome, but i am not getting through to you. You need to sit down and learn some basics first. Please read this book: Learning Perl. Repeat. Please read this book: Learning Perl.

The reason for the warnings is because your hash probably has keys, but no values. Now, your problem is two fold:

  1. the way you are passing arguments to the sub
  2. the way you are receiving the arguments in the sub
You refuse to show me what your input is and what your desired output should be, so i really can't help you any further with THIS problem. I can show you some examples of how to call functions in Perl, though. Run this code first to see the output, then study the code itself.
use strict; my @array1 = (1,2,3,4); my @array2 = (5,6,7,8); my %hash = ( key => 'val', foo => 'bar', ); print '=' x 20, "\nwrong way:\n"; wrong1(@array1,@array2); sub wrong1 { my (@a1,@a2) = @_; print "array 1: @a1\n"; print "array 2: @a2\n"; # notice that @a2 is empty } print '=' x 20, "\nright way:\n"; right1(\@array1,\@array2); sub right1 { my @a1 = @{ shift @_ }; my @a2 = @{ shift @_ }; print "array 1: @a1\n"; print "array 2: @a2\n"; # multiple arrays must be passed in as references } print '=' x 20, "\nwrong way:\n"; wrong2(%hash); sub wrong2 { my %hash = %_; while (my($k,$v) = each %hash) { print "$k => $v\n"; } # %_ is not special, use @_ instead - always! } print '=' x 20, "\nright way:\n"; right2(%hash); sub right2 { my %hash = @_; while (my($k,$v) = each %hash) { print "$k => $v\n"; } # a hash is really just a special kind of array # and yes, multiple hashes must be passed as references too } # last - a hash slice my %slice; @slice{@array1} = @array2; print '=' x 20, "\nhash slice:\n"; while (my($k,$v) = each %slice) { print "$k => $v\n"; } # and don't creat hash slices inside an subroutine's # argument list - that is bad bad bad ;)
Good luck, and please read this book: Learning Perl.

jeffa

Cargo Cult Programming - Just say 'NO!'

In reply to (jeffa) 3Re: How to open sub FH when filename is passed to sub? by jeffa
in thread How to open sub FH when filename is passed to sub? 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.