Re: perl like tail -f
Harry Putnam wrote: Shawn H Corey shawnhco...@gmail.com writes: http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm Thanks that looks useful. Is there a reason why I should use that module as apposed to the kind of code offered in the faq about tail? (perldoc -q tail) as suggested by another poster (Jim G). I mean, I'm not experienced enough to know if there are things the module handles that a simple script like the one below does not. open(FILE,./named-pipe) or die Can't Open ./named-pipe: $!; while(FILE){ print; if(eof){ sleep 2; seek (FILE,0,1); } } It seems at least to survive repeated restarts of system logger. If I write my script based on this code... what I'd be adding would be code to get 1 or 2 rgx from the cmdline, then write the hits to various files. I'm told there is a systematic way to add my script to solaris bootup, and to restart it automatically if need be. But other than those are there other `gotchas' or whatever I'm liable to need the module for? In the general case, modules usually take care of special cases that you may not be aware of. That makes them the preferred method of solving a problem. In this case, the above code is a kludge. You can tell this because the program sleeps, rather than waiting on input. When a program does something to emulate what it really should be doing, it introduces code that may not work in all cases. -- 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: perl like tail -f
On Mon, 19 Oct 2009 23:30:30 -0500, Harry Putnam wrote: Shawn H Corey shawnhco...@gmail.com writes: http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm Thanks that looks useful. Is there a reason why I should use that module as apposed to the kind of code offered in the faq about tail? (perldoc -q tail) as suggested by another poster (Jim G). For code this brief, it's a toss-up. Using the module results in about the same amount of code; the advantage is that it's a bit more readable. In general, for tasks like this, you can expect a module to be more portable and featureful, and handle more special cases. You may never need any of its additional functionality, but if the day comes when, for instance, you want your code to be smarter about how fast it responds to changes in a file, the module would instantly become a better choice. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Want to write a script to note specific IP addresses.
Hi all, I want to write a script to note specific IP addresses by appending the corresponding location informations. For detail, I describe my issue as follows: Suppose I have two files, the first file is used to store the specific IP addresses which I want to note, and the second file is used to store the IP database along with the corresponding location informations. The first file has one IP address per line with dotted decimal format, e.g.: 0.125.125.125 4.19.79.28 4.36.124.150 ... The second file has four field per line delimited by CHARACTER TABULATION (U+0009). These four field are: StartIP, EndIP, Country, and Local, e.g.: StartIP EndIP Country Local 0.0.0.0 0.255.255.255 IANACZ88.NET 4.19.79.0 4.19.79.63 AmericanArmed Forces Radio/Television 4.36.124.1284.36.124.255AmericanTechnical Resource Connections Inc ... Based on the second file, I want to reformat the first file by appending the corresponding location informations for each IP address in it, i.e., for the above example, I want to obain the following result: 0.125.125.125#IANA CZ88.NET 4.19.79.28#American Armed Forces Radio/Television 4.36.124.150#American Technical Resource Connections ... Any hints on this issue will be highly appreciated. Thanks in advance. -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Filesize limit for Perl on UNIX
On Mon, Oct 19, 2009 at 9:12 AM, Shawn H Corey shawnhco...@gmail.com wrote: Taylor, Andrew (ASPIRE) wrote: Is there a 2GB filesize limit for perl? - we're running on verion 5.6. There is no file limit in Perl. There is no memory limit in Perl. Such limits are because of: * the hardware, * the OS, * the compiler that complied Perl And the options to the compiler at compile time. Type perl -V to see if your version of perl has large file support. For example, my install of perl under Ubuntu shows this: Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API If your perl was not compiled with large file support, then one workaround would be to wrap the perl script in a bash script. Assuming the perl script writes to stdout, you could do something like this: for i in $list_of_files ; do perl_script $i done large.outfile Good luck and let us know how things go. Regards, - Robert -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Want to write a script to note specific IP addresses.
Hongyi Zhao wrote: Hi all, I want to write a script to note specific IP addresses by appending the corresponding location informations. For detail, I describe my issue as follows: Suppose I have two files, the first file is used to store the specific IP addresses which I want to note, and the second file is used to store the IP database along with the corresponding location informations. The first file has one IP address per line with dotted decimal format, e.g.: 0.125.125.125 4.19.79.28 4.36.124.150 ... The second file has four field per line delimited by CHARACTER TABULATION (U+0009). These four field are: StartIP, EndIP, Country, and Local, e.g.: StartIP EndIP Country Local 0.0.0.0 0.255.255.255 IANACZ88.NET 4.19.79.0 4.19.79.63 AmericanArmed Forces Radio/Television 4.36.124.128 4.36.124.255AmericanTechnical Resource Connections Inc ... Based on the second file, I want to reformat the first file by appending the corresponding location informations for each IP address in it, i.e., for the above example, I want to obain the following result: 0.125.125.125#IANA CZ88.NET 4.19.79.28#American Armed Forces Radio/Television 4.36.124.150#American Technical Resource Connections ... Any hints on this issue will be highly appreciated. Thanks in advance. Is the IP address you're interested in the StartIP, the EndIP, or both? -- 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: How to set a proxy server.
Dear list: I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups = unpack a$n x (length( $string ) /$n ), $string; print @groups; when I run it, the screen displays the $string value, like 1234567890abcdefghijABCDEFGHIJK but I want the groups and the group size is 2 . Is it wrong that this phrase (length($string)/$n ? Thanks in advance !!
How can I split a string into chunks of size n bytes?
Dear list: I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups = unpack a$n x (length( $string ) /$n ), $string; print @groups; when I run it, the screen displays the $string value, like 1234567890abcdefghijABCDEFGHIJK but I want the groups and the group size is 2 . Is it wrong that this phrase (length($string)/$n ? Thanks in advance !!
Re: How can I split a string into chunks of size n bytes?
Majian wrote: Dear list: I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl use strict; use warnings; my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups = unpack a$n x (length( $string ) /$n ), $string; print @groups; print @groups\n; # or use Data::Dumper; print Dumper \...@groups; when I run it, the screen displays the $string value, like 1234567890abcdefghijABCDEFGHIJK but I want the groups and the group size is 2 . Is it wrong that this phrase (length($string)/$n ? Thanks in advance !! -- 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: How to set a proxy server.
At 9:35 AM +0800 10/21/09, Majian wrote: Dear list: I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups = unpack a$n x (length( $string ) /$n ), $string; print @groups; when I run it, the screen displays the $string value, like 1234567890abcdefghijABCDEFGHIJK but I want the groups and the group size is 2 . Is it wrong that this phrase (length($string)/$n ? ' The line print @groups; will print the elements of @groups with no spaces or other characters separating the elements, so you are actually getting the expected output. To actually see the elements, use join to add a separator: print join(',',@groups),\n; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to set a proxy server.
Majian wrote: Dear list: Hello, I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups = unpack a$n x (length( $string ) /$n ), $string; Or more simply as: my @groups = unpack (a$n)*, $string; Or as: my @groups = $string =~ /.{$n}/sg; print @groups; when I run it, the screen displays the $string value, like 1234567890abcdefghijABCDEFGHIJK but I want the groups and the group size is 2 . print @groups; Is the same as saying: print join '', @groups; Each $n byte string is printed next to each other because the default value of the $, variable is ''. You could print it like this: print @groups; Which is the same as saying: print join ' ', @groups; Because the default value of the $ variable is ' '. John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/