Howdy Monks,
I am having difficultly with user defined functions in that they return data but not when using strict pragma. How do you use strict correctly when defining your own functions and returning data. I have provided the code and it works if I comment out the use strict pragma. I read the definitions about strict pragma but I am just not getting it in terms of user defined function returning results.
Here is my code and many thanks for the help
#!/usr/local/bin/perl -w use Net::MySQL; use strict; sub get_all_records{ my $mysql = Net::MySQL->new( hostname => 'tspform02.sbms.sbc.com', # Default use UNIX soc +ket database => 'RTSERVER', user => 'nco', password => 'xxxxxxxx' ); $mysql->query(q{SELECT * FROM RTSERVER.SITESCOPE}); my $a_record_iterator = $mysql->create_record_iterator(); my @db; while (my $record = $a_record_iterator->each) { push(@db, "$record->[0]:$record->[1]:$record->[2]:$record->[3] +:$record->[4]:$record->[5]:$record->[6]:$record->[7]"); } $mysql->close; return @db; } get_all_records(); my $count = 1; foreach my $item (my @db){ # THIS IS PROBLEM,DIFFERENT array print "Record #$count: $item\n"; $count++; }

In reply to passing variables from user defined function when use strict by onegative

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.