Thank you Sir, But is it not wrong to create an array in a function and send a reference to the array back into the main function?
Because the scope of the array is limited to the function and calling a reference that is not available(the variables local in scope to the function are collapsed) must be illegal!! Regards, Satya "Rob Dixon" <[EMAIL PROTECTED] To: [EMAIL PROTECTED] am.co.uk> cc: Subject: Re: Passing array to a function 12/19/2002 10:45 AM Satya I'm not sure why you're getting odd results - I ran the text of your post under Perl (with no changes) and got Satya - Dec19 20021219 "12/19/2002","Thursday", Satya1 - Dec19 : 20021219 : "12/19/2002","Thursday", which looks fine to me. The proper way to return arrays from a function is to pass them by reference. Change the last line of getTimeInfo() to return \@results; and dereference in the call, like this @results = @{getTimeInfo()}; HTH, Rob "Satya Devarakonda" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi, > > How can I pass an array to a function and get values back in it??? Here > are excerpts from my code. > ######################################################## > sub getTimeInfo > { > my $sec = 0; > my $min = 0; > my $hour = 0; > my $day = 0; > my $mon = 0; > my $year = 0; > my $IsDST = 0; > my $week_day = 0; > my @time_info = "\n"; > my $day_of_year = 0; > > ($sec,$min,$hour,$day,$mon,$year,$week_day,$day_of_year,$IsDST) = > localtime(time); > my @monName = > ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" ); > my @dayName = > ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); > > $mon += 1; > $year += 1900; > $results[0] = "$monName[${mon}-1]${day}"; > > if ( $day < 10 ) > { > $day = "0${day}"; > } > $results[1] = "$year$mon$day"; > > $results[2] = "\"$mon\/$day\/$year\",\"${dayName[$week_day]}\", \n"; > > print "Satya - @results"; > return "@results"; > } #End of getTimeInfo () > ######################################################### > use strict; > use Net::FTP; > use Time::Local; > > #Get Time Information to be used to call different functions > my @results; > > @results = split (/ /, getTimeInfo(), 3); > my $MonthDay = $results[0]; > my $ccyymmdd = $results[1]; > my $FormattedDate = $results[2]; > > print "Satya1 - $MonthDay : $ccyymmdd : $FormattedDate \n"; > ###################################################### > > > Satya1 - Dec18 : 20021218 : > "12/18/2002","Wednesday",27480969643208615188651398403761002 > And why am I getting junk(I believe it is pointer information) at the the > end like ==== > 27480969643208615188651398403761002 > > Thanks for your help. > Satya > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]