Willman023 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Fellow Monks,
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
(z) Re: Modifying Global Variable
by zigdon (Deacon) on Jan 08, 2003 at 17:38 UTC | |
Re: Modifying Global Variable
by gryphon (Abbot) on Jan 08, 2003 at 18:02 UTC | |
Re: Modifying Global Variable
by boo_radley (Parson) on Jan 08, 2003 at 18:53 UTC | |
Re: Modifying Global Variable
by vek (Prior) on Jan 08, 2003 at 17:41 UTC |
Back to
Seekers of Perl Wisdom