DATA Transfer from a remote machine :: which one is best SCP or VSFTPD
Dear List I need to collect bulk data files from some remote machines into my local machine. I will be using a perl script to read about the remote machines directory listing from where I will get the source data files.The remote machines' directory listing from where I will get the data files most probably changes time by time . So now please tell me which one is good options can be used in this situation SCP or VSFTPD? I need a secure and fast data transfer. Thanks Regards in Advance Anirban Adhikary.
Re: DATA Transfer from a remote machine :: which one is best SCP or VSFTPD
I use SCP. About faster or not, it depends on the bandwidth in both locations and load CPU in each locations. On Thu, Mar 27, 2008 at 1:16 PM, Anirban Adhikary [EMAIL PROTECTED] wrote: Dear List I need to collect bulk data files from some remote machines into my local machine. I will be using a perl script to read about the remote machines directory listing from where I will get the source data files.The remote machines' directory listing from where I will get the data files most probably changes time by time . So now please tell me which one is good options can be used in this situation SCP or VSFTPD? I need a secure and fast data transfer. Thanks Regards in Advance Anirban Adhikary. -- Eko Budiharto
Re: Plotting widget in Perl?
Zentara, gtkdatabox looks good for me. Can you please mention which perl module in Gtk2::* should I use to use this from perl? Thanks! On Wed, Mar 26, 2008 at 5:23 PM, zentara [EMAIL PROTECTED] wrote: On Wed, 26 Mar 2008 00:22:03 +0530, [EMAIL PROTECTED] (Gowtham M) wrote: Thanks for the help. I tried to install Gtk2::Ex::Graph::* modules. Couldn't succeed. There was an error while building GD.pm: gcc -c -I/usr/include -I/usr/include/gd -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -march=i386 -mcpu=i686 -DVERSION=\2.35\ -DXS_VERSION=\2.35\ -fPIC -I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE -DHAVE_JPEG -DHAVE_FT -DHAVE_XPM -DHAVE_GIF -DHAVE_PNG -DHAVE_ANIMGIF GD.c There is a gd c library that needs to be installed first, and the level of the Perl GD module must be comptible with the c lib. The README docs usually tell you what c lib versions are working correctly. Normally, you can get the latest gd c lib, and the latest GD Perl module, and they will be compatible. Install them manually for best results. Install the c gd lib first. If you get GD going, you might take a look at the GD-SVG module. SVG's are scalable with the right viewer. zentara -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- Gowtham M
RE: How to replace one line in a text file with Perl?
Here is the entire code to accomplish your task. It will delete 1st 3rd lines. use warnings; use strict; my @array; open FH,data.txt; @array = FH; for my $i (0..$#array) { $array[$i] =~ s/^(\*\/tmp\/dst\/file(1|3)\*(\d){3}\*RW\*(\d){3,4})$/ /; #replace the lines you want to delete with (space) } my @result = grep(/[^\s]/,@array); #Take other lines in @result. close FH; open FH,data.txt; print FH @result; Hope it is useful. -Original Message- From: btna [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2008 9:21 PM To: beginners@perl.org Subject: How to replace one line in a text file with Perl? Hi all, I have a file that looks like: */tmp/dst/file1*234*RW*6790 */tmp/dst/file2*568*RW*908 */tmp/dst/file3*345*RW*746 */test/flm/file4*354*RW*987 */test/flm/file5*643*RW*645 I need to keep all of the lines with the exception of the one with file1 and file3 which have in common /tmp/dst. I need to preserve the line /tmp/dst/file2 plus the others that start with */test Any ideas on how to do this with perl? Thanks, BTNA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: How to replace one line in a text file with Perl?
Here is the entire code to accomplish your task. It will delete 1st 3rd lines. use warnings; use strict; my @array; open FH,data.txt; @array = FH; for my $i (0..$#array) { $array[$i] =~ s/^(\*\/tmp\/dst\/file(1|3)\*(\d){3}\*RW\*(\d){3,4})$/ /; #replace the lines you want to delete with i.e. (space) } my @result = grep(/[^\s]/,@array); #Take other lines in @result. close FH; open FH,data.txt; print FH @result; Hope it is useful. -Original Message- From: btna [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2008 9:21 PM To: beginners@perl.org Subject: How to replace one line in a text file with Perl? Hi all, I have a file that looks like: */tmp/dst/file1*234*RW*6790 */tmp/dst/file2*568*RW*908 */tmp/dst/file3*345*RW*746 */test/flm/file4*354*RW*987 */test/flm/file5*643*RW*645 I need to keep all of the lines with the exception of the one with file1 and file3 which have in common /tmp/dst. I need to preserve the line /tmp/dst/file2 plus the others that start with */test Any ideas on how to do this with perl? Thanks, BTNA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to replace one line in a text file with Perl?
[ Please do not top-post your replies. TIA ] sanket vaidya wrote: Here is the entire code to accomplish your task. It will delete 1st 3rd lines. use warnings; use strict; my @array; open FH,data.txt; You should *always* verify that the file opened correctly: open FH, '', 'data.txt' or die Cannot open 'data.txt' $!; @array = FH; my @array = FH; for my $i (0..$#array) { $array[$i] =~ s/^(\*\/tmp\/dst\/file(1|3)\*(\d){3}\*RW\*(\d){3,4})$/ /; If you have a lot of / characters in the pattern you should probably use a delimiter other than /. A character class is better for single character alternatives then using alternation and you don't use the captured strings so you don't need capturing parentheses. $array[$i] =~ s!^\*/tmp/dst/file[13]\*\d{3}\*RW\*\d{3,4}$! !; #replace the lines you want to delete with (space) } my @result = grep(/[^\s]/,@array); #Take other lines in @result. [^\s] could be written more simply as \S. Or you could just remove the elements from the original array: for my $i ( reverse 0 .. $#array ) { splice @array, $i, 1 if $array[$i] =~ m!^\*/tmp/dst/file[13]\*\d{3}\*RW\*\d{3,4}$!; } close FH; open FH,data.txt; You should *always* verify that the file opened correctly: open FH, '', 'data.txt' or die Cannot open 'data.txt' $!; print FH @result; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: question on lexical declaration and submodule
[EMAIL PROTECTED] wrote: Hi, I am doing some studies on sub modules and Lexical variables (my). With regards to diagram 1 below, what can I do so that the lexical $counter can count up to 4. Of course, one way of doing this is to change the lexical $counter into a global variable as seen in diagram 2 but I dont think this is a good idea as the sub-module will then have a mixture of both lexical (my) and global variables. So, are there any other ways of writing in diagram 1 so that the $counter can count up to 4? Thanks ## Diagram 1 lexical $counter t### use strict; my $anything = 0; while ($anything 5){ $anything +=1; testing_module ; } sub testing_module { my $counter = (); if ($counter 5){ $counter += 1; } } ### # Diagram 2 global $counter below ## use strict; my $anything = 0; my $counter = (); #global counter while ($anything 5){ $anything +=1; testing_module ; } sub testing_module { $counter = (); if ($counter 5){ $counter += 1; } } I'd reckon that a while/for loop would do just as well. sub testing_module { #You could assign counter to 0 here, but in a for loop not needed. for(my $counter;$counter 5; $counter++) { # Do things with $counter.. } # while($counter 5) { $counter++ } # this also would work. } --START NOTE-- I didn't include the first loop because I didn't see why it'd make a difference :P The counter was all you were asking about, so that's all I worried about. --END NOTE-- TMTOWTDI, bloo` -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reference to subroutine???
Hi I copied the code into a script so I could be sure it was the exactly the same source being used on version 5.8.8 and 5.10.0. I'm running an AMD Athlon64 x2 Ubuntu 7.10 but that is I think irrelevant. For those not familiar with vim line #2 turns off syntax colouring for this file only.Its called a modeline feature. -- Andrew in Edinburgh,Scotland On Wed, 26 Mar 2008, yitzle wrote: Um. No offense, but can you double check that the same exact code is being ran against both versions? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
system calls return code
I am really going crazy here. I have the following system call that I would like to run from perl: ls *.txt | xargs cat out if *.txt does not exist then I expect to get an exit code different from 0. So to test I do: use strict; my $f = file_which_does_not_exist; # method 1 print test 1\n; qx(ls $f | xargs cat); print $?,\n; #method 2 print test 2\n; system(ls $f | xargs cat); print $?,\n; Both calls return 0 instead of returning error as 'ls' fails. Help. How do I do this ? Would 'open' help ? C. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: system calls return code
This is because you send ls's output to a pipe, and the command on the right of the pipe get executed successfully. Try this test on shell: -bash-3.00$ ls |xargs cat ls: : No such file or directory -bash-3.00$ echo $? 0 -bash-3.00$ ls ls: : No such file or directory -bash-3.00$ echo $? 1 As you see, the first command always returns a 0. On Thu, Mar 27, 2008 at 6:50 PM, [EMAIL PROTECTED] wrote: I am really going crazy here. I have the following system call that I would like to run from perl: ls *.txt | xargs cat out if *.txt does not exist then I expect to get an exit code different from 0. So to test I do: use strict; my $f = file_which_does_not_exist; # method 1 print test 1\n; qx(ls $f | xargs cat); print $?,\n; #method 2 print test 2\n; system(ls $f | xargs cat); print $?,\n; Both calls return 0 instead of returning error as 'ls' fails. Help. How do I do this ? Would 'open' help ? C. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: What counts as a void context in Don't use grep in a void context?
On Wed, Mar 26, 2008 at 9:47 PM, Rob Dixon [EMAIL PROTECTED] wrote: Jay Savage wrote: If you want to see grep really shine, though, think about ways you might use it to avoid calling print for every element in the return list, e.g. print join \n, grep {$_ % 2 == 0} @list; I think that's very misleading. Why should I want to avoid calling print for each element? What you've written is the sort of thing for which Perl gets a bad name - it's less readable and has no obvious benefits over print $_\n foreach grep { $_ % 2 == 0 } @list; cmpthese(1000, { 'foreach' = sub { print $_\n for grep {$_ % 2 == 0} 0..1000; }, 'join' = sub { print join \n, grep {$_ % 2 == 0} 0..1000; }, }); Rate foreachjoin foreach 40.7/s ---20% join50.8/s 25% -- 25% performance gain strikes me as a pretty obvious benefit. YMMV, of course, depending on your data and memory performance, but in general, function calls are expensive, and and print moreso than most, because it requires a system call out to the OS. Calling a function like print on each iteration through a loop is rarely the most efficient way to do business. This doesn't really have anything to do with Perl; it's true in any language. Of course, efficiency, like beauty, is in the eye of the beholder. And that's why I was clear with OP, that he should do whatever made the most sense for him in his particular situation. TIMTOWTDI isn't what gives Perl a bad name; it's what makes it the wonderful, flexible tool that it is, and crates passionate groups of users like this one. (It also doesn't print a terminating \n) I think you'll agree there are several trivial fixes for this. 'print \n' jumps immediately to mind. Best, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: question on lexical declaration and submodule
- Original Message - From: Gunnar Hjalmarsson [EMAIL PROTECTED] To: beginners@perl.org Sent: Thursday, March 27, 2008 8:27 AM Subject: Re: question on lexical declaration and submodule ... but I dont think this is a good idea as the sub-module will then have a mixture of both lexical (my) and global variables. No, they are both lexical, but in different scopes. Thanks everyone for the help! In a large program, I guess there may be many programmers involved and each of these programmers are responsible to write their own sub rountine as required. Henceforth it will be very confusing and problematic if the programmers have to use variables from outside of their own sub-rountine. Henceforth to prevent such confusion it is best to declare their variables scope within their own sub-rountine. However, just like a counter, there are times when we need to keep the values of these variables so that in the next iteration such as in while function, I can add one to the counter whose values was not discarded in the previous iteration thus changing the value of the counter from 5 to 6... etc Therefore, if I wish to write a subroutine so that all its variables are scope within his subroutine and yet I want to retain the values of some of these variables for the next calling of this subroutine, I can write as follows but I just wonder is this the best way :- Also the script below produce the following warnings and so what must I do to get rid of this warning. The warning says Use of uninitialized value $counter in numeric lt () at C:/Documents and Settings/the solar system/Desktop/testing.pl line 16. 3 use strict; use warnings; my $anything = 0; my $test_variable = 0; while ($anything 5){ $anything +=1; $test_variable = testing_module($test_variable) ; } sub testing_module { my $counter = $_; if ($counter 5) { $counter += 1; } $_ = $counter; print Counter counting $counter\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reference to subroutine???
sanket vaidya wrote: Whereas the output on perl 5.6.1 is Hello!!1 Ummm, beg to differ #!/usr/bin/perl use strict; use warnings; sub hello; my $ref = \hello; {$ref}; sub hello { print hello!!; } [EMAIL PROTECTED]:~$ perl -l pbml.pl hello!! [EMAIL PROTECTED]:~$ perl -v This is perl, v5.6.1 built for i386-linux -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
$topIter-next()
Can some one pls tell me wts the meaning of $topIter-next() ? I know - is used for hash refs, but dont know when to use -( ) !!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: system calls return code
On 27 мар, 03:50, [EMAIL PROTECTED] (Ultra Star X) wrote: I am really going crazy here. I have the following system call that I would like to run from perl: ls *.txt | xargs cat out if *.txt does not exist then I expect to get an exit code different from 0. So to test I do: use strict; my $f = file_which_does_not_exist; # method 1 print test 1\n; qx(ls $f | xargs cat); print $?,\n; #method 2 print test 2\n; system(ls $f | xargs cat); print $?,\n; Both calls return 0 instead of returning error as 'ls' fails. Help. How do I do this ? Would 'open' help ? So Jeff already explained why. Now what can be done. One way: if you still want to run this command line correctly, try IPC::Run. It is a bit tricky to use first, but can safely run any pipelines. Another way: try using native Perl methods. opendir() and readdir() instead of ls, match file names with regex, and then read and append files, or run cat. /sandy http://myperlquiz.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: What counts as a void context in Don't use grep in a void context?
On Wed, Mar 26, 2008 at 9:47 PM, Rob Dixon [EMAIL PROTECTED] wrote: Jay Savage wrote: If you want to see grep really shine, though, think about ways you might use it to avoid calling print for every element in the return list, e.g. print join \n, grep {$_ % 2 == 0} @list; I think that's very misleading. Why should I want to avoid calling print for each element? What you've written is the sort of thing for which Perl gets a bad name - it's less readable and has no obvious benefits over print $_\n foreach grep { $_ % 2 == 0 } @list; I do not see how is print join \n, grep {$_ % 2 == 0} @list; any less readable than print $_\n foreach grep { $_ % 2 == 0 } @list; Would perhaps a pair of braces help? print join( \n, grep {$_ % 2 == 0} @list); I want to PRINT, JOINed by a newline, all even elements from @list instead of I want to print the item and a newline for each even element from @list. A big difference. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $topIter-next()
From: Subra [EMAIL PROTECTED] Can some one pls tell me wts the meaning of $topIter-next() ? I know - is used for hash refs, but dont know when to use -( ) !!! - is used for any references. And for method calls. In this case you are calling the next() method of the $topIter object. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
File Handling problem.
Hi, Current task requires me to combine a few files into a single file ( abc. txt ) where in each file has to be in a single page. I was able to create a combined file, but not able to ensure that each file resides in a page. Attempted a few things like 'format_lines_left' i.e $-. in vain... One of the possibilities left with me is to give sufficient \n between each file that way ensuring that each file read in resides in a page (which is something that I would like to do at the last). Is there any other mechanism that can be done to ensure that each file resides in a page.. say page break character or something... Any help would be appreciated... Thanks, -Wg -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Plotting widget in Perl?
I tried gtkdatabox. The C language version works fine on my machine, but the perl module doesn't compile :( I get this error: Databox.xs: In function `gtk_databox_data_type_get_type': Databox.xs:75: `GTK_DATABOX_NOT_DISPLAYED' undeclared (first use in this function) Databox.xs:75: (Each undeclared identifier is reported only once Databox.xs:75: for each function it appears in.) Databox.xs:75: initializer element is not constant Databox.xs:75: (near initialization for `values[0].value') Also, when I run perl Makefile,PL, I get this warning: Note (probably harmless): No library found for -lgtkdatabox Is this really harmless? I have built the c version of gtkdatabox separately and have set env vars CFLAGS and LD_LIBRARY_PATH accordingly. CFLAGS=-Igtkdatabox_install/include -Lgtkdatabox_install/lib LD_LIBRARY_PATH=gtkdatabox_install/lib:${LD_LIBRARY_PATH} Can you pount out what I am missing? Thanks On Thu, Mar 27, 2008 at 4:48 PM, zentara [EMAIL PROTECTED] wrote: On Thu, 27 Mar 2008 14:00:42 +0530, [EMAIL PROTECTED] (Gowtham M) wrote: Zentara, gtkdatabox looks good for me. Can you please mention which perl module in Gtk2::* should I use to use this from perl? Thanks! Google for Gtk2-Databox and you will find the links and discussion. The first link gives the location of muppet's alpha module http://asofyet.org/muppet/software/gtk2-perl/Gtk2-Databox-0.001.tar.gz The second link gtkdatabox version 3.0 xs problem says that it worked up until version 2.4.7 of gtkdatabox. Now the old versions are available at http://www.eudoxos.de/gtk/gtkdatabox/ I tried to learn some xs, to make the module up to date, but it's beyond my meager brain power. :-) ### Additionally, I came across the new Cairo based canvas, which has zoomable text now, so you can make zoomable graphs. It's called the Goo-Canvas. Check it out. To get the goocanvas-0.9 c library http://sourceforge.net/project/showfiles.php?group_id=173653 Compatible Perl module: http://search.cpan.org/~yewenbin/Goo-Canvas-0.04/http://search.cpan.org/%7Eyewenbin/Goo-Canvas-0.04/ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- Gowtham M
Re: What counts as a void context in Don't use grep in a void context?
Jay Savage wrote: On Wed, Mar 26, 2008 at 9:47 PM, Rob Dixon [EMAIL PROTECTED] wrote: Jay Savage wrote: If you want to see grep really shine, though, think about ways you might use it to avoid calling print for every element in the return list, e.g. print join \n, grep {$_ % 2 == 0} @list; I think that's very misleading. Why should I want to avoid calling print for each element? What you've written is the sort of thing for which Perl gets a bad name - it's less readable and has no obvious benefits over print $_\n foreach grep { $_ % 2 == 0 } @list; cmpthese(1000, { 'foreach' = sub { print $_\n for grep {$_ % 2 == 0} 0..1000; }, 'join' = sub { print join \n, grep {$_ % 2 == 0} 0..1000; }, }); Rate foreachjoin foreach 40.7/s ---20% join50.8/s 25% -- 25% performance gain strikes me as a pretty obvious benefit. YMMV, of course, depending on your data and memory performance, but in general, function calls are expensive, and and print moreso than most, because it requires a system call out to the OS. Calling a function like print on each iteration through a loop is rarely the most efficient way to do business. Yes I understood your intention, but efficiency isn't everything by any means. I believe very firmly that programs should be coded in the clearest and most obvious way possible, then tested and optimised if the performance is inadequate.The most natural way to print a list of data is simply to print each item, and to code it differently from that is to start on the road of efficiency at the cost of intelligibility. In any case, if someone offered me a way of making my program run in 20ms instead of 25ms I wouldn't be overly impressed, and certainly don't see it as a case of grep 'shining'. My guess is that optimising out print calls would be less, not more effective than with most subroutines: all it does is to append the passed-in data to the output buffer, and the system call is performed only when that buffer is filled. This doesn't really have anything to do with Perl; it's true in any language. Yes, but now you mention it I would be surprised to see this technique used in C: char buff[1] = \0; int n; char convert[10]; for (n = 0; n = 1000; n++) { sprintf(convert, %d\n, n); strcat(buff, convert); } fputs(buff, stdout); But perhaps I am wrong. Of course, efficiency, like beauty, is in the eye of the beholder. And that's why I was clear with OP, that he should do whatever made the most sense for him in his particular situation. TIMTOWTDI isn't what gives Perl a bad name; it's what makes it the wonderful, flexible tool that it is, and crates passionate groups of users like this one. My concern is that Perl has a reputation for appearing to be an unintelligible string of symbols, and I am wary of anything that even leans in that direction. (It also doesn't print a terminating \n) I think you'll agree there are several trivial fixes for this. 'print \n' jumps immediately to mind. Yes, of course. I was simply pointing out that they weren't equivalent. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reference to subroutine???
sanket vaidya wrote: Hi everyone, Kindly go through the code below. use strict; use warnings; sub hello; my $ref = \hello; {$ref}; sub hello { print hello!!; } The output on perl 5.10 is Hello!! Whereas the output on perl 5.6.1 is Hello!!1 Why two different outputs in two different versions? From where did 1 come from how to remove it? I suspect the 1 is output by something separate from Perl. Try writing the output to a file instead by rewriting your subroutine as: sub hello { open my $fh, '', 'test' or die $!; print $fh Hello!!\n; } also, you should call the subroutine by reference like this: my $ref = \hello; $ref-(); as the syntax you have chosen is prone to error. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: system calls return code
Thank you very much for explaining. I will try what Sandy suggested. I had tested at the command line already just as Jeff did. The confusion came from the fact that I had tried it in csh and in csh, doing the ls |xargs cat returned 1. Annoying. C. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: question on lexical declaration and submodule
[EMAIL PROTECTED] wrote: In a large program, I guess there may be many programmers involved and each of these programmers are responsible to write their own sub rountine as required. Henceforth it will be very confusing and problematic if the programmers have to use variables from outside of their own sub-rountine. No. A few variables outside the scope of various subs is a very natural thing, and the pure existence of such variables is neither confusing nor problematic. However, just like a counter, there are times when we need to keep the values of these variables so that in the next iteration such as in while function, I can add one to the counter whose values was not discarded in the previous iteration thus changing the value of the counter from 5 to 6... etc Note that you do _not_ keep the values of the sub's variables between the calls of the sub. You have (or mean to have...) the actual counter outside the sub in $test_variable. Therefore, if I wish to write a subroutine so that all its variables are scope within his subroutine and yet I want to retain the values of some of these variables for the next calling of this subroutine, I can write as follows but I just wonder is this the best way :- It certainly isn't. You are using the package variable $_ as the actual counter, which is the worst possible solution I can think of. ;-) Your _intention_ seems to be to use $test_variable as the actual counter, let testing_module() increment it by passing it to testing_module() each time you call the sub, and have the sub return the new value. use strict; use warnings; my $anything = 0; my $test_variable = 0; while ($anything 5){ $anything +=1; $test_variable = testing_module($test_variable) ; } sub testing_module { my $counter = $_; You probably mean: my $counter = shift; or my ($counter) = @_; if ($counter 5) { $counter += 1; } $_ = $counter; You do not want that line! print Counter counting $counter\n; return $counter; } -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File Handling problem.
Text files don't /have/ pages. The number of lines per page depends on the printer driver - the font size, margin size, etc. If you know the number of lines the print driver does per page, you can fill to that point with newlines based on the number of lines already outputted. Or you might be interested in a PostScript/PDF module from CPAN... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $topIter-next()
Just posted to clpmisc: Original Message Subject: Re: Operator -() Date: Thu, 27 Mar 2008 20:35:27 +0100 From: Gunnar Hjalmarsson [EMAIL PROTECTED] Newsgroups: comp.lang.perl.misc Subra wrote: [ exactly the same question as was posted to the beginners list a few minutes earlier ] DO NOT DO THAT !!! -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: What counts as a void context in Don't use grep in a void context?
On Thu, Mar 27, 2008 at 2:22 PM, Rob Dixon [EMAIL PROTECTED] wrote: Yes I understood your intention, but efficiency isn't everything by any means. I believe very firmly that programs should be coded in the clearest and most obvious way possible, then tested and optimised if the performance is inadequate. In general, I agree with you; but I maintain that clear and obvious are subject to interpretation. I also maintain that using grep to feed input to a for loop isn't obvious, whereas using grep to optimize out a loop is. There is nothing that grep does that can't be done in a loop, and we normally use grep when, for whatever reason, we want to avoid a loop. The most natural way to print a list of data is simply to print each item, and to code it differently from that is to start on the road of efficiency at the cost of intelligibility. Again, I don't entirely disagree. But this thread isn't about the most natural way to print lists. It's about grep. In any case, if someone offered me a way of making my program run in 20ms instead of 25ms I wouldn't be overly impressed, and certainly don't see it as a case of grep 'shining'. I think you missed my point. I may not have been clear. No, shaving a few ms off runtime isn't shining. But it's an *example* of the *type* of thing grep shines at. That is, taking loops and tunring them into blocks, and cutting out, in this case, 999 system calls. Are the savings anything to write home about? No, of course not. But the *idea* is fantastic, and in a more complicated situation often leads to not just faster execution, but saved programmer time, increased clarity, and simplified control structures. Again, it's not about a few prints in this particular made-up case. It's about the types of things grep really does well. My guess is that optimising out print calls would be less, not more effective than with most subroutines: all it does is to append the passed-in data to the output buffer, and the system call is performed only when that buffer is filled. Well, that depends entirely on what file handle you're printing to. If you're printing to STDOUT, as all these examples so far have, each newline--and therefore each pass though the loop that matches the condition--flushes the buffer. This doesn't really have anything to do with Perl; it's true in any language. Yes, but now you mention it I would be surprised to see this technique used in C: That's because C doesn't have grep. The extra variable assignments and sprintfs you need to make the equivalent C code eat up any potential gains. The situation of he two languages isn't at all comparable. TIMTOWTDI isn't what gives Perl a bad name; it's what makes it the wonderful, flexible tool that it is, and crates passionate groups of users like this one. My concern is that Perl has a reputation for appearing to be an unintelligible string of symbols, and I am wary of anything that even leans in that direction. Point well taken. But this is a thread about grep; and grep's raison d'etre is optimizing out loops. I don't think giving an example that shows grep cutting a loop is out of order. I certainly hope it wasn't unintelligible. It's also the little optimizations (like grep and map) that are built into the language that set Perl apart from the crowd. Best, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: What counts as a void context in Don't use grep in a void context?
Jay Savage wrote: [snip] In any case, if someone offered me a way of making my program run in 20ms instead of 25ms I wouldn't be overly impressed, and certainly don't see it as a case of grep 'shining'. I think you missed my point. I may not have been clear. No, shaving a few ms off runtime isn't shining. But it's an *example* of the *type* of thing grep shines at. That is, taking loops and tunring them into blocks, and cutting out, in this case, 999 system calls. Are the savings anything to write home about? No, of course not. But the *idea* is fantastic, and in a more complicated situation often leads to not just faster execution, but saved programmer time, increased clarity, and simplified control structures. Then as far as I can tell we concur! I thought your point was that print join \n, @list, ''; was superior to print $_\n foreach @list; whereas you meant something more like process_list(grep { $_ % 2 == 0 } @list); is superior to my @temp; foreach (@list) { push @temp, $_ if $_ % 2 == 0; } process_list(@temp); with which I would wholeheartedly agree :) I would say though that it is a shame that it was called grep. The utility is far from universally known, and the function doesn't provide a Global Regular Expression Print facility. I prefer to see it as a list mapping function: given an input list it returns an output list which is a function of the input. It can even be emulated with the map function. Again, it's not about a few prints in this particular made-up case. It's about the types of things grep really does well. My guess is that optimising out print calls would be less, not more effective than with most subroutines: all it does is to append the passed-in data to the output buffer, and the system call is performed only when that buffer is filled. Well, that depends entirely on what file handle you're printing to. If you're printing to STDOUT, as all these examples so far have, each newline--and therefore each pass though the loop that matches the condition--flushes the buffer. [snip] Now there I would disagree. Only STDERR is autoflushed: data sent to STDOUT is output only when the buffer fills, unless that is explicitly changed. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
how to repeat non-atom patterns
Given a multiple char patterns like :C9 that repeated, how to write a regex that repeat the patterns( which is non-atom ) 6 times. like in below WWPN:10:00:00:00:c9:2e:e8:90 I tried to define pattern to match my $match= qr/ {:[0-9a-e][0-9a-e]}{6} /; print matched if /$match/ ; but it unable to match. any suggestions. Thanks. ciwei -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Handling OLD files
Hi! I am looking for a way of moving files older than a date, I am need this in a script for moving/erase old files from a production machine Any tips where to read more about this i gratefull, i can't find any, (it is on a Windows server) and i would like to stick to PERL standard package (ActiveState) if it is possible -- Anders -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how to repeat non-atom patterns
ciwei wrote: Given a multiple char patterns like :C9 that repeated, how to write a regex that repeat the patterns( which is non-atom ) 6 times. like in below WWPN:10:00:00:00:c9:2e:e8:90 I tried to define pattern to match my $match= qr/ {:[0-9a-e][0-9a-e]}{6} /; print matched if /$match/ ; but it unable to match. any suggestions. You need to enclose the subpattern in parentheses. The string you show will match a regex like this: 'WWPN:10:00:00:00:c9:2e:e8:90' =~ /^WWPN(:[0-9a-f]{2}){8}$/; but because normal parentheses will cause unnecessary substring captures, it's better to use the non-capturing structure (?: ... ) so the regex becomes /^WWPN(?::[0-9a-f]{2}){8}$/ HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Handling OLD files
To get the date of a file: perldoc stat http://perldoc.perl.org/functions/stat.html For moving files: http://perldoc.perl.org/perlfaq5.html#How-can-I-reliably-rename-a-file%3f -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how to replace @ inside of { }
Gunnar Hjalmarsson wrote: Rob Dixon wrote: Richard Lee wrote: Gunnar Hjalmarsson wrote: C:\hometype test.pl use Data::Dumper; my %HoA = ( something = [ qw/val1 val2 val3 and so forth/ ], something2 = [ qw/vala valb valc and so forth/ ], something3 = [ qw/valZ valZ1 valZ2 so forth/ ], ); my %HoH; while ( DATA ) { /^(\S+)/; @{ $HoH{$1} }{ @{ $HoA{$1} } } = split; } print Dumper \%HoH; __DATA__ something3 one two three etc something2 two three and so on something one two three four five C:\homeperl test.pl $VAR1 = { 'something3' = { 'so' = 'three', 'valZ2' = 'two', 'forth' = 'etc', 'valZ1' = 'one', 'valZ' = 'something3' }, 'something2' = { 'so' = 'so', 'valb' = 'two', 'forth' = 'on', 'valc' = 'three', 'vala' = 'something2', 'and' = 'and' }, 'something' = { 'so' = 'four', 'forth' = 'five', 'val2' = 'one', 'val1' = 'something', 'val3' = 'two', 'and' = 'three' } }; C:\home Hey, this works perfectly, thanks. I just need to understand more on this @{ $HoH{$1} }{ @{ $HoA{$1} } } = split; This is really spinning my heads in all direction trying to see if I can truly understand them instead of just using it. Yes, it's not the most transparent line of code is it. The while loop is equivalent to: while ( DATA ) { my @values = split; my $key = $values[0]; my $labels = $HoA{$key}; my %map; @[EMAIL PROTECTED] = @values; $HoH{$key} = \%map; } And IMO it's better written like that. While I agree that a few temporary variables may increase the readability, I believe that the OP's difficulties to grasp the code has little to do with the coding style. Easier to read code does not replace the need in this case to understand hash slices and references. I agree. Let me get more fundametal of reference and get back to you guys. thanks!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how to repeat non-atom patterns
Rob Dixon wrote: ciwei wrote: Given a multiple char patterns like :C9 that repeated, how to write a regex that repeat the patterns( which is non-atom ) 6 times. like in below WWPN:10:00:00:00:c9:2e:e8:90 I tried to define pattern to match my $match= qr/ {:[0-9a-e][0-9a-e]}{6} /; print matched if /$match/ ; but it unable to match. any suggestions. You need to enclose the subpattern in parentheses. The string you show will match a regex like this: 'WWPN:10:00:00:00:c9:2e:e8:90' =~ /^WWPN(:[0-9a-f]{2}){8}$/; but because normal parentheses will cause unnecessary substring captures, it's better to use the non-capturing structure (?: ... ) so the regex becomes /^WWPN(?::[0-9a-f]{2}){8}$/ Hexadecimal is case insensitive so this will probably work better: /^WWPN(?i::[0-9a-f]{2}){8}$/ John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Using File::Find module???
Hi all I have some files stored in directory resumes1 (say the files are file1, file2 file3). When I run the following code use warnings; use strict; use File::Find; find (\del,D:/resumes1); sub del { print File name is $_\n ; } The output is: File name is .(i.e. a dot) File name is file1 File name is file2. File name is file3 Where did this . come from how to eliminate it? I use ActivePerl 5.10 on windows. Thanks in advance.
Re: Using File::Find module???
On 3/28/08, sanket vaidya [EMAIL PROTECTED] wrote: Where did this . come from how to eliminate it? '.' means the current directory. to remove it, add a line at the begin of the callback function: return if /^\.+$/; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/