Re: how to do a `cp` on millions of files
SB == Steve Bertrand st...@ibctech.ca writes: SB my $results SB = timethese( 10, { SB 'rsync' = sub { `rsync -arc $directory $backup` }, SB 'perl-cp' = sub { dircopy( $directory, $backup ) }, to make this a proper benchmark, you need to remove all the copied files beforehand. rsync isn't supposed to copy files unless they have changed. basically rsync isn't doing any copies after the first time. this would be better to compare cp -r and dircopy as they are similar in function. then you wouldn't need to remove the files as you would always overwrite them with each copy pass. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to do a `cp` on millions of files
Uri Guttman wrote: SB == Steve Bertrand st...@ibctech.ca writes: SB my $results SB = timethese( 10, { SB 'rsync' = sub { `rsync -arc $directory $backup` }, SB 'perl-cp' = sub { dircopy( $directory, $backup ) }, to make this a proper benchmark, you need to remove all the copied files beforehand. rsync isn't supposed to copy files unless they have changed. basically rsync isn't doing any copies after the first time. this would be better to compare cp -r and dircopy as they are similar in function. then you wouldn't need to remove the files as you would always overwrite them with each copy pass. Heh. I knew I shouldn't have written the file creation function into the program. I figured that if the rsync test ran first, results would be ok. However, I see how the results may have been skewed. ...I think I've got the bench, and the dir struct fixed ( nothing in u* or p* -backup). On a normal day, I'd rather be in bed with my wife about now, but I wanted to give this a crack...I'm certain that I'll regret Perl for this... %ll -rwxr-xr-x 1 steve steve 348 Sep 29 02:13 bench.pl drwxr-xr-x 2 steve steve 1002 Sep 29 00:32 files drwxr-xr-x 2 steve steve 2 Sep 29 02:15 p-backup drwxr-xr-x 2 steve steve 2 Sep 29 02:15 u-backup #!/usr/bin/perl use warnings; use strict; use File::Copy::Recursive qw ( dircopy ); use Benchmark qw( :all ); my $directory = './files'; my $unix_bk = './u-backup'; my $perl_bk = './p-backup'; my $results = timethese( 5, { 'unix-cp' = sub { `cp -r $directory $unix_bk` }, 'perl-cp' = sub { dircopy( $directory, $perl_bk ) }, } ); cmpthese $results; __END__ Benchmark: timing 5 iterations of perl-cp, unix-cp... perl-cp: 74 wallclock secs ( 1.60 usr + 11.84 sys = 13.45 CPU) @ 0.37/s (n=5) unix-cp: 49 wallclock secs ( 0.00 usr 0.00 sys + 0.04 cusr 8.91 csys = 8.95 CPU) s/iter perl-cp unix-cp perl-cp 2.69 ---100% unix-cp 2.00e-16 134453125000256% -- Steve ps. let me know if this is the test you wanted to see. smime.p7s Description: S/MIME Cryptographic Signature
Re: Re: how to do a `cp` on millions of files
When It comes with million of files to copy from one place to another,there are two considerations: 1,performance 2,repeatable(fault tolerance),when it fails in-middle,it can continue with uncopied files.`cp -R` will not be ok for this because it begains from the very start, and `rsync` is good at this. 2009-09-29 xufengnju 发件人: Steve Bertrand 发送时间: 2009-09-29 14:46:50 收件人: Uri Guttman 抄送: xufengnju; beginners 主题: Re: how to do a `cp` on millions of files Uri Guttman wrote: SB == Steve Bertrand st...@ibctech.ca writes: SB my $results SB = timethese( 10, { SB 'rsync' = sub { `rsync -arc $directory $backup` }, SB 'perl-cp' = sub { dircopy( $directory, $backup ) }, to make this a proper benchmark, you need to remove all the copied files beforehand. rsync isn't supposed to copy files unless they have changed. basically rsync isn't doing any copies after the first time. this would be better to compare cp -r and dircopy as they are similar in function. then you wouldn't need to remove the files as you would always overwrite them with each copy pass. Heh. I knew I shouldn't have written the file creation function into the program. I figured that if the rsync test ran first, results would be ok. However, I see how the results may have been skewed. ...I think I've got the bench, and the dir struct fixed ( nothing in u* or p* -backup). On a normal day, I'd rather be in bed with my wife about now, but I wanted to give this a crack...I'm certain that I'll regret Perl for this... %ll -rwxr-xr-x 1 steve steve 348 Sep 29 02:13 bench.pl drwxr-xr-x 2 steve steve 1002 Sep 29 00:32 files drwxr-xr-x 2 steve steve 2 Sep 29 02:15 p-backup drwxr-xr-x 2 steve steve 2 Sep 29 02:15 u-backup #!/usr/bin/perl use warnings; use strict; use File::Copy::Recursive qw ( dircopy ); use Benchmark qw( :all ); my $directory = './files'; my $unix_bk = './u-backup'; my $perl_bk = './p-backup'; my $results = timethese( 5, { 'unix-cp' = sub { `cp -r $directory $unix_bk` }, 'perl-cp' = sub { dircopy( $directory, $perl_bk ) }, } ); cmpthese $results; __END__ Benchmark: timing 5 iterations of perl-cp, unix-cp... perl-cp: 74 wallclock secs ( 1.60 usr + 11.84 sys = 13.45 CPU) @ 0.37/s (n=5) unix-cp: 49 wallclock secs ( 0.00 usr 0.00 sys + 0.04 cusr 8.91 csys = 8.95 CPU) s/iter perl-cp unix-cp perl-cp 2.69 ---100% unix-cp 2.00e-16 134453125000256% -- Steve ps. let me know if this is the test you wanted to see.
Use Strict, Perl 5.10 and Global Symbol requires explicit package name
Take a look at the following snippet of code: #!/usr/bin/perl use warnings; use strict; use Tie::Handle::CSV; #Read Market Data my $file1= shift @ARGV; my $file2= shift @ARGV; my $master_fh=Tie::Handle::CSV-new($file1,header=1); my $transact_fh=Tie::Handle::CSV-new($file2,header=1); #Date Extraction my @dates; my $counter=0; my $index=0; while($master_fh) { $dates{$counter}= $_-{'Date'} ; #Line a $dates[$counter+1]=$index; $counter+=2; $index+=1; } my %datehash =...@dates; $counter=0; my %trades; while($transact_fh) { unless($trades{$_-{'Scrip'}}++) { $trades{$counter}=$_-{'Scrip'};#Line b $counter++; $trades{$counter}=$counter-1; $counter++; } } Now, I am using use strict directive (is that the right word, I am sorry I am still stuck in C/C++ mode), now in Line a, I have changed from square brackets to curly brackets for the hash work. The exactly same thing, is also done in Line #b. Why does, Line a throw a compiler error, Global Symbol @dates requires explicit package name while Line b throws the same error if I do just the opposite. Change the curly to sqaures. Btw, I can't do away with use strict directive. Moreover, is there a better, more elegant way to do the same thing which I have done inside the while loop? I am sure there is, because I think I haven't use the features which make Perl beautiful. And lastly, is there a way or a necessity to do, memory management. I agree, I read somewhere Perl does it for you, but I am asking nevertheless.. For example the array @dates, I need no longer, so can I do some delete() or something like that for the entire array itself. Thanks Soham Try the new Yahoo! India Homepage. Click here. http://in.yahoo.com/trynew
Re: Use Strict, Perl 5.10 and Global Symbol requires explicit package name
@dates and %dates are two different variables in Perl. An error occurs, becouse %dates is not declared. -- Alexandr A Alexeev http://web20.su/ Soham Das пишет: Take a look at the following snippet of code: #!/usr/bin/perl use warnings; use strict; use Tie::Handle::CSV; #Read Market Data my $file1= shift @ARGV; my $file2= shift @ARGV; my $master_fh=Tie::Handle::CSV-new($file1,header=1); my $transact_fh=Tie::Handle::CSV-new($file2,header=1); #Date Extraction my @dates; my $counter=0; my $index=0; while($master_fh) { $dates{$counter}= $_-{'Date'} ; #Line a $dates[$counter+1]=$index; $counter+=2; $index+=1; } my %datehash =...@dates; $counter=0; my %trades; while($transact_fh) { unless($trades{$_-{'Scrip'}}++) { $trades{$counter}=$_-{'Scrip'};#Line b $counter++; $trades{$counter}=$counter-1; $counter++; } } Now, I am using use strict directive (is that the right word, I am sorry I am still stuck in C/C++ mode), now in Line a, I have changed from square brackets to curly brackets for the hash work. The exactly same thing, is also done in Line #b. Why does, Line a throw a compiler error, Global Symbol @dates requires explicit package name while Line b throws the same error if I do just the opposite. Change the curly to sqaures. Btw, I can't do away with use strict directive. Moreover, is there a better, more elegant way to do the same thing which I have done inside the while loop? I am sure there is, because I think I haven't use the features which make Perl beautiful. And lastly, is there a way or a necessity to do, memory management. I agree, I read somewhere Perl does it for you, but I am asking nevertheless.. For example the array @dates, I need no longer, so can I do some delete() or something like that for the entire array itself. Thanks Soham Try the new Yahoo! India Homepage. Click here. http://in.yahoo.com/trynew -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Use Strict, Perl 5.10 and Global Symbol requires explicit package name
Shit!! Thanks, How asinine of me. From: Алексеев Александр aleks...@rumonitor.ru To: Soham Das soham...@yahoo.co.in Cc: beginners@perl.org Sent: Tuesday, 29 September, 2009 2:52:26 PM Subject: Re: Use Strict, Perl 5.10 and Global Symbol requires explicit package name @dates and %dates are two different variables in Perl. An error occurs, becouse %dates is not declared. -- Alexandr A Alexeev http://web20.su/ Soham Das пишет: Take a look at the following snippet of code: #!/usr/bin/perl use warnings; use strict; use Tie::Handle::CSV; #Read Market Data my $file1= shift @ARGV; my $file2= shift @ARGV; my $master_fh=Tie::Handle::CSV-new($file1,header=1); my $transact_fh=Tie::Handle::CSV-new($file2,header=1); #Date Extraction my @dates; my $counter=0; my $index=0; while($master_fh) { $dates{$counter}= $_-{'Date'} ; #Line a $dates[$counter+1]=$index; $counter+=2; $index+=1; } my %datehash =...@dates; $counter=0; my %trades; while($transact_fh) { unless($trades{$_-{'Scrip'}}++) { $trades{$counter}=$_-{'Scrip'};#Line b $counter++; $trades{$counter}=$counter-1; $counter++; } } Now, I am using use strict directive (is that the right word, I am sorry I am still stuck in C/C++ mode), now in Line a, I have changed from square brackets to curly brackets for the hash work. The exactly same thing, is also done in Line #b. Why does, Line a throw a compiler error, Global Symbol @dates requires explicit package name while Line b throws the same error if I do just the opposite. Change the curly to sqaures. Btw, I can't do away with use strict directive. Moreover, is there a better, more elegant way to do the same thing which I have done inside the while loop? I am sure there is, because I think I haven't use the features which make Perl beautiful. And lastly, is there a way or a necessity to do, memory management. I agree, I read somewhere Perl does it for you, but I am asking nevertheless.. For example the array @dates, I need no longer, so can I do some delete() or something like that for the entire array itself. Thanks Soham Try the new Yahoo! India Homepage. Click here. http://in.yahoo.com/trynew -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ From cricket scores to your friends. Try the Yahoo! India Homepage! http://in.yahoo.com/trynew
Re: Arrays, Dates, Indexing and Initialisation
r...@i.frys.com wrote: Soham Das wrote: int a[125]; for(i=0;i125;i++) a[i]=0; my @array; $array[$_] = 0 for 0..125; s/125/124/ -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Hash of Hashes
How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Soham From cricket scores to your friends. Try the Yahoo! India Homepage! http://in.yahoo.com/trynew
Re: Hash of Hashes
Soham Das wrote: How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Hashes use {}, arrays use [] $ChildHash{Joe}{21A} = Sally; -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
AW: Hash of Hashes
Soham Das soham...@yahoo.co.in asked: How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Please keep in mind: square brackets are for arrays/lists. Curly brackets are for hashes. In any case, wouldn't it be smarter to organize your data differently? I.e.: %parent = ( 'Joe' = { 'address' = '21A', children = ['Dick','Sally'] } ); To add another child to an existing parent you'd then say push @{$parent{'Joe'}{'children'}}, 'Jane'; To add a new parent: @{$parent{'Sven'}}{'address','children'} = ( '9b', ['Bjorn'] ); HTH, Thomas
Re: AW: Hash of Hashes
Yes,its much more powerful, the way you said, but in my case it won't be necessary or important. Here I guess, I gave a wrong example where the data can be changed. Lets assume, the hash of hash being a record of something which has already happened and hence we know the final value, not something which is right now happening, i.e changeable. In my case, its like $Position{$Scrip}{$Date}= #some value That is, my position in a previous date $Date, in the stock $scrip, was some integer. Thanks for the correction, regarding the brackets. I stand corrected and it seems I have made a lot of such mistakes apparent in the previous two three mails. Soham From: Thomas Bätzler t.baetz...@bringe.com To: beginners@perl.org Cc: Soham Das soham...@yahoo.co.in Sent: Tuesday, 29 September, 2009 3:46:28 PM Subject: AW: Hash of Hashes Soham Das soham...@yahoo.co.in asked: How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Please keep in mind: square brackets are for arrays/lists. Curly brackets are for hashes. In any case, wouldn't it be smarter to organize your data differently? I.e.: %parent = ( 'Joe' = { 'address' = '21A', children = ['Dick','Sally'] } ); To add another child to an existing parent you'd then say push @{$parent{'Joe'}{'children'}}, 'Jane'; To add a new parent: @{$parent{'Sven'}}{'address','children'} = ( '9b', ['Bjorn'] ); HTH, Thomas Connect more, do more and share more with Yahoo! India Mail. Learn more. http://in.overview.mail.yahoo.com/
Re: how to do a `cp` on millions of files
Why not mirror the partitions ? Or If solaris. Ufsdump 0cf - filesystem |(cd new filesys;ufsrestore -xf -) Sent from my Verizon Wireless BlackBerry -Original Message- From: Steve Bertrand st...@ibctech.ca Date: Mon, 28 Sep 2009 22:50:55 To: xufengnjuxufeng...@sina.com Cc: beginnersbeginners@perl.org Subject: Re: how to do a `cp` on millions of files xufengnju wrote: Hi all, I have a storage server that holds one million of images with well structured directory structure such as /data/user1/2008/09/12/image1.jpg /data/user1/2008/09/12/image2.jpg ... /data/user2/2009/01/01/image1.jpg ... I want to copy them to the /data2 directory in the same server on another disk partion. I want to keep the directory structure and `chown` `chmod` the directories and files,much like doing a `cp -rf /data /data2 chown -R sysuser:sysuser /data2 chmod -R 755 /data2`. File::Find maybe an option. Is there somebody who have some suggestions? If I do a `cp -rf /data /data2 chown -R sysuser:sysuser /data2 chmod -R 755 /data2`,how much time maybe taken to finish the job?(The images are about one million in count and 250GB in size totally). Perhaps I am missing something completely obvious. If not: Why-oh-why do you want to use Perl do perform such a task? Use dump/restore (which I can't recall a cli sequence for off the top of my head), or rsync: # mount the new disk into /mnt/data, then: % rsync -arcvv /data /mnt/data ...owns/perms will be copied. The '' will ensure that the process will continue if your term session breaks mid-stream. Steve
Re: Hash of Hashes
2009/9/29 Shawn H Corey shawnhco...@gmail.com: Soham Das wrote: How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Hashes use {}, arrays use [] That's in Python? :-) Perl's both hash and array use (). But anonymous hash and array use {} and []. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
get list of files sorted by date
Hello, according to the man glob can only sort by name. Is there a way to get a list of files sorted by date ? Bye Andreas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: get list of files sorted by date
print join \n, sort {(stat $a)[8] = (stat $b)[8]} glob ./*; -- Alexandr A Alexeev http://www.unixcommunity.net/ Andreas Moroder пишет: Hello, according to the man glob can only sort by name. Is there a way to get a list of files sorted by date ? Bye Andreas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: get list of files sorted by date
2009/9/29 Andreas Moroder andreas.moro...@sb-brixen.it: Hello, according to the man glob can only sort by name. Is there a way to get a list of files sorted by date ? sure. first I will use unix's ls command like ls -ltr. in perl one of the ways: my @sorted = map { $_-[0] } sort { $a-[1] = $b-[1] } map { [$_,(stat $_)[9]] } glob *; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Hash of Hashes
On Tue, Sep 29, 2009 at 07:40, Jeff Peng jeff.p...@freenet.de wrote: 2009/9/29 Shawn H Corey shawnhco...@gmail.com: Soham Das wrote: How can I create a Hash of Hashes from two lists. Is it possible? I want the effective functionality to be served like this $ChildHash[Joe][21A]=Sally i.e Joe at 21A has a child called Sally. List1 here will be the name of Parents, List2 here will contain the house number. Hashes use {}, arrays use [] That's in Python? :-) Perl's both hash and array use (). But anonymous hash and array use {} and []. snip To clarfy, Perl uses (LIST) to initialize hashs and arrays. One way to create a list is (X). my @a = (1, 2, 3); my %h = (a = 1, b = 2, c = 3); Perl uses X[Y] to get the value at the Yth index in X when X is an array or a list. my $x = $a[1]; #$x is now 2 Perl uses X{Y} to get the value associated with Y when X is a hash. $x = $h{c}; #$x is now 3 Perl uses [LIST] to create an anonymous array ref. my $aref = [1, 2, 3]; $x = $aref-[0]; #$x is now 1 Perl uses {LIST} to create an anonymous hash ref. my $href = {a = 1, b = 2, c = 3}; $x = $href-{b}; #$x is now 2 See [perldoc perlop][1] or my [perlopref][2] document for more information. [1] : http://perldoc.perl.org/functions/perlop.html [2] : http://github.com/cowens/perlopref -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Hash of Hashes
Jeff Peng wrote: That's in Python? :-) Wouldn't know, don't do Python. Perl's both hash and array use (). But anonymous hash and array use {} and []. Hashes use {}, arrays use [], lists use (). When you set an element of a hash, you use {} to surround its key: $hash{$key} = $value; When you set an element of an array, you use [] to surround its index: $array[$index] = $datum; When you set both to a list, surround the list with (): %hash = ( 1, 2, 3, ); @array = ( 'a', 'b', 'c', ); See `perldoc perldata` for more details. http://perldoc.perl.org/perldata.html -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Wants to migrate from one machine to another.
Hello, We have one software which is installed at one machine. The software was developed by many developers(students) as it was used in multiple projects in the lab, all the code is written in perl. Now we want to do the backup of that software for that we want to make one copy running on a new machine. The problem we are facing is that we installed many CPAN modules and different developers used different CPAN modules and non of them did the documentation. I need your guidance that how we know that the software is using which modules plus on a new system we wants to preinstalled all the modules before moving the software. Regards, Raheel.
Re: Wants to migrate from one machine to another.
Since you know the scripts' names you may find what modules they are using: http://search.cpan.org/~elliotjs/Module-Used-v1.2.0/lib/Module/Used.pm 2009/9/29 Raheel Hassan raheel.has...@gmail.com: Hello, We have one software which is installed at one machine. The software was developed by many developers(students) as it was used in multiple projects in the lab, all the code is written in perl. Now we want to do the backup of that software for that we want to make one copy running on a new machine. The problem we are facing is that we installed many CPAN modules and different developers used different CPAN modules and non of them did the documentation. I need your guidance that how we know that the software is using which modules plus on a new system we wants to preinstalled all the modules before moving the software. Regards, Raheel. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Wants to migrate from one machine to another.
Yes we know but the number of scripts is in hundreds, so it is very time consuming to identify the modules and then install, is there any quick way. On Tue, Sep 29, 2009 at 3:18 PM, Jeff Peng jeff.p...@freenet.de wrote: Since you know the scripts' names you may find what modules they are using: http://search.cpan.org/~elliotjs/Module-Used-v1.2.0/lib/Module/Used.pmhttp://search.cpan.org/%7Eelliotjs/Module-Used-v1.2.0/lib/Module/Used.pm 2009/9/29 Raheel Hassan raheel.has...@gmail.com: Hello, We have one software which is installed at one machine. The software was developed by many developers(students) as it was used in multiple projects in the lab, all the code is written in perl. Now we want to do the backup of that software for that we want to make one copy running on a new machine. The problem we are facing is that we installed many CPAN modules and different developers used different CPAN modules and non of them did the documentation. I need your guidance that how we know that the software is using which modules plus on a new system we wants to preinstalled all the modules before moving the software. Regards, Raheel.
Re: Wants to migrate from one machine to another.
Raheel Hassan wrote: Yes we know but the number of scripts is in hundreds, so it is very time consuming to identify the modules and then install, is there any quick way. pmfind will find all installed modules, whether they're in use or not. http://github.com/shawnhcorey/pmfind To use: pmfind \* You can use the output to create a `cpan` script to install them. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Wants to migrate from one machine to another.
Could you please write down the steps how to do that, I am using Ubuntu jaunty. On Tue, Sep 29, 2009 at 4:00 PM, Shawn H Corey shawnhco...@gmail.comwrote: Raheel Hassan wrote: Yes we know but the number of scripts is in hundreds, so it is very time consuming to identify the modules and then install, is there any quick way. pmfind will find all installed modules, whether they're in use or not. http://github.com/shawnhcorey/pmfind To use: pmfind \* You can use the output to create a `cpan` script to install them. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy.
Re: Arrays, Dates, Indexing and Initialisation
Soham Das wrote: a... How do I initialise an array of a definite size with zero. Say the C equivalent of such a statement will be: int a[125]; for(i=0;i125;i++) a[i]=0; You easily can, but why would you? It is often a sign of bad design. b. Is it possible, to have dates as index? I am trying to parse and process data corresponding to a list of trades I have made(financial trades) and want to see, how my portfolio varies with time. So is it possible to do in such a way? Just format them as a string: -mm-dd? -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
HI
Hello, Can anyone help me to explain how to call subroutines. Also if possible, explain with example for running blast searches. Many Thanks.
Re: AW: Hash of Hashes
SD == Soham Das soham...@yahoo.co.in writes: SD Lets assume, the hash of hash being a record of something which SD has already happened and hence we know the final value, not SD something which is right now happening, i.e changeable. you keep swapping hash and array concepts, words and symbols. please learn to keep them separate or your perl life will be hell. hashes have no concept of 'final value' as an array would. maybe you mean the hash is finalized and won't be changed anymore. if so then say that. SD In my case, its like SD $Position{$Scrip}{$Date}= #some value SD That is, my position in a previous date $Date, in the stock SD $scrip, was some integer. Thanks for the correction, regarding the SD brackets. I stand corrected and it seems I have made a lot of such SD mistakes apparent in the previous two three mails. hashes have no positions, just keys. again. try to use standard terminology or you won't convey any proper meaning here. programming requires this to be accurate. and yes, you have been making a bunch of hash/array mistakes and you must fix that in your head. they are similar in syntax styles in some ways (e.g. [] vs {}) but very different in semantics and terminology. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: AW: Hash of Hashes
Uri Guttman wrote: SD == Soham Das soham...@yahoo.co.in writes: SD Lets assume, the hash of hash being a record of something which SD has already happened and hence we know the final value, not SD something which is right now happening, i.e changeable. you keep swapping hash and array concepts, words and symbols. please learn to keep them separate or your perl life will be hell. hashes have no concept of 'final value' as an array would. maybe you mean the hash is finalized and won't be changed anymore. if so then say that. SD In my case, its like SD $Position{$Scrip}{$Date}= #some value SD That is, my position in a previous date $Date, in the stock SD $scrip, was some integer. Thanks for the correction, regarding the SD brackets. I stand corrected and it seems I have made a lot of such SD mistakes apparent in the previous two three mails. hashes have no positions, just keys. again. try to use standard terminology or you won't convey any proper meaning here. programming requires this to be accurate. and yes, you have been making a bunch of hash/array mistakes and you must fix that in your head. they are similar in syntax styles in some ways (e.g. [] vs {}) but very different in semantics and terminology. uri It would also help to post the snippet of code that is causing you problems. Include some data it is to work on (not real data, you don't want to post real data on a public mailing list; create some typical but fake data) and the output you want. There is no need to post the actual output; that can be generated by running the code. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Fwd: HI
Thanks for reply Rajiv. Will go through.Also can you explain me what this error means: Odd number of elements in anonymous hash at /usr/lib/cgi-bin/websubroutine.pl line 18. line 18 is as follows: print $q-header(text/html),
SOLVED re: GD::Text::Wrap
I think I had black text on a black bg or it was outside of the image. After some trial error, I got it to work. Corrected version is below along with notes to clarify since I found the module notes to be scant. Jo #!/usr/bin/perl use strict; use warnings; use CGI; use GD; use GD::Text::Wrap; my $query = new CGI; #my $text=hello; my $text = EOSTR; This is a very long line that is going to exceed the box width so we meed to try to get it to wrap within the space we have reserved for our image. EOSTR my $image = new GD::Image(600,180); # width,height of image # first spec'd color is a BG (suggest match page?) # then other colors to be used my $black = $image-colorAllocate( 0, 0, 0); my $red = $image-colorAllocate( 255, 0, 0); my $white= $image-colorAllocate(255,255,255); # instead try wrapping the text #$image-string(gdGiantFont,20,10,$text,$red); # # color below is text color my $wrapbox = GD::Text::Wrap-new($image, line_space = 4, color = $red, text= $text ); $wrapbox-set_font(gdGiantFont); # $wrapbox-set_font('arial',12); # Can't spec fonts on our system $wrapbox-set(align = 'left', width = 500); # text alignment and paragraph width; # height will autoscale with text $wrapbox-draw(25,10); # left and top positioning of paragraph $image-rectangle($wrapbox-get_bounds(25,10),$white); # optional colored border around text, use same top and left print $query-header(image/png); binmode STDOUT; print $image-png(); exit; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: hash question
Thanks to all that assisted in this thread. I think I am now getting where I want to go with using hashes. One comment that I could use clarification on is: JR( for ( $i=0; $i = $number_of_elements-1; $i++ ) { don't loop over indices, loop over the data. JR( $element = (split /,/, $_)[$i]; What is meant by don't loop over indices, loop over the data? Isn't the purpose of the indice to control how many times you loop? -Original Message- From: Uri Guttman [mailto:u...@stemsystems.com] Sent: Friday, September 25, 2009 1:58 PM To: Johnson, Reginald (GTS) Cc: beginners@perl.org Subject: Re: hash question JR( == Johnson, Reginald (GTS) reggie_john...@ml.com writes: JR( Sample input file test2,MS-Windows-NT,Silver,NPRO30DINCR,Client JR( JXWGTI7R5CHD1 WINDOWS NT,Schedule test2_full_1700 FULL 604800 JR( print Enter the filename of input file with full path\n; JR( my $input_file = ; JR( chomp($input_file); JR( # check to see if input file exist JR( if ( -e $input_file) { JR( open( INFILE, , $input_file) or JR( die $input_file does not exists: $!; JR( } the -e check and the open/die are redundant. drop the -e as you don't need it. JR( my %policy_Hash=(); no need to initialize a hash to () as my does that. JR( my ($parameters); declare vars as they are used. JR( while (INFILE) { JR( my @n = split /,/, $_; JR( my $number_of_elements = scalar @n; JR( print scalar @n, \n; why do you not use $number_of_elements since you just go it? JR( my ($policy_name,$i,$element); JR( ($policy_name,$parameters) = split( /,/, $_, 2 ); JR( print policy_name = $policy_name has $number_of_elements elements\n; JR( for ( $i=0; $i = $number_of_elements-1; $i++ ) { don't loop over indices, loop over the data. JR( $element = (split /,/, $_)[$i]; you split the whole line on , so that split won't do anything JR( print this is element i=$i $element\n; JR( $policy_Hash{$policy_name}{ 'element_$i'}= JR( (split /,/, $_)[$i]; here is your main bug. '' won't interpolate $i. use for that. this is assigning each value to the same hash element and overwriting the previous one. learn to use Data::Dumper to see what is really in your hash. JR( This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. References to Merrill Lynch are references to any company in the Merrill Lynch Co., Inc. group of companies, which are wholly-owned by Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this E-communication may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing. that disclaimer is longer than your code! uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: hash question
Johnson, Reginald (GTS) wrote: Thanks to all that assisted in this thread. I think I am now getting where I want to go with using hashes. One comment that I could use clarification on is: JR( for ( $i=0; $i = $number_of_elements-1; $i++ ) { don't loop over indices, loop over the data. JR( $element = (split /,/, $_)[$i]; What is meant by don't loop over indices, loop over the data? Isn't the purpose of the indice to control how many times you loop? Perl has many tools for manipulating arrays and you rarely need to use indexes. Loop by index: for my $index ( 0 .. $#array ){ my $item = $array[$index]; } Loop by element: for my $item ( @array ){ } -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: HI
2009/9/30 Jyoti jcutiep...@gmail.com: Thanks for reply Rajiv. Will go through.Also can you explain me what this error means: Odd number of elements in anonymous hash at /usr/lib/cgi-bin/websubroutine.pl line 18. That may mean, you passed wrong arguments to the method in a class. The method expects a hash, should have even number of elements. line 18 is as follows: print $q-header(text/html), Maybe you got wrong in other location. This statement has no problem for me: # perl -MCGI -e '$q=CGI-new;print $q-header(text/html)' Content-Type: text/html; charset=ISO-8859-1 Jeff. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: HI
Thanks Jeff On Wed, Sep 30, 2009 at 4:40 AM, Jeff Peng jeff.p...@freenet.de wrote: 2009/9/30 Jyoti jcutiep...@gmail.com: Thanks for reply Rajiv. Will go through.Also can you explain me what this error means: Odd number of elements in anonymous hash at /usr/lib/cgi-bin/websubroutine.pl line 18. That may mean, you passed wrong arguments to the method in a class. The method expects a hash, should have even number of elements. line 18 is as follows: print $q-header(text/html), Maybe you got wrong in other location. This statement has no problem for me: # perl -MCGI -e '$q=CGI-new;print $q-header(text/html)' Content-Type: text/html; charset=ISO-8859-1 Jeff.
Fw: AW: Hash of Hashes
- Forwarded Message From: Soham Das soham...@yahoo.co.in To: Uri Guttman u...@stemsystems.com Sent: Wednesday, 30 September, 2009 10:29:12 AM Subject: Re: AW: Hash of Hashes From: Uri Guttman u...@stemsystems.com To: Soham Das soham...@yahoo.co.in Cc: Thomas Bätzler t.baetz...@bringe.com; beginners@perl.org Sent: Tuesday, 29 September, 2009 9:17:57 PM Subject: Re: AW: Hash of Hashes SD == Soham Das soham...@yahoo.co.in writes: SD Lets assume, the hash of hash being a record of something which SD has already happened and hence we know the final value, not SD something which is right now happening, i.e changeable. you keep swapping hash and array concepts, words and symbols. please learn to keep them separate or your perl life will be hell. hashes have no concept of 'final value' as an array would. maybe you mean the hash is finalized and won't be changed anymore. if so then say that. The hash is finalised and wont be changing anymore. SD In my case, its like SD $Position{$Scrip}{$Date}= #some value SD That is, my position in a previous date $Date, in the stock SD $scrip, was some integer. Thanks for the correction, regarding the SD brackets. I stand corrected and it seems I have made a lot of such SD mistakes apparent in the previous two three mails. hashes have no positions, just keys. again. try to use standard terminology or you won't convey any proper meaning here. programming requires this to be accurate. and yes, you have been making a bunch of hash/array mistakes and you must fix that in your head. they are similar in syntax styles in some ways (e.g. [] vs {}) but very different in semantics and terminology. Now what I wrote, was not describing what that statement is supposed to do, but the english transliteration of that statement. i.e the hash position will convey me the record of my positions. Hence my position in a particular scrip on a particular date (which will act as keys) will give me some value, which will stand for the number of shares I was holding. I hope I am not ambiguous this time. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Now, send attachments up to 25MB with Yahoo! India Mail. Learn how. Yahoo! India has a new look. Take a sneak peek http://in.yahoo.com/trynew
Re: Fw: AW: Hash of Hashes
SD == Soham Das soham...@yahoo.co.in writes: hashes have no positions, just keys. again. try to use standard terminology or you won't convey any proper meaning here. programming requires this to be accurate. and yes, you have been making a bunch of hash/array mistakes and you must fix that in your head. they are similar in syntax styles in some ways (e.g. [] vs {}) but very different in semantics and terminology. SD Now what I wrote, was not describing what that statement is SD supposed to do, but the english transliteration of that SD statement. i.e the hash position will convey me the record of my SD positions. Hence my position in a particular scrip on a SD particular date (which will act as keys) will give me some value, SD which will stand for the number of shares I was holding. you are still inventing terms and not using standard ones. there is no hash position. i think you mean slot or entry which are commonly used for where a hash stores the value associated with a key. but that has nothing to do with a position in a script nor a date. it will help you enormously if you use the common terms for perl things. hashes have keys and values. values are stored in slots or entries (arrays or hashes). array slots are accessed by an integer index (or sequentially in a loop) and hash slots are accessed by a string key. read perldoc perldsc, perllol for more on perl data structures and how to create and access them. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/