Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

(z) Re: Modifying Global Variable

by zigdon (Deacon)
on Jan 08, 2003 at 17:38 UTC ( [id://225305]=note: print w/replies, xml ) Need Help??


in reply to Modifying Global Variable

There's a few problems with your code:

  • Instead of "main::date" try "$date" - you shouldn't need to specify main:: unless you specified a different package.
  • You are returning a value (the literal string "main::date"), but thankfully, you're not using it.
  • You are splitting on an uninitialised variable ($_), which you would have known if you had warnings turned on. Use $_[0] instead.
  • You can change all the splits into one split:
    my ($year, $month, $day, $hour, $min, $sec) = split /[- :]/, $_[0];
  • You don't need to modify the global - just return the value you need:
    my $date = dateconverter($date_begin); print $date, "\n"; sub dateconverter { my @bits = split /[- :]/, $_[0]; return join ".", @bits[0,1,2]; }

-- Dan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://225305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found