Re: File Size Script Help - Working Version
Hi folks, happy new year to everyone. ) John, you're right, of course. ) The filenames in nested directories could well overlap, and using $File::Find::name would be safer. Didn't think of that as a big problem, though, as original script (with 'opendir') ignored all the nested folders overall. Jonathan, no, you don't have to store the filenames as array: complete pathnames of the file can't be repeated. It'll be sufficient just to change this line: $filedata{$_} = [$filesize, $filemd5] for $filedata{$File::Find::name} = [$filesize, $filemd5] (and replace catfile in the writing block as well, as %filedata keys will now be the whole filenames themselves). On sorting: cmp and = is not the same: former compares strings, latter - numbers. So, for example, 'abc' cmp 'def' gives you -1, but 'abc' = 'def' gives 0 (and warnings about non-numeric args as well). It's nice to know the difference, but... do you really need to sort the output in your script? What output? ) It makes no difference in what order your .md5 files will be created, right? And you don't need to print the list of files processed (as I did in my test script, that's why the ordering was ever mentioned). As for $_, the problem John mentioned is logical, not 'perlical': as $_ variable is assigned a filename processed within File::Find target sub, and files in different directories could have the same names (but not full names, with absolute path attached), it may cause a bit of confusion when they DO have the same names. ) Generally speaking, $_ usage is for comfort and speed (yes, thinking of it as of 'it' word is right )). Of course, you can reassign it, but it'll make your scripts bigger (sometimes _much_ bigger) without adding much clarity, in my opinion. But that, again, is a matter of taste. For me, I use $_ almost every time I process shallow collections (hashes or arrays, doesn't matter). When two-level (or more complex) data structure is processed, it's usually required to use a temporary variable - but even then inner layers can be iterated with $_ easily. -- iD
Re: tinyMCE as web editor for editing code?
Hi Rajeev, On Mon, 2 Jan 2012 20:54:01 -0800 (PST) Rajeev Prasad rp.ne...@yahoo.com wrote: Hello, Has anyone ever used, tinyMCE as web based editor (to run inside the browser) to edit the perl/php/shell scripts on the server? I am looking for some direction and advice? I don't know how possible it is, because from what I know tinyMCE is an editor for rich-text syntax (HTML/etc.) and not for code, which is plaintext. That put aside, editing code directly on the server is not a good idea, because: 1. You should be using version control - see http://better-scm.shlomifish.org/ and http://www.slideshare.net/xSawyer/source-code-management-systems . Editing the files directly on the server will interfere with that. 2. You should be using a staging server, where you upload code for testing before actual deployment. 3. Allow the code on the server to be editable using HTTP/HTTPS will open the door for many security problems. -- All that put aside, I should note that the Mozilla people started working on a web/AJAX-based IDE, but it's currently in its infancy - http://mozillalabs.com/skywriter/ . I would not recommend editing code directly on the production server with it either. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ The Human Hacking Field Guide - http://shlom.in/hhfg Larry Wall can program in his sleep. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File Size Script Help - Working Version
Hello: On Sat, Dec 31, 2011 at 02:56:50AM +0200, Igor Dovgiy wrote: $filedata{$_} = [$filesize, $filemd5]; *snip* my ($size, $md5) = @{ $filedata{$filename} }; Alternatively, store a nested hash-reference: $filedata{$File::Find::name} = { md5 = $file_md5, size = $file_size, }; # ... my ($size, $md5) = @{$filedata{$filename}}{qw/size md5/}; That way you don't need to remember which [arbitrary] order they're in, and if the order changes, or more fields are added, the meaning of subsequent code doesn't change. Regards, -- Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org Castopulence Software https://www.castopulence.org/ Blog http://www.bamccaig.com/ perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' signature.asc Description: Digital signature