How to check the FILE HANDLE STATUS ???
hi, I want to check the status of File handle before reading/writing to file ? How to do this ? like following open(FH_IN_FILE, file.txt); # This statement is executed by some other function close(FH_IN_FILE); print FH_IN_FILE SOME DATA; here before writing to file, i want to check the status of FH_IN_FILE..(whether file is opened or closed ) Thanks __ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
help on regular expression
Hi, I need some help on regular expression... i have following in variable $total_count $total_count = ##I USBP 01 10:38:09(000) xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100 Here in this ETRACK_TOTAL_RECS is fixed and common for all and rest is changing... like following $total_count = ##I USBP 02 12:38:09(000) abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500 here i need some regular expression to get, 100 like following $total_count = 100 I appreciate u r help.. Thanks -Madhu __ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
how to create/use data structures in perl ?
Hi, How to create data structures in perl ? I have following data structure in C...and i have to create similar data structure in perl and use... how to create data strutures in perl and how to use ? typedef struct { charPrefix[8]; charPrint; charName[80]; charModTime[32]; int Len; } fileinfo_; Thanks -Madhu __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
ASCII Manipulation in perl
I didn't get this mail... I am re seinding Hi, I want to write following C Equivalant with PERL My perl equvalant is at the end of this mail.. please correct me... my questios are inside perl comments... -- C Code start - for(i=0;i(int)strlen(Buffer);i++) { if((Buffer[i] 32) || (Buffer[i] 126)) { if((Buffer[i] == 10) || (Buffer[i] == 13)) { Buffer[i] = '\0'; } else { BadRec = 1; if(Buffer[0] != 26) { BadCnt++; fprintf(Reject,%s\n,Buffer); } else Ignore++; } break; } } PERL CODE START --- for(split(//)){ if ((ord() 32) || (ord() 126)) { if (ord() == 10) || (ord() == 13)) { #make this char as NULL # here how to make this char is NULL ? # $_ =~ tr/\r\n/\0\0/; is this Correct ? } else { $badrec = 1; # if ord() of first char is not 26 # reject reocrd } } } Thanks in Advance -Madhu __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Fwd: ASCII Manipulation in perl
--- Madhu Reddy [EMAIL PROTECTED] wrote: Date: Mon, 7 Jul 2003 10:39:51 -0700 (PDT) From: Madhu Reddy [EMAIL PROTECTED] Subject: ASCII Manipulation in perl To: [EMAIL PROTECTED] Hi, I want to write following C Equivalant with PERL My perl equvalant is at the end of this mail.. please correct me... my questios are inside perl comments... -- C Code start - for(i=0;i(int)strlen(Buffer);i++) { if((Buffer[i] 32) || (Buffer[i] 126)) { if((Buffer[i] == 10) || (Buffer[i] == 13)) { Buffer[i] = '\0'; } else { BadRec = 1; if(Buffer[0] != 26) { BadCnt++; fprintf(Reject,%s\n,Buffer); } else Ignore++; } break; } } PERL CODE START --- for(split(//)){ if ((ord() 32) || (ord() 126)) { if (ord() == 10) || (ord() == 13)) { #make this char as NULL # here how to make this char is NULL ? # $_ =~ tr/\r\n/\0\0/; is this Correct ? } else { $badrec = 1; # if ord() of first char is not 26 # reject reocrd } } } Thanks in Advance -Madhu __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
ASCII Manipulation in perl
Hi, I want to write following C Equivalant with PERL My perl equvalant is at the end of this mail.. please correct me... my questios are inside perl comments... -- C Code start - for(i=0;i(int)strlen(Buffer);i++) { if((Buffer[i] 32) || (Buffer[i] 126)) { if((Buffer[i] == 10) || (Buffer[i] == 13)) { Buffer[i] = '\0'; } else { BadRec = 1; if(Buffer[0] != 26) { BadCnt++; fprintf(Reject,%s\n,Buffer); } else Ignore++; } break; } } PERL CODE START --- for(split(//)){ if ((ord() 32) || (ord() 126)) { if (ord() == 10) || (ord() == 13)) { #make this char as NULL # here how to make this char is NULL ? # $_ =~ tr/\r\n/\0\0/; is this Correct ? } else { $badrec = 1; # if ord() of first char is not 26 # reject reocrd } } } Thanks in Advance -Madhu __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to add and remove spaces in a record
Hi, I have file to load into database... the file contains fixed length records.. basically i need to check for record lengths before loading into database.. suppose my fixed record length is 25 i have to read each record then of recors length is more than 25, delete the chars after 25...basically truncate record length to 25 and if record length is less than 25 add some spaces to make record length 25. how to do this in perl ? I appreciate u r help... thanks -madhu __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER
Hi, When i run perl programs, some times it will hang in the middle of program...and when i press ENTER then it is going to next step.. But it will not happen all the times... once some times it is hapenning i don't know what could be the reasons... my plat form is Windows 2000 and i am using perl 5.8 following is my sample program... and i use lot of system commands in my script is system command giving problemm Each time my program will hang after executing system command Can any one help on this.. I appreciate u r help... thanks in Advance -Madhu __ #!C:\perl\bin\perl -W 1. get the file name from C:\temp 2. read the file close 3. run some system command (system bteaq a.bteq out.txt) 4. print some message 3. run some system command (system mload a.mload out1.txt) print some message and again some system command __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER
Hi, I am already re-directing erros messages to file... and i am sure that there were no erros. even if there are some erros..it should come out from system command and should go to next step right ? following is my system command system `bteq $bteq_script 2$bteq_err $bteq_out`; thanks -madhu --- Tim Johnson [EMAIL PROTECTED] wrote: The problem is probably in your system() command. I would recommend redirecting STDERR to a file to see what messages you are getting. Try putting: open(STDERR,error.log) || die $!\n; at the beginning of the section with the system commands. If you are not on a Win32 system, then I think it gets a little more complicated because you might have to trap the STDERR and make a separate file handle to save the old STDERR in so that you can put it back later, but this shouldn't be necessary in Windows. -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED] Sent: Monday, June 30, 2003 8:54 AM To: [EMAIL PROTECTED] Subject: PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER Hi, When i run perl programs, some times it will hang in the middle of program...and when i press ENTER then it is going to next step.. But it will not happen all the times... once some times it is hapenning i don't know what could be the reasons... my plat form is Windows 2000 and i am using perl 5.8 following is my sample program... and i use lot of system commands in my script is system command giving problemm Each time my program will hang after executing system command Can any one help on this.. I appreciate u r help... thanks in Advance -Madhu __ #!C:\perl\bin\perl -W 1. get the file name from C:\temp 2. read the file close 3. run some system command (system bteaq a.bteq out.txt) 4. print some message 3. run some system command (system mload a.mload out1.txt) print some message and again some system command __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER
that may be one of the reason... but i am not using backticks for all the commands... today my program hung at following location system DTSRun \/S \test_box\\TSQL02\ \/N \Weekly mfdf Cubes\ \/V \{FE3888AE-3ABB-4A4C-84CF-EB12BF466177}\ \/L \$dts_err_file\ \/W \-1\ \/E; Here i am not using any backticks ? i am suspecting do we need to handle any signals in my program ? thanks -madhu -madhu --- Tim Johnson [EMAIL PROTECTED] wrote: Oh, there's your problem. Put the system command in quotes, not backticks. Backticks are a special quote-like operator that runs the command in as if it was run on the command-line and then passes the results back. So you would use backticks like this: my $result = `command`; -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED] Sent: Monday, June 30, 2003 9:24 AM To: Tim Johnson; [EMAIL PROTECTED] Subject: RE: PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER Hi, I am already re-directing erros messages to file... and i am sure that there were no erros. even if there are some erros..it should come out from system command and should go to next step right ? following is my system command system `bteq $bteq_script 2$bteq_err $bteq_out`; thanks -madhu --- Tim Johnson [EMAIL PROTECTED] wrote: The problem is probably in your system() command. I would recommend redirecting STDERR to a file to see what messages you are getting. Try putting: open(STDERR,error.log) || die $!\n; at the beginning of the section with the system commands. If you are not on a Win32 system, then I think it gets a little more complicated because you might have to trap the STDERR and make a separate file handle to save the old STDERR in so that you can put it back later, but this shouldn't be necessary in Windows. -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED] Sent: Monday, June 30, 2003 8:54 AM To: [EMAIL PROTECTED] Subject: PERL HANG on WINDOWS AND WAITING FOR TO PRESS ENTER Hi, When i run perl programs, some times it will hang in the middle of program...and when i press ENTER then it is going to next step.. But it will not happen all the times... once some times it is hapenning i don't know what could be the reasons... my plat form is Windows 2000 and i am using perl 5.8 following is my sample program... and i use lot of system commands in my script is system command giving problemm Each time my program will hang after executing system command Can any one help on this.. I appreciate u r help... thanks in Advance -Madhu __ #!C:\perl\bin\perl -W 1. get the file name from C:\temp 2. read the file close 3. run some system command (system bteaq a.bteq out.txt) 4. print some message 3. run some system command (system mload a.mload out1.txt) print some message and again some system command __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: reading file into hash?
This will do ... alpha_hash is u r hash... - my %alpha_hash = (); open(FH_D,$d_list) || die File opening $d_list\n; @file_list = FH_D; foreach $record (@file_list) { @t_array = split(/\|/, $record); $alpha_hash{$t_array[0]} = $t_array[1]; } close(FH_D); --- Tim McGeary [EMAIL PROTECTED] wrote: I'm still very green to perl, so please forgive this possibly stupid question. I want to setup a configuration file to have a list of alpha codes delimiter and a unique number that will match the code e.g. PACT | 23 PART | 24 etc How is the best way to read such a file into my program (hash ?) so that I can: a.) use the alpha codes to sort out data from another file b.) organize that data to later include that unique number. The end result will be 2 files: 1.) list # (chronological # from the list) | unique code # 2.) list # | data Tim -- Tim McGeary [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: reading file into hash?
This will do ... alpha_hash is u r hash... - my %alpha_hash = (); open(FH_D,$d_list) || die File opening $d_list\n; @file_list = FH_D; foreach $record (@file_list) { @t_array = split(/\|/, $record); $alpha_hash{$t_array[0]} = $t_array[1]; } close(FH_D); --- Tim McGeary [EMAIL PROTECTED] wrote: I'm still very green to perl, so please forgive this possibly stupid question. I want to setup a configuration file to have a list of alpha codes delimiter and a unique number that will match the code e.g. PACT | 23 PART | 24 etc How is the best way to read such a file into my program (hash ?) so that I can: a.) use the alpha codes to sort out data from another file b.) organize that data to later include that unique number. The end result will be 2 files: 1.) list # (chronological # from the list) | unique code # 2.) list # | data Tim -- Tim McGeary [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
find and replace string
Hi, I want to find and replace string with particular pattern my $str = 13 A.MFDF_FEEDER_ET; $str =~ s/\s+//g; here i want to replace string that end with _ET with null basically i wanto get result 13 in $str. how to do this? I really appreciate u r help Thanks -Madhu __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Is there any Polling mechanism in perl ?
Hi, Is there any polling mechanism in perl ? Following is my problem.. my program has to wait (poll) on particular folder... If any file arrived on that folder, my main program has to invoke another program... In Unix, we have poll() system call for waiting on particular event ? is there any similar thing in perl to wait on particular event ? if event occurs trigger some job.. following is my algorithm... i want to implement in better way... here file arrived means, completely transfered... Files will be FTPed to C:\temp on my local system... once that FTP is completed, i want to know... But i don't want to know in the middle of FTP. I want to know after FTP done... I think here we need unix lsof command? Does anybody have any idea ? about that? while(1) { if (file arrived on C:\temp\) { mail me the file name. } } __ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
LSOF in perl [list open files]
Does anybody know, is there any lsof, unix equivalant utility in perl (on windows) Thanks in advance -Madhu __ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Command line argurments to perl program
Hi, I want to pass command line arguements to perl program ? How to do this ? Thanks -Madhu __ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to check ASCII chars in perl ?
i don't thing the above will work. try: for(split(//)){ if(ord 32 || ord 126){ print Char is non printable char\n; }else{ print $_\n; } } I want to do following, if any char is ASCII value of 10 or 13, i want to make that char as null like following $_ = hello\n\t\r world; for(split(//)){ if(ord() 32 || ord() 126){ if (ord() eq 10 ) { = make this char as null } if (ord() eq 13 ) { = make this char as null } print Char is non printable char\n; }else{ print $_\n; } } __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to check ASCII chars in perl ?
Hi, I want to check for some ASCII chars in perl like following C code.. How to do this in Perl ? follwing will work in perl ? for($i=0;$i length;$i++) { if (($_[$i] 32) || (($_[$i] 126)) { print Char is non printable char\n; } } following is C code for(i=0;i(int)strlen(Buffer);i++) { if((Buffer[i] 32) || (Buffer[i] 126)) { if((Buffer[i] == 10) || (Buffer[i] == 13)) { Buffer[i] = '\0'; } else { BadRec = 1; if(Buffer[0] != 26) { BadCnt++; fprintf(Reject,%s\n,Buffer); } else Ignore++; } __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to pass perl variables between files
Hi, I want to find out how to pass perl variables between files and functions... in C, we declare with extern to work in different files how to do in perl... between files means , i declare variable in file1 and file2 will update those variables and want to access in file1 Ex: like $var1 and $var2 in following example between functions means, from main file i need to pass variables to function.. that function will update those arguements like $var3 and var4 in following example like in C, we pass the address of variable to functions following is the scenerio... File1 : Script1.pl - #!C:\perl\bin\perl -w require script2.pl; $var1 = 0; $var2 = 0; # this is a function from another file, this function #needs to update $var1 and $var2 my $ret = VAL::Validate(); print var1 is $var1\n; print var2 is $var2\n; VAL::func1($var3, $var4); print var3 is $var3\n; print var4 is $var4\n; -- File : Script2.pl -- #!C:\perl\bin\perl -w package VAL; # here some code will be there sub Validate () { #update var1 and var2 variables $var1 = 50; $var2 = 40; return 0; } sub func1 { $var3 = shift; $var4 = shift; $var3 = 90; $var4 = 70; } 1; -- Thanx -Madhu __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: locks in threads
thanx for u r response... i did used use threads::shared; my %bounds : shared = (); but i didn't use following { lock(%bounds); #-- do something with %bounds } and i got following error while running script... perl.exe application errorr The instruction at 0x2808335c referenced memory at 0x0004. The memory couldn't be written this error is because of not doing lock on %bounds ? when we do the lock like lock(%bounds) does it lock all the elements in hash ? Thanx Madhu Thanx -Madhu --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: hi, I just want to find out how and when to use locks in threads... i have following program.. in following %bounds is global variable each thread will update %bounds and later i am using %bounds... do i have lock the %bounds before each thread update ? my %bounds = (); by default, %bounds is not shared among threads (local variable is not shared among threads), you have to tell Perl that you want to share it like: use threads::shared; my %bounds : shared = (); now that %bounds is shared, you need to lock it when you update/access %bounds. again you have to tell Perl that you want to lock it like: { lock(%bounds); #-- do something with %bounds } #-- unlock when block exit the bare block is important, Perl unlocks %bounds automatically when the block exit. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl Application error on windows
Hi, I have following sorting program... basically it will split the large files into small file and creates thread..each thread will sort files after that merge back all sorted files... this program works fine on single CPU machine... same program giving problem on 8 CPU machine... the problem is , after creating the thread one of the thread finishes the job... all other threads are still working as soon as one thread finishes the job, i am getting perl application error (pops up small window) popup window contains following message... == perl.exe application errorr The instruction at 0x2808335c referenced memory at 0x0004. The memory couldn't be written === follwoing is output D:\Madhu\Sort_tmpperl sort_new1.pl Thu Feb 27 14:37:00 2003 thread 1 Sorting chunk : tmp_1.txt Thu Feb 27 14:37:00 2003 thread 2 Sorting chunk : tmp_2.txt Thu Feb 27 14:37:00 2003 thread 3 Sorting chunk : tmp_3.txt Thu Feb 27 14:37:01 2003 thread 4 Sorting chunk : tmp_4.txt Thu Feb 27 14:37:05 2003 thread 5 Sorting chunk : tmp_5.txt Thu Feb 27 14:37:11 2003 thread 6 Sorting chunk : tmp_6.txt Thu Feb 27 14:37:17 2003 thread 7 Sorting chunk : tmp_7.txt Thu Feb 27 14:37:25 2003 thread 8 Sorting chunk : tmp_8.txt Thu Feb 27 14:37:34 2003 thread 9 Sorting chunk : tmp_9.txt Thu Feb 27 14:37:42 2003 thread 10 Sorting chunk : tmp_10.txt Thu Feb 27 14:37:51 2003 thread 11 Sorting chunk : tmp_11.txt Thu Feb 27 14:38:02 2003 thread 12 Sorting chunk : tmp_12.txt Thu Feb 27 14:38:14 2003 thread 13 Sorting chunk : tmp_13.txt Thu Feb 27 14:38:26 2003 thread 14 Sorting chunk : tmp_14.txt Thu Feb 27 14:38:44 2003 thread 14 Sorting chunk : tmp_14.txt COMPLETED ** here i am getting error ..following is message perl.exe application errorr The instruction at 0x2808335c referenced memory at 0x0004. The memory couldn't be written *** any body have any idea ? following is my script ++ #!C:\perl_5.8\bin\perl -w #use strict; use threads; use threads::shared; my $counter = 0; my @tmp_files; my @buffer; my %bounds:shared = (); my $i = 0; my $tm1 = my_time(); my $file = 'D:\Madhu\Tmp\abi_feeder.dat'; open(FILE,$file) || die $!; while(FILE){ push(@buffer,$_); if(@buffer 100){ $counter++; my $tmp = tmp_$counter.txt; open(TMP,$tmp) || die $!; for(@buffer){ print TMP $_; } close(TMP); push(@tmp_files,$tmp); @buffer = (); } } if(@buffer){ my $tmp = tmp_ . ++$counter . .txt; open(TMP,$tmp) || die $!; for(@buffer){ print TMP $_; } push(@tmp_files,$tmp); close(TMP); @buffer = (); } my @threads = (); for(@tmp_files){ push(@threads, new threads(\sort_it,$_)); } $_-join for(@threads); my_print(Sorting completed, merging started\n); #$thrs = scalar(@threads); #print no of threads : $thrs\n; #sleep(10); my @keys = keys %bounds; #my @vals = values %bounds; my $n_keys = scalar(@keys); my_print(no of keys : $n_keys\n); #print vals : @vals\n; merge_it(\%bounds); my_print(merge completed\n); my $tm2 = my_time(); print \n\nReport \n; print Sort Start : $tm1\n; print Sort End : $tm2\n; print ---\n; sub sort_it{ #my $ref = shift; #my $tmp = shift; my $chunk = shift; my $first = 1; my $tid = threads-self-tid(); my_print(thread $tid Sorting chunk : $chunk\n); my @buf = (); open(TMP,$chunk) || die $!; push (@buf, $_) while(TMP); close(TMP); open(TMP,$chunk) || die $!; for(sort {my $fields1 = substr($a,10,10); my $fields2 = substr($b,10,10); $fields1 = $fields2 } @buf){ if($first){ { #lock lock(%bounds); $bounds{$chunk} = substr($_,10,10); } # unlock $first = 0; } print TMP $_; } close(TMP); # my @keys = keys %bounds; #print keys : @keys\n; my_print(thread $tid Sorting chunk : $chunk COMPLETED\n); } sub merge_it{ my $ref = shift; my @files = sort {$ref-{$a} = $ref-{$b}} keys %{$ref}; my $merged_to = $files[0]; my_print(merging : $files[0]\n); for(my $i=1; $i@files; $i++){ open(FIRST,$merged_to) || dir $!;
Re: Perl Application error on windows
I am using perl 5.8 following is my perl version info i am using windows. this error coming only on multi cpu machine ( 8 cpus) not on single cpu machine - This is perl, v5.8.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2002, Larry Wall Binary build 805 provided by ActiveState Corp. http://www.ActiveState.com Built 18:08:02 Feb 4 2003 - --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: Hi, I have following sorting program... basically it will split the large files into small file and creates thread..each thread will sort files after that merge back all sorted files... this program works fine on single CPU machine... same program giving problem on 8 CPU machine... the problem is , after creating the thread one of the thread finishes the job... all other threads are still working as soon as one thread finishes the job, i am getting perl application error (pops up small window) popup window contains following message... == perl.exe application errorr The instruction at 0x2808335c referenced memory at 0x0004. The memory couldn't be written i didn't spot anything that could cause this. what version of Perl are you using? i believe you are on the windows platform right? david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl Application error on windows
- if you do perl -V, do you see a line that looks like: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define NO, I didn't see that one... following is my perl -v output how to debug that error.. i started my script with debug option.. still i couldn't find where the error is i started my probram like perl -d sort.pl --- C:\Documents and Settings\RPonnoluperl -v This is perl, v5.8.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2002, Larry Wall Binary build 805 provided by ActiveState Corp. http://www.ActiveState.com Built 18:08:02 Feb 4 2003 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.com/, the Perl Home Page. --- __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
locks in threads
hi, I just want to find out how and when to use locks in threads... i have following program.. in following %bounds is global variable each thread will update %bounds and later i am using %bounds... do i have lock the %bounds before each thread update ? my %bounds = (); for(@tmp_files){ push(@threads, new threads(\sort_it,$_)); } sub sort_it{ #my $ref = shift; #my $tmp = shift; my $chunk = shift; my $first = 1; #my $tid = $thread-tid(); print thread Sorting chunk : $chunk\n; my @buf = (); open(TMP,$chunk) || die $!; push (@buf, $_) while(TMP); close(TMP); open(TMP,$chunk) || die $!; for(sort {my $fields1 = substr($a,10,5); my $fields2 = substr($b,10,5); $fields1 = $fields2 } @buf){ if($first){ $bounds{$chunk} = substr($_,10,5); $first = 0; } print TMP $_; } close(TMP); # my @keys = keys %bounds; #print keys : @keys\n; } __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Out of memory while finding duplicate rows
that is true..before loading into database...we need to do some validations if input file contains morethan 5% duplicates, don't load into databse... that is why i am finding duplicates... Thanx -Madhu --- Beau E. Cox [EMAIL PROTECTED] wrote: Thanks Peter - good point -Original Message- From: Peter Scott [mailto:[EMAIL PROTECTED] Sent: Sunday, February 23, 2003 5:17 AM To: [EMAIL PROTECTED] Subject: RE: Out of memory while finding duplicate rows In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Beau E. Cox) writes: Hi - Wait! If you are going to load the data into a database anyway, why not use the existing database (or the one being created) to remove duplicates. You don't even have to have an index on the column you are making unique (but it would be _much_ faster). Just select on you key, and, if found, reject the datum as a duplicate. You really shouldn't have to go to any draconian measures to find duplicates! No need even to do that. Just set a primary key constraint on the database table (like all good tables should have anyway) and you're done. (Or if the duplicate criterion involves some other column, put a UNIQUE constraint on it.) Then all inserts of duplicate records will fail automatically. Just make sure that RaiseError is set to false in the DBI connect. -- Peter Scott http://www.perldebugged.com I was speaking in general terms - I have no idea what the structure of his target db is, so my manual way covers all bases... :) Aloha = Beau; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to sort a big file
Hi David, how are U... I am using u r program for sorting... below is u r program (at the end of mail)... I am sorting 7.5 GB file with this program... it has 13 millions of records... i changed u r program to following if(@buffer 50){ my $tmp = tmp . $counter++ . .txt; . } following are the statistics... it took 5:30 hours to sort 13 millions record file... on 8 CPU's and 8GB RAM how to improve the speed i think 5 hours is more Thanx -Madhu --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: Hi, I want to sort a file and want to write the result to same file I want to sort a based on 3rd column.. following is my file format C1 C2 C3 C4 1234 guhr 89890 uierfer 1324 guii 60977 hiofver 5467 frwf 56576 err i want to sort above file based on column 3(C3) and i want to write sorted result to same file After sorting my file should be 5467 frwf 56576 err 1324 guii 60977 hiofver 1234 guhr 89890 uierfer how to do this ? file may have around 20 millions rows .. if you are using the *nix os, you should try the sort utility. if you are not using *nix and you don't have the sort utility, you will have to rely on Perl's sort function. with 20m rows, you probably don't want to store everything in memory and then sort them. what you have to do is sort the data file segment by segment and then merge them back. merging is the real tricky business. the following script(which i did for someone a while ago) will do that for you. what it does is break the file into multiple chunks of 10 lines, sort the chunks in a disk tmp file and then merge all the chunks back together. when i sort the file, i keep the smallest boundary of each chunk and use this number to sort the file so you don't have to compare all the tmp files. #!/usr/bin/perl -w use strict; my @buffer = (); my @tmps= (); my %bounds = (); my $counter = 0; open(FILE,file.txt) || die $!; while(FILE){ push(@buffer,$_); if(@buffer 10){ my $tmp = tmp . $counter++ . .txt; push(@tmps,$tmp); sort_it([EMAIL PROTECTED],$tmp); @buffer = (); } } close(FILE); merge_it(\%bounds); unlink(@tmps); #-- DONE --# sub sort_it{ my $ref = shift; my $tmp = shift; my $first = 1; open(TMP,$tmp) || die $!; for(sort {my @fields1 = split(/\s/,$a); my @fields2 = split(/\s/,$b); $fields1[2] = $fields2[2] } @{$ref}){ if($first){ $bounds{$tmp} = (split(/\s/))[2]; $first = 0; } print TMP $_; } close(TMP); } sub merge_it{ my $ref = shift; my @files = sort {$ref-{$a} = $ref-{$b}} keys %{$ref}; my $merged_to = $files[0]; for(my $i=1; $i@files; $i++){ open(FIRST,$merged_to) || dir $!; open(SECOND,$files[$i]) || dir $!; my $merged_tmp = merged_tmp$i.txt; open(MERGED,$merged_tmp) || die $!; my $line1 = FIRST; my $line2 = SECOND; while(1){ if(!defined($line1) defined($line2)){ print MERGED $line2; print MERGED while(SECOND); last; } if(!defined($line2) defined($line1)){ print MERGED $line1; print MERGED while(FIRST); last; } last if(!defined($line1) !defined($line2)); my $value1 = (split(/\s/,$line1))[2]; my $value2 = (split(/\s/,$line2))[2]; if($value1 == $value2){ print MERGED $line1; print MERGED $line2; $line1 = FIRST; $line2 = SECOND; }elsif($value1 $value2){ while($value1 $value2){ print MERGED $line2; $line2 = SECOND; last unless(defined $line2); $value2 = (split(/\s/,$line2))[2]; } }else{ while($value1 $value2){ print MERGED $line1; $line1 = FIRST; last unless(defined $line1
Multi threading in perl
Hi, does anybody have sample perl script multi threaded program any site does talks about perl multi threading I appreciate u r help Thanx -Madhu __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Out of memory while finding duplicate rows
Hi, I have a script that will find out duplicate rows in a file...in a file i have 13 millions of records out of that not morethan 5% are duplicate for finding duplicate i am using following function... while (FH) { if (find_duplicates ()) { $dup++ } } # return 1, if record is duplicate #returns 0, if record is not duplicate sub find_duplicates () { $key = substr($_,10,10); if ( exists $keys{$key} ) { $keys{$key}++; return 1; #duplicate row } else { $keys{$key}++; return 0; #not a duplicate } } - here i am storing 13 millions into hash... I think that is why i am getting out of memory. how to avoid this ? Thanx -Madhu __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Out of memory while finding duplicate rows
Hi, those data finally have to load into database.. before loading into dabase,,we need to do some validations like remove duplicate etc. that is why i am doing... i have another idea.. What i am planning is first sort the file.. once we sort the file..then it is easy to find duplicate $first =1; while (FH) { if ($first) { my $last_key = substr($_,10,10); last_$_ = $_; $first = 0; next; } my $cur_key = substr($_,10,10); if ($last_key == $cur_key) { print dup_file last_$_; $dup++; } else { print good_file $_; $good++; } last_$_ = $_; } then only thing is we need to find out how much time it will take to sort 22 millino rows file Any comments ? sugegestions ? --- Beau E. Cox [EMAIL PROTECTED] wrote: Hi - -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED] Sent: Saturday, February 22, 2003 11:12 AM To: [EMAIL PROTECTED] Subject: Out of memory while finding duplicate rows Hi, I have a script that will find out duplicate rows in a file...in a file i have 13 millions of records out of that not morethan 5% are duplicate for finding duplicate i am using following function... while (FH) { if (find_duplicates ()) { $dup++ } } # return 1, if record is duplicate #returns 0, if record is not duplicate sub find_duplicates () { $key = substr($_,10,10); if ( exists $keys{$key} ) { $keys{$key}++; return 1; #duplicate row } else { $keys{$key}++; return 0; #not a duplicate } } - here i am storing 13 millions into hash... I think that is why i am getting out of memory. how to avoid this ? Thanx -Madhu Yeah, Madhu, you are treading on the edge of memory capabilties... You may need to use a database (MySQL comes to mind), and write a key-value table that could accomplish your task as a hash would, and you could handle as many records as your disk space allows. Do you currently have a database installed? If you are running on Windows, even Access would work. Have you used the perl DBI (CPAN) interface? Just some thoughts... Aloha = Beau; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Sending e-mail from perl script using SMTP on Windows
Hi, This is regarding sending e-mail from perl script using SMTP my script is running fine..but i am not getting any mail which i sent from script... following is my program correct me if any thing is wrong in the script. messages with debug option attached at the end. --- Script Starts -- sub send_mail { my ( $to, $from, $subject , @body)=@_ ; use Net::SMTP ; my $relay='xyz.ap.bdi.gte.com'; print relay is : $relay\n; #my $smtp=Net::SMTP-new($relay, # Mreddy = '[EMAIL PROTECTED]', # Timeout = 30, # Debug = 1) ; my $smtp=Net::SMTP-new($relay) || die Couldnt make Connection: $!\n if (! defined $smtp) ; $smtp-mail($from) ; $smtp-to($to); $smtp-data(); $smtp-datasend(TO: $to\n); $smtp-datasend(From: $from\n); $smtp-datasend(Subject: $subject \n); $smtp-datasend (\n ) ; foreach (@body) { $smtp-datasend($_ \n) ; } $smtp-dataend() ; $smtp-quit ; } # end of function @body=( This is a TEST MESSAGE ) ; send_mail('[EMAIL PROTECTED]','[EMAIL PROTECTED]', hello, @body); Script Ends if I enable debug option in that script, i got following Mreddy is my machine name where i am running perl script =debug mesage = C:\Mydat\Perlc:\usr\bin\perl smtp.pl Net::SMTP: Net::SMTP(2.24) Net::SMTP: Net::Cmd(2.21) Net::SMTP: Exporter(5.562) Net::SMTP: IO::Socket::INET(1.25) Net::SMTP: IO::Socket(1.26) Net::SMTP: IO::Handle(1.21) Net::SMTP=GLOB(0x1aafb98) 220 xyz.ap.bdi.gte.com ESMTP Server (Microso ft Exchange Internet Mail Service 5.5.2653.13) ready Net::SMTP=GLOB(0x1aafb98) EHLO localhost.localdomain Net::SMTP=GLOB(0x1aafb98) 250-blackberry.ap.bdi.gte.com Hello [MREDDY] Net::SMTP=GLOB(0x1aafb98) 250-XEXCH50 Net::SMTP=GLOB(0x1aafb98) 250-HELP Net::SMTP=GLOB(0x1aafb98) 250-ETRN Net::SMTP=GLOB(0x1aafb98) 250-DSN Net::SMTP=GLOB(0x1aafb98) 250-SIZE 0 Net::SMTP=GLOB(0x1aafb98) 250-AUTH LOGIN Net::SMTP=GLOB(0x1aafb98) 250 AUTH=LOGIN SMTP is : Net::SMTP=GLOB(0x1aafb98) Net::SMTP=GLOB(0x1aafb98) MAIL FROM:[EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) 250 OK - mail from [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) RCPT TO:[EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) 250 OK - Recipient [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) DATA Net::SMTP=GLOB(0x1aafb98) 354 Send data. End with CRLF.CRLF Net::SMTP=GLOB(0x1aafb98) TO: [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) From: [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) Subject: hello Net::SMTP=GLOB(0x1aafb98) Net::SMTP=GLOB(0x1aafb98) This is a TEST MESSAGE Net::SMTP=GLOB(0x1aafb98) . Net::SMTP=GLOB(0x1aafb98) 250 OK Net::SMTP=GLOB(0x1aafb98) QUIT Net::SMTP=GLOB(0x1aafb98) 221 closing connection __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sending e-mail from perl script using SMTP on Windows!!! working now
Hi Guys, now it's working fine there is typeo in e-mail address i put email address as '[EMAIL PROTECTED]' here typeo... actual is redy.ponnolu now, how to chatch this type of erros in script... if i put wrong e-mail address...does it bounce back ? how to check this... --- Madhu Reddy [EMAIL PROTECTED] wrote: Hi, This is regarding sending e-mail from perl script using SMTP my script is running fine..but i am not getting any mail which i sent from script... following is my program correct me if any thing is wrong in the script. messages with debug option attached at the end. --- Script Starts -- sub send_mail { my ( $to, $from, $subject , @body)=@_ ; use Net::SMTP ; my $relay='xyz.ap.bdi.gte.com'; print relay is : $relay\n; #my $smtp=Net::SMTP-new($relay, # Mreddy = '[EMAIL PROTECTED]', # Timeout = 30, # Debug = 1) ; my $smtp=Net::SMTP-new($relay) || die Couldnt make Connection: $!\n if (! defined $smtp) ; $smtp-mail($from) ; $smtp-to($to); $smtp-data(); $smtp-datasend(TO: $to\n); $smtp-datasend(From: $from\n); $smtp-datasend(Subject: $subject \n); $smtp-datasend (\n ) ; foreach (@body) { $smtp-datasend($_ \n) ; } $smtp-dataend() ; $smtp-quit ; } # end of function @body=( This is a TEST MESSAGE ) ; send_mail('[EMAIL PROTECTED]','[EMAIL PROTECTED]', hello, @body); Script Ends if I enable debug option in that script, i got following Mreddy is my machine name where i am running perl script =debug mesage = C:\Mydat\Perlc:\usr\bin\perl smtp.pl Net::SMTP: Net::SMTP(2.24) Net::SMTP: Net::Cmd(2.21) Net::SMTP: Exporter(5.562) Net::SMTP: IO::Socket::INET(1.25) Net::SMTP: IO::Socket(1.26) Net::SMTP: IO::Handle(1.21) Net::SMTP=GLOB(0x1aafb98) 220 xyz.ap.bdi.gte.com ESMTP Server (Microso ft Exchange Internet Mail Service 5.5.2653.13) ready Net::SMTP=GLOB(0x1aafb98) EHLO localhost.localdomain Net::SMTP=GLOB(0x1aafb98) 250-blackberry.ap.bdi.gte.com Hello [MREDDY] Net::SMTP=GLOB(0x1aafb98) 250-XEXCH50 Net::SMTP=GLOB(0x1aafb98) 250-HELP Net::SMTP=GLOB(0x1aafb98) 250-ETRN Net::SMTP=GLOB(0x1aafb98) 250-DSN Net::SMTP=GLOB(0x1aafb98) 250-SIZE 0 Net::SMTP=GLOB(0x1aafb98) 250-AUTH LOGIN Net::SMTP=GLOB(0x1aafb98) 250 AUTH=LOGIN SMTP is : Net::SMTP=GLOB(0x1aafb98) Net::SMTP=GLOB(0x1aafb98) MAIL FROM:[EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) 250 OK - mail from [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) RCPT TO:[EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) 250 OK - Recipient [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) DATA Net::SMTP=GLOB(0x1aafb98) 354 Send data. End with CRLF.CRLF Net::SMTP=GLOB(0x1aafb98) TO: [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) From: [EMAIL PROTECTED] Net::SMTP=GLOB(0x1aafb98) Subject: hello Net::SMTP=GLOB(0x1aafb98) Net::SMTP=GLOB(0x1aafb98) This is a TEST MESSAGE Net::SMTP=GLOB(0x1aafb98) . Net::SMTP=GLOB(0x1aafb98) 250 OK Net::SMTP=GLOB(0x1aafb98) QUIT Net::SMTP=GLOB(0x1aafb98) 221 closing connection __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to get 1st line, last line and no of lines in a file
Hi, How to get first line, last line and no of lines in a file. is there any perl functions available for that ? right now what i am doing is open file while (FH { $lines++; } close(FH) This operation is expensive.. suppose, if file have millions of records, it will take more time I think there should be some functions to get those.. i appreciate u r help Thanx in advance -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to set environment variables
Hi, I want to put MFILE=mdl_data.txt in ENV and want to access later.. i am trying following...I am getting error... system(`MFILE=mdl_data.txt`); $k6 = MFILE; $key6 = $ENV{$k6}; print $key6 \n; how to do this ? Thanx -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to avoid this Warning ?
Hi, I have following script, basically this will ding the duplicate rows in a file... I am getting following warnings Use of uninitialized value at Audit_WTN.pl line 133, FH_IN_FILE chunk 18. Use of uninitialized value at Audit_WTN.pl line 133, FH_IN_FILE chunk 19. how to avoid warning at following location 133 if ( $ret = 1 ) { # return 1, if record is duplicate #returns 0, if record is not duplicate sub find_duplicates () { 128# get the key frim row 129 $key = substr($_,8,18); 130 $ret = $keys{$key}; 132 #Record is Duplicate 133 if ( $ret = 1 ) { 133 $keys{$key}++; 134 return 1; } else { $keys{$key}++; return 0; #not a duplicate } } __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Too may arguements Error
Hi, i have a script with multi files... in one file, i defined all the functions.. and from other file i am calling the functions... suppose, following is my function defination... sub log_msg() { print LOG @_\n; } i am calling this function with log_msg(Running script\n) here i am getting following error, too many arguements to log_msg at (Running script\n) -- then i changed the function defnitation.like following ##here i removed () in function definition sub log_msg { print LOG @_\n; } now it's workingI am curious to know, why it is hapenning ? in function definition we don't need to put () ? Thanx -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
how to sort a big file
Hi, I want to sort a file and want to write the result to same file I want to sort a based on 3rd column.. following is my file format C1 C2 C3 C4 1234 guhr 89890 uierfer 1324 guii 60977 hiofver 5467 frwf 56576 err i want to sort above file based on column 3(C3) and i want to write sorted result to same file After sorting my file should be 5467 frwf 56576 err 1324 guii 60977 hiofver 1234 guhr 89890 uierfer how to do this ? file may have around 20 millions rows .. I appreciate u r help.. -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to Add spaces at the end of a line
Hi, I want to do some data validation... I hvae to read each (row)line in a file and have to check the length of each row, if length of row is 263 I need to add 2 spaces at the end of line (row) to make 265 row lenghth .. Here how to add spaces at the end of length while(FH) { if (length($_) == 263) { Add 2 spaces to the end (before new line char) of $_ } } How to do this ? Thanx -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to Add spaces at the end of a line
while(FH) { if (length($_) == 263) { Add 2 spaces to the end (before new line char) of $_ $_ .= ' '; # or $_ .= ' ' x 2; } } How to do this ? $_ will have newline char.. ' '(2 spaces) added after the new line char (\n) i want to add before newline char... i don't want to chomp the newline char i want new line char should be there again.. how to do this ? -Madhu Thanx -Madhu __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
perl behaviour on Multi processor machine
Hi, When i ran perl script on multi processor machine... it is taking more time as than on single processor machine Let me explain clearly I have big file (.5Gb) it has 8 million records... my perl script will read each record and validates.. Validation includes..checking each record lenghth etc When i ran this script on single processor machine With 256MB RAM, It took 3 min to process 8 million records... If ran the same script on Multi processor machine (4 CPU's and 3GB RAM), it took 6min Any body have idea why it is taking more time on multi processor system ? Thanx -Madhu __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl behaviour on Multi processor machine
Hi, Thanx all for u r input... I ran only once on two systems for comparision What i observed is, when i ran on small machine ( 1cpu and 512 MB ram), CPU utilisations going to above 95 %...memory utilisation is 50% and when i ran on 4 cpu machines, cpu utilisation is not more than 50%...memory utilisations is 10% on 4 CPU machine, so many other applications are running... I think their my script not scheduled continuously... is theards on perl are good ? I never used threads in perl..i used in unix... is it good idea to use threads to validate such a huge records (22 millions) ? Thanx -Madhu --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: Hi, When i ran perl script on multi processor machine... it is taking more time as than on single processor machine Let me explain clearly I have big file (.5Gb) it has 8 million records... my perl script will read each record and validates.. Validation includes..checking each record lenghth etc When i ran this script on single processor machine With 256MB RAM, It took 3 min to process 8 million records... If ran the same script on Multi processor machine (4 CPU's and 3GB RAM), it took 6min Any body have idea why it is taking more time on multi processor system ? there are a lot of reason why your script runs slower in a more powerful machine but i am a bit suprise by your finding, how many test have you done to compare the result in these 2 machines? one? or have you test at least say, 10 times, and average the process time between the 2? a machine with 4 cpu and 3gb of memory is definitely hard wired to crunch number and boost i/o performance. not accounting for machine load, there is very little reason your Perl script will run slower on a powerful machine. i don't believe i/o is the bottleneck in your 4cpu machine. again, if the machine has heavy load then it could be the reason but hardware wise, it shouldn't. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
finding rows in a large file (22 millions of rows)
Hi, I want find a duplicate records in a large file it contains around 22 millions records. basically following is my file structure C1 C2 C3 C4 12345 efghij klmno pqrs 34567 abnerv oiuuy uyrv ... ... ... . it has 22 million records..and each record have 4 columns (C1,C2,C3 and C4) C1 is primary key here i want to do some validation.. following is my validation... 1. Validate record length 2. Check if first column is NULL 3. Separate duplicate records How do i separate dulicate records on such a huge file. duplicate means...only primary key (column)... if column1 (C1) is duplicate, that means that row is duplicate row and need to write into another file Does anybody have effeciant algorithm to find duplicate records on a large file duplicate means, not complete row duplicate..if column1 is duplicate, that means that row is duplicate I appreciate u r help -Madhu __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: finding rows in a large file (22 millions of rows)
C1 C2 C3 C4 12345 efghij klmno pqrs 34567 abnerv oiuuy uyrv 94567 abnerv gtuuy hyrv 12345 aswrfr rtyyt erer 94567 abnerv gtuuy hyrv Here row1 and row4 are duplicates...those needs to be removed or moved to another file --- Madhu Reddy [EMAIL PROTECTED] wrote: Hi, I want find a duplicate records in a large file it contains around 22 millions records. basically following is my file structure C1 C2 C3 C4 12345 efghij klmno pqrs 34567 abnerv oiuuy uyrv ... ... ... . it has 22 million records..and each record have 4 columns (C1,C2,C3 and C4) C1 is primary key here i want to do some validation.. following is my validation... 1. Validate record length 2. Check if first column is NULL 3. Separate duplicate records How do i separate dulicate records on such a huge file. duplicate means...only primary key (column)... if column1 (C1) is duplicate, that means that row is duplicate row and need to write into another file Does anybody have effeciant algorithm to find duplicate records on a large file duplicate means, not complete row duplicate..if column1 is duplicate, that means that row is duplicate I appreciate u r help -Madhu __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: finding rows in a large file (22 millions of rows)
1 word. Oracle. This is really why database software exists. I know this probably didn't help much, but if this is more than a one time occurrence a real database ought to be considered. You might start by checking out any reference material on how large database systems handle this sort of thing, as that is exactly what you are trying to mimic. We are trying to load date into teradata [which is data warehousing, stores Terabytes of data, and which is 10 times faster than any other database..) before loading data into Teradata, we need to do some massaging on data..basically eliminating..duplicate rows and invalid rows... __ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to Handle Large files in Perl ?
Hi, We are doing file operations on large files(more than 5GB). basically reading the file and validatiing the each record in in the file. we used Tie::File It took 35 min to read and count the number of lines in file of 8millions (500MB) following is the script Does anybody have any idea is there any good perl modules available for handling large files... Thanx -Madhu - #!C:\Perl\bin\perl -w use Tie::File; $IN_FILE = 'H:\Madhu\madhudb2.txt'; $time1 = my_time(); print Before tieing : $time1\n; tie @file_array, 'Tie::File', $IN_FILE or die opening file : $IN_FILE $!\n; $time2 = my_time(); print Before tieing : $time2\n; $time3 = my_time(); print Before array count : $time3\n; $n_recs = @file_array; print records in array is : $n_recs\n; $time4 = my_time(); print After array count : $time4\n; untie @file_array; sub my_time() { my $time= time ; $daytime = localtime($time) ; return $daytime ; } __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to send an e-mail from perl script on windows using SMTP?
Hi, I did telnet ..i got following error - C: telnet ivhpxc0003.ap.bdi.gte.com 25 Connecting To ivhpxc0003.ap.bdi.gte.com...Could not open a connection to host on port 25 : Connect failed C:telnet ivhpxc0003.ap.bdi.gte.com Connecting To ivhpxc0003.ap.bdi.gte.com...Could not open a connection to host: Connect failed - what couldbe the error ? Thanx -Madhu --- Timothy Johnson [EMAIL PROTECTED] wrote: Assuming that ivhpxc0003.ap.bdi.gte.com is your email server, I would first try to do a telnet ivhpxc0003.ap.bdi.gte.com 25 at the command prompt. If you get a connection refused or denied message, then you will not be able to send the email from your script. -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 05, 2003 6:11 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: How to send an e-mail from perl script on windows using SMTP? I changed to Net::SMTP still i am getting following error Couldnt make Connection: Unknown error --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: use NET::SMTP ; should probably be: use Net::SMTP; unless NET::SMTP is a new module. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- 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] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to send an e-mail from perl script on windows using SMTP?
This script is running where my e-mail client is (MicroSoft Look)... I am not running on remote.. I am running on localNetwork I am using Microsoft Outlook 2002 I used following procedure to get the my-email server name - 1. On Outlook ToolsoptionsMail Setup===E-mail Accounts==view existing E-mail Accounts== ==microsoft exchange server==Double click on Microsoft exchange server== I got following IVHPXC0003 Then i did ping...I got some IP address then I did nslookup then I got the following host name ivhpxc0003.ap.bdi.gte.com Is this is not my SMTP server ? what could be the reasons for not getting the connection. Then i setup the debug option. After that i got following error = Couldnt make Connection: Unknown error === How to set debug option is following is correct... following is my script - sub send_mail { my ( $to, $from, $subject , @body)=@_ ; use Net::SMTP ; my $relay='ivhpxc0003.ap.bdi.gte.com'; print relay is : $relay\n; my $smtp=Net::SMTP-new($relay, Hello = '[EMAIL PROTECTED]', Timeout = 30, Debug = 1) ; print SMTP is : $smtp\n; die Couldnt make Connection: $!\n if (! defined $smtp) ; $smtp-mail($from) ; $smtp-to($to); $smtp-data(); $smtp-datasend(TO: $to\n); $smtp-datasend(From: $from\n); $smtp-datasend(Subject: $subject \n); $smtp-datasend (\n ) ; foreach (@body) { $smtp-datasend($_ \n) ; } $smtp-dataend() ; $smtp-quit ; } @body=( This is a TEST MESSAGE ) ; send_mail('[EMAIL PROTECTED]','[EMAIL PROTECTED]', hello, @body); --- [EMAIL PROTECTED] wrote: On Thu, 6 Feb 2003 17:09:40 -, dan [EMAIL PROTECTED] wrote: I tried telnetting to that host on port 25, it exclaimed host could not be found. Seems that's your problem. Not necessarily, unless you are on the same local network as him. He could have an internal route/DNS available behind a firewall that you should never even know about and would never be able to use from outside of it, but to him the DNS and route are perfectly acceptable. Which brings up another point/question, is the script he is running remote or local? Even if his local mail client uses that mail host, if the script is in a remote location, it *may not* have access to that same server http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to send an e-mail from perl script on windows using SMTP?
Hi, I want to send an e-mail from perl script i have following script...but i am getting following error. does anybody have any idea, why it is failing ? == following is error message -- Couldnt make Connection: Unknown error --- following is script = #!C:\usr\bin\bin\perl -w sub send_mail { my ( $to, $subject , @body)=@_ ; use NET::SMTP ; my $relay=ivhpxc0003.ap.bdi.gte.com; my $smtp=Net::SMTP-new($relay) ; die Couldnt make Connection: $!\n if (! defined $smtp) ; $smtp-mail($from) ; $smtp-to($to); $smtp-data(); $smtp-datasend(TO: $to\n); $smtp-datasend(From: $from\n); $smtp-datasend(Subject: $subject \n); $smtp-datasend (\n ) ; foreach (@body) { $smtp-datasend($_ \n) ; } $smtp-dataend() ; $smtp-quit ; } @body=( This is a TEST MESSAGE ) ; send_mail('[EMAIL PROTECTED]', hello, @body); === __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to send an e-mail from perl script on windows using SMTP?
I changed to Net::SMTP still i am getting following error Couldnt make Connection: Unknown error --- david [EMAIL PROTECTED] wrote: Madhu Reddy wrote: use NET::SMTP ; should probably be: use Net::SMTP; unless NET::SMTP is a new module. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]