I'm having quite a problem, using a function to alter a global variable. I'm hoping you guys can show me how to use a function to modify multiple variables. I'm trying to convert (YYYY-MM-DD HH:MM:SS) to unix time(seconds starting from 1970). I'm thinking about using Time::Local for the conversion. The error I'm getting before even trying to convert is:
Can't modify constant item in scalar assignment at calendar.pl line 276, near ""$year.$month.$day";"
Execution of calendar.pl aborted due to compilation errors.
Code:
I originally tryed just setting the date by using $date = "$year..."; but read one of Ovid's nodes on scope and tried main::date with no luck. Thanks alot in advance for any advice!my $date; dateconverter($date_begin); print $date, "\n"; sub dateconverter { my $year, my $month, my $day, my $hour, my $min, my $sec; ($year, $month, $day) = split /-/, $_; ($day, $hour) = split / /, $day; ($hour, $min, $sec) = split /:/, $hour; main::date = "$year.$month.$day"; # get unix seconds for $date return main::date; }
bW
Perl - the breakfast of Champions!
In reply to Modifying Global Variable by Willman023
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |