The problem is I am clearly passing a scalar var to this sub and it is getting a null list. I have tested this thoroughly. Why might it do this? The sub code is in a .pm package, but everything is clearly defined. I have similar subs and calls that work fine!
Here is my call where $form_data{'judeo_date'} is a date like "25-AUG-2002-AD":
my $j_date = $form_data{'judeo_date'}; my $long_count = get_long_count $j_date if defined $form_data{'judeo_d +ate'};
and
sub get_long_count { my ($dd, $mon, $yyyy, $bc) = split /-/, $_, 4; $yyyy = (0 - $yyyy) if ($bc eq 'BC'); my $feb = 0; if ( int ( $yyyy / 4 ) == ( $yyyy / 4 ) ) { $feb += 29; } else { $feb += 28; } my $months = { 'JAN' => '31', 'FEB' => "$feb", 'MAR' => '31', 'APR' => '30', 'MAY' => '31', 'JUN' => '30', 'JUL' => '31', 'AUG' => '31', 'SEP' => '30', 'OCT' => '31', 'NOV' => '30', 'DEC' => '31', }; my @month_keys = (keys %months); my $tot_days = $dd; for ($i = 0; $month_keys[$i] ne $mon; $i++) { $tot_days += $months{$month_keys[$i]}; } for ($y = $yyyy; $y >= -3114; $y--) { if ( int ( $y / 4 ) == ( $y / 4 ) ) { $tot_days += 366; } else { $tot_days += 365; } } $tot_days -= 223; my $kin = 0; my $uinal = 0; my $tun = 0; my $katun = 0; my $baktun = 0; $baktun = int ( $tot_days / 144000 ) if ( $tot_days >= 144000 ); $tot_days -= ( $baktun * 144000 ); $katun = int ( $tot_days / 7200 ) if ( $tot_days >= 7200 ); $tot_days -= ( $katun * 7200 ); $tun = int ( $tot_days / 360 ) if ( $tot_days >= 360 ); $tot_days -= ( $tun * 360 ); $uinal = int ( $tot_days / 20 ) if ( $tot_days >= 20 ); $tot_days -= ( $uinal * 20 ); $kin = $tot_days; my $long_count; $long_count = "$baktun.$katun.$tun.$uinal.$kin"; }
Thanks,
Chris

P.S. in case your wondering, this sub translates Judeo dates into Mayan long count calendar dates.

Originally posted as a Categorized Question.


In reply to Why does my subroutine not receive the scalar parameter as $_? by @ncientgoose

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.