Length of String
Hi guys Do you know whether there is a function in perl to find the size of a string ? For example, "06" would be size 2. Cheers Tony
Perl dates
Hi guys, I was wondering if you could help me. I have a variable in my perl code called $deadline_date. I assign $deadline_date the value 20011212. The date format is MMDD. I have a file which contains 2 columns of values i.e. date and product as follows: 20011001 abc 20010701 bcd 20011101 efg 20010201 hij I need to select those rows which has a date less than 3 months before the $deadline_date i.e. rows 1 and 3 How can I use DATE functionalities in perl to do this comparison ? Any advice would be appreciated. Thanks in advance Tony
Concatenation
Hi guys I was wondering if you could help me. In my perl code, I am reading a file with the following line: 123000 There are 3 spaces before 123000. I unpack the values into 2 variables, A and B A is assigned the 3 spaces and B is assigned the value 123000. I have another variable C which is assigned the value 600. If I write the values A, B and C to a new file using the following code: print NEW_FILE $C$A$B I get the following result: 600123000 I was hoping to get to obtain the following result: 600 123000 Any ideas why the spaces in variable A is not taken into account ? I would be most grateful if you could let me know. Thanks in advance Tony
Decimal numbers
Hi guys I was wondering if you could help me. If I read a value of 123.456 and I would like to print this value out as 123456 (without decimals), how can I go about it without doing any multiplication ? I would be most grateful for any advice. Thanks in advance Tony
Writing formatted results to a file
Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, line 21. This is the section of my perl code reads results from an BCP output file and is as follows : sub create_summary_report { my (@record, $element, $rows_copied, $line_output); @record = qw(A B C); $rows_copied = "rows copied"; $element = 0; open SUMMARYTMP, "<$bcp_file_directory$log_file_summary_tmp" or die "Unable to open $log_file_summary_tmp for reading: $!\n"; open SUMMARY, ">$log_directory$log_file_summary_final" or die "Unable to open $log_file_summary_final for writing: $!\n"; print SUMMARY "Summary Details\n"; print SUMMARY "--\n"; print SUMMARY "Account (From) : $fromAccount\n"; print SUMMARY "Account (To) : $toAccount\n\n\n"; print SUMMARY "Record Types\n"; print SUMMARY "\n"; format ADDRESSLABEL = @<, @< $record[$element], $line_output .. while() { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { print SUMMARY write(ADDRESSLABEL); $element = $element + 1; } } close SUMMARYTMP or die "Error closing $log_file_summary_tmp"; close SUMMARY or die "Error closing $log_file_summary_final"; } I would be most grateful with any advice. Thanks in advance Tony
RE: Writing formatted results to a file
Hi Bob Thanks for the help. I renamed the format label from ADDRESSLABEL to SUMMARY and it appeared to work also. Thanks again for the help. Tony -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: 16 April 2002 19:36 To: [EMAIL PROTECTED] Subject: Re: Writing formatted results to a file On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: > Hi guys > I was wondering if you could help me. > Does anybody know how to write formatted results to a file ? > > I am getting the following error : > > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 5. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 15. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 21. > > This is the section of my perl code reads results from an BCP output file > and is as follows : > > sub create_summary_report > { > my (@record, $element, $rows_copied, $line_output); > @record = qw(A B C); > $rows_copied = "rows copied"; > $element = 0; > > open SUMMARYTMP, "<$bcp_file_directory$log_file_summary_tmp" > or die "Unable to open $log_file_summary_tmp for reading: $!\n" > ; > > open SUMMARY, ">$log_directory$log_file_summary_final" > or die "Unable to open $log_file_summary_final for writing: > $!\n"; > > print SUMMARY "Summary Details\n"; > print SUMMARY "--\n"; > print SUMMARY "Account (From) : $fromAccount\n"; > print SUMMARY "Account (To) : $toAccount\n\n\n"; > print SUMMARY "Record Types\n"; > print SUMMARY "\n"; > > format ADDRESSLABEL = > @<<<<<, @<<<<< > $record[$element], $line_output > .. > > while() { > chop; > $line_output = $_; > if ($line_output =~ /\b$rows_copied\b/) { > print SUMMARY write(ADDRESSLABEL); > $element = $element + 1; > } > } > in addition you need to quote the format label when assigning: $~ = 'ADDRESSLABEL'; > close SUMMARYTMP > or die "Error closing $log_file_summary_tmp"; > > close SUMMARY > or die "Error closing $log_file_summary_final"; > } > > I would be most grateful with any advice. > > Thanks in advance > Tony > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Writing formatted results to a file
Hi Bob, I am having trouble writing another new format into the same file as the one I mentioned in the previous email. I executed the following code and it prints out the SUMMARY format but NOT the SUMMARY1 format into the same file. Any ideas ? Thanks in advance Tony The code is as follows : sub create_summary_report { my (@record, @record_processed, $element, $rows_copied, $rows_processed, $line_output, $oldhandle); @record = qw(A B C D); @record_processed = qw(ACCOUNT); $rows_copied= "rows copied"; $rows_processed = "rows_processed"; $element = 0; open SUMMARYTMP, "<$bcp_file_directory$reports_file_summary_tmp" or die "Unable to open $reports_file_summary_tmp for reading: $!\n"; open SUMMARY, ">$reports_directory$reports_file_summary_final" or die "Unable to open $reports_file_summary_final for writing: $!\n"; print SUMMARY "Extraction Summary Details\n"; print SUMMARY "--\n"; print SUMMARY "Server: $server\n"; print SUMMARY "Database : $db\n"; print SUMMARY "User : $user\n"; print SUMMARY "Account (From): $fromAccount\n"; print SUMMARY "Account (To) : $toAccount\n"; print SUMMARY "Start Time: $start_time\n"; print SUMMARY "End Time : $end_time\n\n\n"; print SUMMARY "Record (Bulk Copied)\n"; print SUMMARY "--\n"; while() { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { write(SUMMARY); $element = $element + 1; } } $element = 0; print SUMMARY "\n\nRecord (Processed)\n"; print SUMMARY "\n"; while() { chop; $line_output = $_; print "$line_output\n"; if ($line_output =~ /\b$rows_processed\b/) { $oldhandle = select(SUMMARY); $~ = "SUMMARY1"; select($oldhandle); write(SUMMARY); $element = $element + 1; } } close SUMMARYTMP or die "Error closing $reports_file_summary_tmp"; close SUMMARY or die "Error closing $reports_file_summary_final"; format SUMMARY = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record[$element], $line_output .. format SUMMARY1 = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record_processed[$element], $line_output .. } -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: 16 April 2002 19:36 To: [EMAIL PROTECTED] Subject: Re: Writing formatted results to a file On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: > Hi guys > I was wondering if you could help me. > Does anybody know how to write formatted results to a file ? > > I am getting the following error : > > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 5. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 15. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 21. > > This is the section of my perl code reads results from an BCP output file > and is as follows : > > sub create_summary_report > { > my (@record, $element, $rows_copied, $line_output); > @record = qw(A B C); > $rows_copied = "rows copied"; > $element = 0; > > open SUMMARYTMP, "<$bcp_file_directory$log_file_summary_tmp" > or die "Unable to open $log_file_summary_tmp for reading: $!\n" > ; > > open SUMMARY, ">$log_directory$log_file_summary_final" > or die "Unable to open $log_file_summary_final for writing: > $!\n"; > > print SUMMARY "Summary Details\n"; > print SUMMARY "--\n"; > print SUMMARY "Account (From) : $fromAccount\n"; > print SUMMARY "Account (To) : $toAccount\n\n\n"; > print SUMMARY "Record Types\n"; > print SUMMARY "\n"; > > format ADDRESSLABEL = > @<<<<<, @<<<<< > $record[$element], $line_output > .. > > while() { > chop; > $line_output = $_; > if ($line_output =~ /\b$rows_copied\b/) { > print SUMMARY write(ADDRESSLABEL); > $element = $element + 1; > } > } > in addition you need to quote the format label when assigning: $~ = 'ADDRESSLABEL'; > close SUMMARYTMP > or die "Error closing $log_file_summary_tmp"; > > close SUMMARY > or die "Error closing $log_file_summary_final"; > } > > I would be most grateful with any advice. > > Thanks in advance > Tony > -- 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]
RE: Writing formatted results to a file - PLEASE IGNORE PREVIOUS EMAIL
Hi guys I managed to resolve the issue regarding the previous issue. First problem - $rows_processed = "rows_processed"; should be : $rows_processed = "rows processed"; After the first WHILE loop, I added a close and open (in this order) of SUMMARYTMP and it worked. Thanks again for the help. Tony -Original Message- From: Ho, Tony Sent: 18 April 2002 20:12 To: 'bob ackerman'; [EMAIL PROTECTED] Subject: RE: Writing formatted results to a file Hi Bob, I am having trouble writing another new format into the same file as the one I mentioned in the previous email. I executed the following code and it prints out the SUMMARY format but NOT the SUMMARY1 format into the same file. Any ideas ? Thanks in advance Tony The code is as follows : sub create_summary_report { my (@record, @record_processed, $element, $rows_copied, $rows_processed, $line_output, $oldhandle); @record = qw(A B C D); @record_processed = qw(ACCOUNT); $rows_copied= "rows copied"; $rows_processed = "rows_processed"; $element = 0; open SUMMARYTMP, "<$bcp_file_directory$reports_file_summary_tmp" or die "Unable to open $reports_file_summary_tmp for reading: $!\n"; open SUMMARY, ">$reports_directory$reports_file_summary_final" or die "Unable to open $reports_file_summary_final for writing: $!\n"; print SUMMARY "Extraction Summary Details\n"; print SUMMARY "--\n"; print SUMMARY "Server: $server\n"; print SUMMARY "Database : $db\n"; print SUMMARY "User : $user\n"; print SUMMARY "Account (From): $fromAccount\n"; print SUMMARY "Account (To) : $toAccount\n"; print SUMMARY "Start Time: $start_time\n"; print SUMMARY "End Time : $end_time\n\n\n"; print SUMMARY "Record (Bulk Copied)\n"; print SUMMARY "--\n"; while() { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { write(SUMMARY); $element = $element + 1; } } $element = 0; print SUMMARY "\n\nRecord (Processed)\n"; print SUMMARY "\n"; while() { chop; $line_output = $_; print "$line_output\n"; if ($line_output =~ /\b$rows_processed\b/) { $oldhandle = select(SUMMARY); $~ = "SUMMARY1"; select($oldhandle); write(SUMMARY); $element = $element + 1; } } close SUMMARYTMP or die "Error closing $reports_file_summary_tmp"; close SUMMARY or die "Error closing $reports_file_summary_final"; format SUMMARY = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record[$element], $line_output .. format SUMMARY1 = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $record_processed[$element], $line_output .. } -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: 16 April 2002 19:36 To: [EMAIL PROTECTED] Subject: Re: Writing formatted results to a file On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: > Hi guys > I was wondering if you could help me. > Does anybody know how to write formatted results to a file ? > > I am getting the following error : > > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 5. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 15. > write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, > line 21. > > This is the section of my perl code reads results from an BCP output file > and is as follows : > > sub create_summary_report > { > my (@record, $element, $rows_copied, $line_output); > @record = qw(A B C); > $rows_copied = "rows copied"; > $element = 0; > > open SUMMARYTMP, "<$bcp_file_directory$log_file_summary_tmp" > or die "Unable to open $log_file_summary_tmp for reading: $!\n" > ; > > open SUMMARY, ">$log_directory$log_file_summary_final" > or die "Unable to ope
Assigning values from files into an aray
Hi guys I was wondering if you could help me. I have the following row of data in one file: 405^100^200^A^B C D E I have the following fragment of code that reads the data row: while () { $number_of_elements= 0; chop; ($record, $customer, $location, $plan, @items) = split(/\^/, $_); $number_of_elements= $#items + 1; print "number_of_elements: $number_of_elements\n"; } At the moment, the program prints out the value of "number_of_elements" to be 1. However "number_of_elements" should print out 4 because there are 4 values (i.e. B, C, D, E) Any ideas where I am going wrong ? Any advice would be greatly appreciated. Thanks in advance Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Error message
Hi guys, Has anybody seen the following message before ? Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at ./test.pl line 150 I would be most grateful with any advice Thanks in advance Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for command success
Can you try this ? system ("tar cvf ../test.tar *.grib"); if ($? == 0) { print "\nSuccess!\n"; } else { print "\nUnsuccessful!\n"; } The return code is in the perl $? variable. See perldoc perlvar for details. -Original Message- From: siren jones [mailto:[EMAIL PROTECTED]] Sent: 07 May 2002 17:38 To: [EMAIL PROTECTED] Subject: Testing for command success I'd like to test the following command to see if it ran successfully? Have no idea how or which variable stores the success of a command ($!, $], $_ )? system "tar cvf ../test.tar *.grib"; Tried: if (system "tar cvf ../test.tar *.grib";) { print "\nSuccess!\n";} got: "Command not found" Thank you in advance. -s _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- 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]
Launching Perl Code in Parallel
Hi Guys I was wondering if you could help me. I have a perl program, get_ice_cream_descriptions.pl, that accepts 2 arguments For example, get_ice_cream_descriptions.pl 1 10 However, I would like to get ice cream descriptions for other ranges at the same time, such as 11 - 20, 21 - 30, 31 - 40, 41 - 50 etc I could write an external file that contains the following : get_ice_cream_descriptions.pl 1 10 & get_ice_cream_descriptions.pl 11 20 & get_ice_cream_descriptions.pl 21 30 & get_ice_cream_descriptions.pl 31 40 & get_ice_cream_descriptions.pl 41 50 & This way I could execute the perl code in parallel and eventually get the descriptions. Instead of using the above method, I would prefer to write some code in get_ice_cream_descriptions.pl accept different number ranges and launch itself. I have been looking at the fork() command. I believe fork() only creates a copy of the original process but I wasn't quite sure how I could pass the different number ranges into the perl code before it forks itself. Any advice would be appreciated. Many Thanks Tony
THIS IS A TEST - PLEASE DELETE THIS EMAIL - THANKS
Multi-dimensional arrays and subroutines
Hi Guys I was wondering if you could help me. I have a multi-dimensional array and I would like to pass it to a subroutine as follows : my @multi_array = ([1,2,3,4], [5,6,7,8]); my @result = process_array(@multi_array); print "The result is : @result\n"; sub process_array { my @array_processed; my @array_given = $_[0]; $select_data = "select A, B, C, D from Table X where A = ? and B = ? and C = ? and D = ?"; $sth = $dbh->prepare($select_data) or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n"; for (@array_given) { $sth->bind_param(1, @$_->[0]); $sth->bind_param(2, @$_->[1]); $sth->bind_param(3, @$_->[2]); $sth->bind_param(4, @$_->[3]); $sth->execute(); $sth->bind_columns(undef, \$A, \$B, \$C, \$D); while ($sth->fetch()) { $new_array = join("|", $A, $B, $C, $D); unshift(@array_processed, $new_array); } } $sth->finish(); return @array_processed; } I am expecting as output the following : The result is 1,2,3,4 The result is 5,6,7,8 The actual output I am getting is : The result is 1,2,3,4 What happened to 5,6,7,8 ? I would be most grateful for any advice. Thanks in advance Tony
RE: Multi-dimensional arrays and subroutines - PLEASE IGNORE PREVIOUS EMAIL
Hi Guys I have just resolved the problem. The problem was the array variable "array_given" in the subroutine. I replaced : my @array_given = $_[0]; with my @array_given = @_; It works fine. Thanks for the help. Tony > -Original Message- > From: Ho, Tony > Sent: Wednesday, July 17, 2002 11:43 AM > To: '[EMAIL PROTECTED]' > Subject: Multi-dimensional arrays and subroutines > > Hi Guys > I was wondering if you could help me. > > I have a multi-dimensional array and I would like to pass it to a > subroutine as follows : > > my @multi_array = ([1,2,3,4], [5,6,7,8]); > my @result = process_array(@multi_array); > print "The result is : @result\n"; > > sub process_array { > > my @array_processed; > my @array_given = $_[0]; > > $select_data = "select A, B, C, D > from Table X > where A = ? and B = ? and C = ? and D = ?"; > > $sth = $dbh->prepare($select_data) > or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n"; > > for (@array_given) { > $sth->bind_param(1, @$_->[0]); > $sth->bind_param(2, @$_->[1]); > $sth->bind_param(3, @$_->[2]); > $sth->bind_param(4, @$_->[3]); > $sth->execute(); > > $sth->bind_columns(undef, \$A, \$B, \$C, \$D); > > while ($sth->fetch()) { > $new_array = join("|", $A, $B, $C, $D); > unshift(@array_processed, $new_array); > } > } > > $sth->finish(); > > return @array_processed; > } > > I am expecting as output the following : > The result is 1,2,3,4 > The result is 5,6,7,8 > > The actual output I am getting is : > The result is 1,2,3,4 > > What happened to 5,6,7,8 ? > > I would be most grateful for any advice. > Thanks in advance > Tony >
Table Access OR File Manipulation
Hi guys I was wondering if you could help me. I am currently designing Perl DBI code to extract data from tables from Sybase Database under UNIX. There are a dozen of tables I need to extract information from. The biggest tables are ACCOUNTS and SUBSCRIBERS. ACCOUNT has 10 million rows and SUBSCRIBERS has 20 million rows. SUBSCRIBERS is related to the ACCOUNTS table as every account has subscribers. At the end of the extraction process, I need to end up with 1 or 2 flat files that shows rows of SUBSCRIBER data and rows of ACCOUNT data associated to those subscribers. Which is the better option in terms of performance and reliability: Access the sybase tables with SELECT+JOIN sql statements, order and write the results to the overall flat file file immediately ? OR BCP out the results into multiple files and manipulate/rearrange/order them into a single file under Unix. I would be most grateful if you could help me out. Cheers T
Unix commands in Perl scripts
Hi guys I was wondering if anyone knows how to execute Unix commands in a Perl Script ? I would be most grateful if you could let me know Thanks in advance Tony
appending to rows
Hi guys I was wondering if you could help me I have 2 files. One file has 3 data rows, A, B and C The file has 1 data row D. I need to append row D to rows A and C in the first file, based on some condition. Any ideas how I could go about this ? Another alternative would be for me to open up a new file and write row 1 : AD row 2 : B row 3 : CD Is the second approach better in terms of performance than the first approach as I will have more than 1 million rows to deal with ? Thanks in advance Tony
DBM and bcp files
Hi guys I was wondering if you could help me. I am bulk copying data from a Database using bcp into a data file. Can I transform my data file into a DBM file in perl ? If so, how do I go about it ? I would be most grateful if you could let me know. Cheers Tony
"Use of uninitialized value" error message
Hi guys I was wondering if you could help me with the following problem. I am getting the following error message: Use of uninitialized value in string ne at format_imsi_msisdn.pl line 257. line 257 and beyond consist of the following: if ($result_value1 ne " ") { $a= substr($result_value1, 0, 8); $b= substr($result_value1, 8, 2); $c= substr($result_value1, 10, 2); return ($a, $b, $c); } else { return (" ", " ", " "); } I declare the variable result_value1 at the begining of the method as follows my $result_value1 =" "; Any ideas why ? Thanks in advance Tony
RE: "Use of uninitialized value" error message
Hi Nikola/Jason Thanks for the help. The variable $result_value1 is declared within the subroutine and is never used outside the subroutine. I originally had the following piece of code (which I forgot to show you guys in the previous email): $result_value1 = $database1{$input_key1} But I changed the above code to the following and it worked ("Use of uninitialized value" error message" did not appear): $result_value1 = $database1{$input_key1} || " "; if ($result_value1 ne " ") { $a= substr($result_value1, 0, 8); $b= substr($result_value1, 8, 2); $c= substr($result_value1, 10, 2); return ($a, $b, $c); } else { return (" ", " ", " "); } Cheers Tony -Original Message- From: Nikola Janceski [mailto:[EMAIL PROTECTED]] Sent: 13 March 2002 17:16 To: 'Jason Larson'; 'Ho, Tony'; '[EMAIL PROTECTED]' Subject: RE: "Use of uninitialized value" error message that actually won't get rid of the warning. but you are right the declaration at the top of the script of the varible goes out of scope when it reaches the if. you are using -w or use warnings; in your script that is causing the warning. perhaps attaching the code would help but we can't tell where the varible goes out of scope. -Original Message- From: Jason Larson [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 11:06 AM To: 'Ho, Tony'; '[EMAIL PROTECTED]' Subject: RE: "Use of uninitialized value" error message > -Original Message- > From: Ho, Tony [mailto:[EMAIL PROTECTED]] > Subject: "Use of uninitialized value" error message > > Hi guys > I was wondering if you could help me with the following problem. > > I am getting the following error message: > > Use of uninitialized value in string ne at > format_imsi_msisdn.pl line 257. > > line 257 and beyond consist of the following: > > if ($result_value1 ne " ") { > $a= substr($result_value1, 0, 8); > $b= substr($result_value1, 8, 2); > $c= substr($result_value1, 10, 2); > return ($a, $b, $c); > } > else { > return (" ", " ", " "); > } > > I declare the variable result_value1 at the begining of the method as > follows > > my $result_value1 =" "; > > Any ideas why ? I'm still new to Perl myself, so I can't tell you exactly what's happening, but it looks like $result_value1 is undef when it gets to the if statement. I think a better way to accomplish what you're trying to do is simply: my $result_value1; if ($result_value) { #$result_value1 is defined $a= substr($result_value1, 0, 8); $b= substr($result_value1, 8, 2); $c= substr($result_value1, 10, 2); } else { #$result_value1 is still undef return (" ", " ", " "); } Hope this helps... Jason CONFIDENTIALITY NOTICE: The information contained in this ELECTRONIC MAIL transmission is confidential. It may also be privileged work product or proprietary information. This information is intended for the exclusive use of the addressee(s). If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution [other than to the addressee(s)], copying or taking of any action because of this information is strictly prohibited. The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc.
Assigning chunks into variables
Hi guys I was wondering if you could help me. I have the following string: 2010:abc:def:ghi If I go through this string and find the first colon (:), I want to assign everything before that colon into variable1 I would like to assign the rest of the string after the first colon into variable2. Therefore, variable1 = 2010 variable2 = abc:def:ghi I was wondering how I can approach this ? I would be most grateful Thanks in advance Tony
RE: Assigning chunks into variables - Please ignore previous email
Hi guys I managed to use the "split" and "join" functions to achieve what I wanted. Many thanks for those who started thinking about a possible approach. Tony -Original Message- From: Ho, Tony Sent: 21 March 2002 20:37 To: '[EMAIL PROTECTED]' Subject: Assigning chunks into variables Hi guys I was wondering if you could help me. I have the following string: 2010:abc:def:ghi If I go through this string and find the first colon (:), I want to assign everything before that colon into variable1 I would like to assign the rest of the string after the first colon into variable2. Therefore, variable1 = 2010 variable2 = abc:def:ghi I was wondering how I can approach this ? I would be most grateful Thanks in advance Tony