Re: Script for auto conf
Thanks to all !!! You are right Brandon .. Sorry about my post. I started searching how to compare 2 files like this: use strict; use warnings; my $f1 = 'E:\upload\new\2.txt'; my $f2 = 'E:\upload\new\a.txt'; my $outfile = 'E:\upload\new\1.txt'; my %results = (); open FILE1, $f1 or die Could not open file: $! \n; while(my $line = FILE1){ $results{$line}=1; } close(FILE1); open FILE2, $f2 or die Could not open file: $! \n; while(my $line =FILE2) { $results{$line}++; } close(FILE2); open (OUTFILE, $outfile) or die Cannot open $outfile for writing \n; foreach my $line (keys %results) { print OUTFILE $line if $results{$line} == 1; } close OUTFILE; from https://www.daniweb.com/software-development/perl/threads/79071/compare-two-text-file then I modify to print from which file is the line ... now ... how do I test each value ... ?? I will try Andrew approach !! Thanks in advance 2014-12-30 5:40 GMT-03:00 Andrew Solomon and...@geekuni.com: Hi Alan This is the module I'd use for it: https://metacpan.org/pod/Config::Tiny The simplest approach would be to: * read the destination config file (some_file.conf) into $Config_current * read the config in-tray (param.txt) into $Config_new * add the in-tray parameters to $Config_current foreach my $key (keys($Config_new-{_}) { $Config_current-{_}-{$key} = $Config_new-{$key}; } * write $Config_current back into some_file.conf Hope that helps! Andrew On Tue, Dec 30, 2014 at 3:47 AM, Alan Glait agl...@gmail.com wrote: Hi ! I have the Idea to make a perl script (better than in bash) to make some configuration on linux. I think to have some files like param.txt with some lines like: param_one = ZZZ XX VV param_two = Z param_three = X so need to check if param_one is in some_file.conf and if it is there test the value .. if it is not .. add to some_file.conf ... I think it should be easy ... right ?? Thanks for any help .. ;) -- Andrew Solomon Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
Script for auto conf
Hi ! I have the Idea to make a perl script (better than in bash) to make some configuration on linux. I think to have some files like param.txt with some lines like: param_one = ZZZ XX VV param_two = Z param_three = X so need to check if param_one is in some_file.conf and if it is there test the value .. if it is not .. add to some_file.conf ... I think it should be easy ... right ?? Thanks for any help .. ;)
Re: a condition
Hello Li, The `notall` function of `List::MoreUtils` (https://metacpan.org/module/List::MoreUtils) can be made use of along with Perl's `grep` function: #!/usr/bin/env perl use strict; use warnings; use List::MoreUtils qw( notall ); my @array = ( 'AB AB AB AB AB', 'AB AC AB AB AB', 'AB AC AD AB AB', ); @array = grep { my @elems = split /\s/; # Split into elements on whitespace notall { $elems[0] eq $_ } @elems; # Check if every element is equal to the first element } @array; Without using `List::MoreUtils`: @array = grep { my $select = 0; for ( my @elems = split /\s/ ) { if ( $elems[0] ne $_ ) { $select = 1; } } $select; } @array; Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: subroutine
Hello Chris, Can this subroutine be better written? I am getting the following erros: Use of uninitialized value $y in subtraction (-) at form.pl line 52. Use of uninitialized value $y in addition (+) at form.pl line 52. sub avg_az { my($x, $y) = shift(@_); In the above line, `shift` will return just the first element from the @_ array. $y will therefore be undefined. The line should be rewritten as: my ( $x, $y ) = @_; Relevant documentation: `perldoc -f shift` or http://perldoc.perl.org/functions/shift.html Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: In search of a list class with unusual accessors
Hello David, I am looking for a class that stores zero or more items (e.g. a list) and that provides accessors that accept and return scalar, list, and/or array references depending upon context and object content (similar to CGI.pm, but not exactly the same): The `wantarray` function can be made use of. It helps in determining the context. #!/usr/bin/perl use strict; use warnings; package WishfulThinkingListClass; sub new { return bless [], __PACKAGE__; } sub set { my ( $self, @values ) = @_; @$self = @values; return; } sub get { my $self = shift; if (wantarray) { return @$self; } else { if ( @$self 1 ) { return [@$self]; } return $self-[0]; } } package main; use Test::More 'tests' = 4; my $obj = WishfulThinkingListClass-new(); $obj-set('foo'); my $value = $obj-get(); is( $value, 'foo', '$value = foo' ); my @values = $obj-get(); ok( eq_array( \@values, ['foo'] ), '@values = (foo)' ); $obj-set( 'bar', 'baz' ); $value = $obj-get(); ok( eq_array( $value, [ 'bar', 'baz' ] ), '$value = [ bar, baz ]' ); @values = $obj-get(); ok( eq_array( \@values, [ 'bar', 'baz' ] ), '@values = ( bar, baz )' ); __END__ Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: GUI Library
On 09/28/11 16:29, Francisco Rivas wrote: Hello, I am planning to write a very small stand alone application to write some file and I would like to know which is the best/recommended GUI library for Perl. I have read about wxPerl, GTK2, PerlQT4 and even Tk, but I would like to know what people recommend from their experience. Thank you very very much in advance for your time and comments. Have a very nice day. Hello, Francisco, Padre, the Perl IDE, uses wxPerl and is under active development. The latest Wx was released on 06th of June 2011. I recommend it. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Good resources on CGI programming with Perl
Hello Parag, Could some please suggest any good online resources on learning CGI programming with Perl Curtis Ovid Poe's CGI course is popular: http://web.archive.org/web/20070709150107/http://users.easystreet.com/ovid/cgi_course/ Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: GUI Module
Hello Emeka, I am thinking of check out GUI ... so I would need to know where to start off. Is there a GUI module with Perl? Or am I going to pull one from web? Check out WxPerl. Padre, the Perl IDE, uses WxPerl for its GUI. You will have to install `Wx` from CPAN. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: searching the array
Hello Anant, I want to search whether a scalar '$a' contains any one of value of an array '@arr'. How it may be done? If you are using perl v5.010 or later, you can use the smart match operator (~~): use 5.010; use strict; use warnings; my @array = qw( foo bar quux ); my $item = 'bar'; if ( $item ~~ @array ) { say Item found: $item; } However, if you have an older perl, you can use List::Util's (which is a core module since perl v5.7.3) `first` subroutine: use strict; use warnings; use List::Util qw( first ); my @array = qw( foo bar quux ); my $item = 'bar'; if ( first { $item eq $_ } @array ) { print Item found: $item\n; } Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: searching the array
Hello Anant, Please read: perldoc -q 'certain element is contained in a list or array' or http://bit.ly/o9uKat Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: loop break condition
Hello Anant, i want to input some numbers via stdin in while loop.And loop should be broken if any nonnumeric character is entered.So how it can be checked. . my @ln; my $i=0; printGive line numbers you want to put into array.\n; while(1){ $ln[$i]=stdin; chomp $ln[$i]; if($ln[$i] =~ /\D/){ printIts not numeric value.\n; $i--; last; } $i++; } . In the above program, `$i` is mostly useless. The length of the array can easily be found out by using `scalar @ln`; Perl's `push` function can be used for pushing values into the array. There is no need for an index. The program can be rewritten as: use strict; use warnings; my @numbers; print Enter numbers:\n; while (1) { chomp( my $number = STDIN ); if ( $number =~ /\D/ ) { print $number is not a numeric value.\n; last; } else { push @numbers, $number; } } One more query:- HOW TO REMOVE ANY ELEMENT FROM AN ARRAY. I mean if i have allocated till arr[5]. Now I want to remove the value arr[4] and arr[5]. So how it can be done so that $#arr would tell 3. You can use the `splice` function (read: `perldoc -f splice`) for this: splice @array, 4, 2; Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: loop break condition
Hello Shlomi, It's a good idea to always use last LABEL; instead of last; (as well as next LABEL; etc. in case more loops are added in between. ⋮ http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-labels Now I understand why it is always good to label loops that use `last`, `next` or `redo`. Thank you. :-) Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Useless use of private variable
Hello Ron, for($i; $i $n; $i++) When Perl evaluates the initialiser of the for loop, it just sees a `$i`. There are no effects for such a statement. Hence the warning. For getting more details about warnings, you can use the diagnostics pragma. (See `perldoc diagnostics`) Since you have already initialised $i to 0 (my $i = 0;), you could omit the initialiser of the for loop: for ( ; $i $n; $i++ ) Otherwise, as is normal, you can use the for loop's initialiser section to declare and then initialise $i to 0: for ( my $i = 0; $i $n; $i++ ) Your program can be rewritten as: print join ', ', 0 .. 7; Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Spidering
Hello, Hi everyone i am a beginer for Perl can you give me a psedocode and a sample code for a spider program.It will be helpful in understanding web interfaces.Thank you Check out WWW::Mechanize - http://search.cpan.org/perldoc?WWW::Mechanize The SYNOPSIS section will help you get started. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl's -M
Hi Feng, What's the meaning of Perl's -M operator? `-M` is a command switch. It is used to load a module and is equivalent to `use`-ing a module within the script. `-M` is different from `-m` in that the former executes `import` function of the module whereas the latter does not import any function except for the ones that have been explicitly listed with the command switch. which perldoc document is it get descripted in? Command switches are documented in `perlrun`. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: very starting help
Hello Anant, #!/usr/bin/perl is a *shebang* and is useful only in unix-like systems where it refers to the location of the interpreter. Under other systems the interpreter ignores this line as a comment. Shebang lines are useful to execute a script directly without having to specify the interpreter. Consider a script named main.pl which can be executed under unix-like systems as: perl main.pl or ./main.pl # system checks the shebang line for the interpreter to use For more information: http://en.wikipedia.org/wiki/Shebang_(Unix) Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Using $variable outside a foreach loop
Hello, foreach my $name (split (/, */, $names)) { Here, the scope of $name is limited to the foreach loop and not outside it. So, you will have to declare the variable again for use outside the loop. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: instal
On Monday 23 May 2011 09:23:35 Gang Cheng wrote: hi, I downloaded a perl but I can't instal it said my cpu don't surport this instal packet, my cpu is i5 with win7 os. how can I instal thank you. Hello, Which installation package did you try to install? You may try installing Strawberry Perl - http://strawberryperl.com/ Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl interview questions
Hello Jyoti, Please give me any link or any tutorial which will be helpful for preparation of PERL interview. Please read `perldoc perlfaq` (http://perldoc.perl.org/perlfaq.html). It is a collection of frequently asked questions which will certainly help you at an interview. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Dynamic replacement of the variable
Hello friends in the list, I did not want to reply, however, I have now been forced to reply. On 04/19/2011 05:26 PM, Jenda Krynicky wrote: Try Alcoholics Anonymous. This is not a post-traumatic mutual support group, this is a technical mailing list! If you can't handle a terse and to the point reply, you should change the profession and try to find nicer talking people in the humanities. The catch is that the emails will start with a greeting, continue with a compliment, use soft words ... and be empty, empty, empty. A 'Technical mailing-list' does not mean that the posts are posted/read by bots! Posts are posted/read by humans who have feelings and can get hurt. Statements like the ones quoted above do more harm than good. On 04/19/2011 05:26 PM, Jenda Krynicky wrote: As it is, those people should not be doing anything technical in the first place. The compiler will not start with a greeting and compliment their hairstyle either. No one is born a programmer; nor does anyone become a perfectionist overnight. Perl might even be some people's first attempt at learning a programming language. Quoting Learning Perl: … we're pleased that we've had many reports of people successfully picking up [Learning Perl] and grasping Perl as their first programming language …. This list is focused on such people. Beginners! We should encourage them and grow the community rather than be rude and let them search for 'green pastures'. For a language to survive, there has to be a thriving community of users. A mailing-list that welcomes new users and assists them is what I call a 'healthy mailing-list'. Such lists will increase user participation and eventually lead to the list being 'useful' to the posters as well as to the community. Flaming is __HARM__ done to the community. No one enjoys it. It is the best way to be destructive! One of my personal experiences: I once posted an answer here (which happened to be wrong) and I had included a sentence: Hope it is clear now. at the bottom of my message. However, a public reply that I got included (other than some useful corrections), a reply to the above sentence: No, nothing is clear from those answers. which was an avoidable, unnecessary quote. If the replier had appended a smiley :-) to the sentence, I would have certainly considered it humorous. If you are into pun, or play with words, consider using smileys as this list is followed by people from different nations, backgrounds, cultures and native languages. Most (if not all) are able to understand smileys. Not everyone's first language is English. It is better not to be ambiguous. In my humble opinion, for rules like quoting e-mails, using/not using line numbers, indenting, et cetera, a wiki page should be created which could then be pointed to when needed. If anyone is interested, please let me know so that we can build one. As an aside: I am sorry if any uneasiness was caused by my statements. This was inevitable. A proverb for the thoughtful: Prevention is better than cure. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl source code beautifier
Hello Bruno, I'm looking for a command line tool for Perl source code beautifier. Have a look at Perl::Tidy. It also includes a script named `perltidy` which can be run from the command-line. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: WMI
Hello Mike, Sure enough the module is gone and I can't find it in ActiveState ppm. It is not found in CPAN either. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: format output from system command
Hello Marc, What about writing it like this: open ('FILEOUT', '', 'cmdout') ||die cant open cmdout: $! \n; Is that O.K.? You are still using a bareword filehandle. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help using cgi
Hello Prashant, Thanx alan.. You are welcome. please suggest the steps to configure my web server. It depends on which web server you are using. You will probably find a cgi-bin directory (in Debian/Ubuntu, Apache's cgi-bin is at /usr/lib/cgi-bin/) which is configured to serve CGI scripts. Else, you will have to configure the web server to allow another directory to serve CGI scripts and copy the script there. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help using cgi
Hello Prashant, Yesterday i tried a Hello world program in perl using cgi script on a windows platform. Check out the CGI module on CPAN. 3. opened it with my web browser. but now instead of giving the output it just shows the original source code. please help! regards You have to configure your web server to execute CGI scripts. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
Hello Mariano, I realize that there may be a number of ways to do what I need to do (most of them better, I bet), and I'd love to learn about them. But now I'm mostly curious about why grep// cannot see words with parentheses in either (or both lists). I suspect the trick may be somehow escaping the (), but I tried a number of ways of doing that to no avail. Characters having specific meanings in regular expressions have to be escaped. You could either use the quotemeta function or enclose the regular expression within \Q and \E: grep /^ \Q $array1[$ctr1] \E $/x, @array2; Some comments about the code: #!usr/bin/perl For increased portability, use the shebang #!/usr/bin/env perl use warnings; Also use strict;. $path1 =STDIN; chomp $path1; Declare variables before they are used. open (INPUT1, $path1); open (INPUT2, $path2); open (INPUT3, $path3); Try to use the 3-argument version of open. my ($array1,$array2,$in1and2); Avoid naming scalars and arrays (or hashes) the same. An alternative solution: =pod code #!/usr/bin/env perl use strict; use warnings; use File::Slurp qw( slurp ); use List::MoreUtils qw( any each_array ); my %path; print Enter path to list 1: ; chomp( $path{'list_1'} = STDIN ); print Enter path to list 2: ; chomp( $path{'list_2'} = STDIN ); chomp( my @list_1 = slurp( $path{'list_1'} ) ); chomp( my @list_2 = slurp( $path{'list_2'} ) ); my @common_list; for my $word (@list_1) { any { $_ eq $word } @list_2 and push @common_list, $_; } printf in 1 = %d in 2 = %d in 1 and 2 = %d\n, scalar @list_1, scalar @list_2, scalar @common_list; =cut Any help will be greatly appreciated! And as usual, if you ever have questions about molecular biology and genetics, fire away - I'd love to pay the favor back. Thank you. Hope this message helps. :-) Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
Hello Mariano, use List::MoreUtils qw( any each_array ); I was experimenting and forgot to take off `each_array` from the import list. `each_array` is not used in the alternative solution and is hence not required. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Select equivalent in perl
Hello Balaji, I have been using shell script for my admin work and recently decided to use perl fo all my automation. So proud I did that. Nice to know that you have decided to use Perl. Quick question: I have been using Select function in shell to present menu to users. Do we have a select equivalent in perl? Or if I have a list of names in an array what is the best way to present them in a menu and prompt the user to select one from the list? The task is very easy to implement using IO::Prompt: =pod code use IO::Prompt; my @names = qw( foo bar baz qux ); my $selected_name = prompt 'Please select one name: ', -menu = \@names; print Selected name: $selected_name\n; =cut code Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: assigning hash to a scalar
Hi Sunita, $var = %input; … Output : 3/8-- What does this output mean ? You are evaluating a hash in a scalar context. Quoting perldata: If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash. This is pretty much useful only to find out whether Perl's internal hashing algorithm is performing poorly on your data set. For example, you stick 10,000 things in a hash, but evaluating %HASH in scalar context reveals 1/16, which means only one out of sixteen buckets has been touched, and presumably contains all 10,000 of your items. This isn't supposed to happen. If a tied hash is evaluated in scalar context, a fatal error will result, since this bucket usage information is currently not available for tied hashes. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: assigning hash to a scalar
Hi Sunita, Thanks Alan . I had got this piece of info from google but I do not understand clearly what it wants to define . It would be good , if you can explain bit more . You are welcome. The numbers are dependent on the internal hashing algorithm used by perl of which I am unaware of. Hopefully the article: How Hashes Really Work can help you understand better. - http://www.perl.com/pub/2002/10/01/hashes.html Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help with array elements
Hello Ashwin, I have an array which has few elements like '1,2,3,4,2,3,1,2,1,1,1,4,6,7' i need to know how many times each element has occurred in the same array. for example 1-5 times 2-3 times... could some one throw some light on how i can do this. Store the array contents into a hash, updating the count each time: =pod code #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @elements = ( 1, 2, 3, 4, 2, 3, 1, 2, 1, 1, 1, 4, 6, 7, ); my %count; $count{$_}++ for @elements; print Dumper \%count; =cut Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Printing Bash and Kernel Version numbers using Perl
Hello Parag, perl -MConfig -le 'print $Config{perlpath}:$^V\n$ENV{SHELL}: Bash_or_Shell_Version\n/kernel/$^O:Kernel_Version' =pod code perl -MConfig -e 'print $Config{perlpath}:$^V\n$ENV{SHELL}: . qx{ bash --version | head -1 } . /kernel/$^O: . qx{ uname -r }' =cut Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Printing Bash and Kernel Version numbers using Perl
Hello Parag, Vern Nice. Completely impressed. But I thought Perl might have some internal variable at least for Kernel version. But anyways this work for me too. `Config` module's `config_re` function can be used: =pod code use Config 'config_re'; my ($os_version) = config_re('^osvers'); $os_version =~ s/^ osvers= | '//gx; print $os_version; =cut Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: understanding the ||= operator
Hi, 12$sheet - {MaxRow} ||= $sheet - {MinRow}; Line 12 can be written as: $sheet-{'MaxRow'} = $sheet-{'MaxRow'} || $sheet-{'MinRow'}; For example: $variable_1 ||= $variable_2 is equivalent to $variable_1 = $variable_1 || $variable_2. The same applies to: **=+=*==== -=/=|==||= .=%=^= //= x= Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: understanding the ||= operator
Hi, then that I don't understand is the program logic :-( It is a logical OR. Quoting `perldoc perlop`: C-style Logical Or Binary || performs a short-circuit logical OR operation. That is, if the left operand is true, the right operand is not even evaluated. Scalar or list context propagates down to the right operand if it is evaluated. $sheet-{'MaxRow'} = $sheet-{'MaxRow'} || $sheet-{'MinRow'}; Equivalent to: unless ( $sheet-{'MaxRow'} ) { $sheet-{'MaxRow'} = $sheet-{'MinRow'}; } In English: If $sheet-{'MaxRow'} has a value that evaluates to false, make $sheet-{'MaxRow'} equal to $sheet-{'MinRow'}. Though I have left the else clause, By the way, it is not recommended to use `unless` for anything complex as it can get in the way of ordinary thinking process. Use `if` and `!`. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to convert EURO Symbol € character to Hex
Hi Khabza, now my problem is I cant type € symbol on my editor Textpad it return funny characters like € Textpad probably allows you to set the encoding of the file to UTF-8, I think. Set it to UTF-8 so that you will be able to type in the € symbol. use utf8; # use whenever source code includes UTF-8 if ( $euros eq 'BC€01' ) { # ... } __OR__ if ( $euros eq 'BC' . chr(0x20AC) . '01' ) { # 0x20AC is the hexadecimal value of € # ... } Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to convert EURO Symbol € character to Hex
Hi Khabza, I have end up using ASCII Encoding instant of UTF-8 it does not find any thing if I use 'BC' . chr(0x20AC) . '01' then i change to 'BC' . chr(0x80) . '01' The following code works if ( $euros eq 'BC' . chr(0x80) . '01' ) { # 0x20AC is the hexadecimal value of € # ... } The Euro symbol is attributed 0x80 in Windows-1252 encoding and not in ASCII. Euro symbol was created much later than the latest ASCII revision. which I am not sure if my code will work to all version of windows. Is there a different between using ASCII or UTF-8? UTF-8 encoding is a super-set of ASCII encoding. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Function to print Object properties
Hi Parag, On Friday 07 January 2011 07:55:38 Parag Kalra wrote: Anyways I want to know is there any function or a way that would reveal all the properties of the object. Introspect the symbol table hash (stash): use strict; use warnings; use Data::Dumper; use Foo::Bar; my $fob = Foo::Bar-new(); my $package = ref $fob; { no strict 'refs'; print Dumper \%{${package}::}; } Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: I can't understand this function that what are parameters ,can you help me?
Hi Yang, sub ok ($;$) { } and sub is ($$;$) { } Those are subroutines with prototypes. `sub NAME(PROTO)` `sub ok ($;$)` Requires one mandatory argument and an optional one. They are separated by a semi-colon in the prototype definition. The arguments will be considered in scalar context (due to the `$`). `sub is ($$;$)` Requires two mandatory arguments and an optional one. All of them will be considered in scalar context. See `perldoc perlsub` for more information. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: need to get parent script name inside child script
Hi Sunita, How can I print parent test script name inside this postrun ? `(caller)[1]` will return the the parent script's filename inside the postrun script. See `perldoc -f caller` for more information. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: 1st line of perl script
Hi Sunita, Perl script works without the first line ( perl Interpreter : #! /usr/bin/perl) . What is the real use of this line ? This line does not through any error on Windows where , this path does not exist . It is a shebang line which is only useful in Unix-like operating systems. In such systems, the shebang line should start in the first column of the first line. When such a script with its executable bit set is run by itself, the operating systems checks for the shebang line to see which interpreter should be used for executing the script. However, in Windows (and other non-Unix-like operating systems), the shebang is usually considered a comment and skipped. Instead of the shebang line, such systems depend on file extension associations or explicit invocation of the script using the interpreter. For more details, see: http://en.wikipedia.org/wiki/Shebang_(Unix) Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Linux Uptime
Matt wrote: I have a perl script but I want to exit it if the uptime on the server is less then say an hour. Any idea how I would get uptime with perl? Hi, You could use the distribution: Unix::Uptime (http://search.cpan.org/perldoc?Unix::Uptime) Example: use strict; use warnings; use Unix::Uptime; my $uptime_hours = Unix::Uptime-uptime() / 3600; if ( $uptime_hours 1 ) { exit(127); } Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Directory Size
On Thursday 28 Oct 2010 06:30:01 Mike Blezien wrote: Hello, I've been out of the programming game for a while and recently got back into some small programming projects. Just need to figure out if there is a Perl function to determine the total size of a folder and files? Meaning once we open/read a directory is to calculate the total, in MB's, the size of the files in a particular directory folder. Thanks, Mike(mickalo)Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Hi Mike, You could make use of File::Find's find function along with stat. =pod Example use strict; use warnings; use File::Find; my $size; my $directory = '/path/to/some/directory'; sub determine_size { if ( -f $File::Find::name ) { $size += ( stat $File::Find::name )[7]; } } find( \determine_size, $directory ); $size /= 1024 * 1024; print Total size: $size MB\n; =cut Relevant documents to read: `perldoc File::Find` - http://perldoc.perl.org/File/Find.html `perldoc -f stat` - http://perldoc.perl.org/functions/stat.html Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl Threads
On Sunday 10 Oct 2010 20:38:32 chillidba wrote: Can some body please point me to Perl Thread tutorials.(some pdf with examples) Hi, perldoc perlthrtut http://perldoc.perl.org/perlthrtut.html Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl Threads
On Sunday 10 Oct 2010 20:38:32 chillidba wrote: Can some body please point me to Perl Thread tutorials.(some pdf with examples) Hi, perldoc perlthrtut http://perldoc.perl.org/perlthrtut.html Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl
On 4 October 2010 09:49, sheikh numan iqbal numan1...@gmail.com wrote: i want to login and need help on perl... Hi Numan, Please let us know where you need help with. Consider expanding the question. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Callbacks
Hi I am a newbie to Perl , I was reading through one of the beginner level books on perl. I did not understand the concept of Callbacks and i have the following questions on it: 1. What are they ? 2. Why do we need them ? 3. What useful purpose do they achieve ? I was reading the following code to understand it but could not comprehend. *Code:* #!/usr/bin/perl use warnings; use strict; use File::Find; find ( \callback, /); sub callback { print $File::Find::name, \n; } *End Of Code:* Thanks Jatin Hi Jatin, A callback is a reference to a subroutine. This reference when passed around, allows other code to invoke it. File::Find's find() method accepts a subroutine reference as the first argument and a path in the filesystem as the second argument. find() traverses recursively in '/' and calls your code reference (callback()) for each file/directory it finds. Thus, your subroutine is able to get each item in the path as soon as they are encountered by File::Find's find(). If find() was not implemented to handle callbacks, the possible way to return encountered file/directory names will be as an array or hash of file/directory names after it has traversed and exhausted all possible file/directory names within the path. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: parsing csv
On 2 July 2010 15:56, Sharan Basappa sharan.basa...@gmail.com wrote: Hi Jason, Does CSV module come prebuilt so that I can avoid installing. I dont know SQL but my requirements are very modest. Extract lines and get filed and reformat them to another type. Regads, Sharan Hi Sharan, DBD::CSV is not in core. You can check it yourself by using the `corelist` command-line frontend to Module::Corelist. For example: alanhag...@love:~$ corelist DBD::CSV DBD::CSV was not in CORE (or so I think) By the way, why do you resist installing modules from CPAN? Regards, Alan. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question abt array
On 30 June 2010 10:31, Chaitanya Yanamadala dr.virus.in...@gmail.com wrote: Hai i am in a situation like i have a scalar $value = 5 now i need to create an array with the number i mean $value how can i do it?? regards Chaitanya Hi Chaitanya, I am not sure if I understood your question well or not. To create an array with the value, either push or unshift the value into an existing array, or assign the value as an array item. #!/usr/bin/env perl use warnings; use strict; my $value = 5; my @values; # different cases: # push @values, $value; # unshift @values, $value; # @values = ($value); __END__ Please refer `perldoc -f push` and `perldoc -f unshift`. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: about split and \d or . (.)
On 11 April 2010 21:10, Harry Putnam rea...@newsguy.com wrote: Why is it that the first two splits do not produce any elements? #!/usr/local/bin/perl use strict; use warnings; my $var = 100421; my @elems1 = split(/\d/,$var); my @elems2 = split(/./,$var); my @elems3 = split(//,$var); if (@elems1){ print elems1 has these elements:\n; for(@elems1){ print $_\n; } print--- --- ---=--- --- ---\n; } if (@elems2){ print elems2 has these elements:\n; for(@elems2){ print $_\n; } print--- --- ---=--- --- ---\n; } if (@elems3){ print elems3 has these elements\n; for(@elems3){ print $_\n; } print--- --- ---=--- --- ---\n; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Hi Harry, split considers the pattern given to it, as a delimiter within the expression. Let us consider the three cases: my @elems1 = split(/\d/,$var); Digits are the delimiters. Delimiters are stripped out of the string by split. Hence, when digits are stripped out of a numeric expression, the result will be undef. my @elems2 = split(/./,$var); Again, anything is considered to be a delimiter due to the '.' (match anything). Thus, again, the result is undef. my @elems3 = split(//,$var); When the pattern is omitted, split splits on whitespace. Since the string does not contain whitespaces, the string cannot be split and split returns the string as it is. Hope it is clear now. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Modules download from CPAN
Hi, CPAN::Mini can be used to create/update local mirrors. minicpan script (http://search.cpan.org/perldoc?minicpan) which uses CPAN::Mini will be helpful in maintaining a local CPAN mirror. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Decimal representation of binary file (unpack)
On 8 April 2010 11:00, Raymond Wan r@aist.go.jp wrote: Hi all, I would like to read in a binary file and extract the 4-byte ints from it. Under Linux, something like od -t uI. I got it working as follows: my $buffer = STDIN; my @buffer = split //, $buffer; for (my $i = 0; $i length ($buffer); $i += 4) { print unpack ('I', $buffer[$i].$buffer[$i + 1].$buffer[$i + 2].$buffer[$i + 3]), \n; } And I was wondering if there was a way of doing this without the for loop. (I am referring to the unpack; not the print.) The perldocs for unpack says: unpack does the reverse of pack: it takes a string and expands it out into a list of values. (In scalar context, it returns merely the first value produced.) So, I thought this means I could give it a string and get a list of values like this: my @tmp = unpack ('I', $buffer); which does not work -- it only converts the first 4 bytes into an integer. Anyway, if the above code with a for loop is the best way, I'm happy to stick with it -- just wondering if I'm missing out on something with unpack... Thanks! Ray Hi Raymond, Wildcards can be used within the template in pack. There is no need of the inner loop you have written. For example, to unpack all signed longs: my @signed_longs = unpack ( 'I*', $buffer ); Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Need help to start with...
Hi Arjun, Can someone suggest me some good e-books or tutorials to start learning PERL? Welcome to the Perl world. :-) By the way, the language is named Perl, and not PERL. For online tutorials and links to books on the Perl language, you can check: http://perl-begin.org/ Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: error while installing win32::Registry module
Hi, Can't locate Win32/Registry.pm in @INC (@INC contains: C:/strawberry/perl/lib C: /strawberry/perl/site/lib C:\strawberry\perl\vendor\lib .) at GETIP.pl line 1. BEGIN failed--compilation aborted at GETIP.pl line 1. It means that perl is unable to find the module Win32::Registry. So, you need to either install it or add it to @INC for perl to find it. From checking CPAN, I read that Win32::Registry (http://search.cpan.org/perldoc?Win32::Registry) is now obsolete use Win32::TieRegistry (http://search.cpan.org/perldoc?Win32::TieRegistry) instead. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl Beginners
Hi Sudheer, Some links to help you get started: http://perl-begin.org/ http://learn.perl.org/ Good luck learning Perl. :-) Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to keep script alive if my shell closes
Hello Ariel, You could use either GNU Screen (http://www.gnu.org/software/screen/) or `nohup` command to run your script. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Archive::Zip library on Solaris
Hello all, I have a Perl Script that uses some of the Archive::Zip's methods for reading zip entries. Works fine on Linux, BUT on Solaris, this lib is not available in Solaris and I'm not allowed to install any lib in it. Is there a way to load the archive::zip lib dinamically, without installing it on the OS? Or, is there any default library on Solaris that I can read zip entries via filehandlers? Thanks! -- Bruno Morelli Vargas Mail: brun...@gmail.com Msn: brun...@hotmail.com Icq: 165055101 Skype: morellibmv Hello Bruno, Archive::Zip is a pure Perl module. You can download it from CPAN to some path where you have rw permissions and untar it. Then, modify @INC to use the library. No need to install it. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Git Talk by Randal
Who are you talking about? Is Merlyn some nickname I'm not aware of? Hi, Merlyn is Randal's nickname. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Windoze Woez
Hi, Windows requires you to use double quotes in place of single quotes. Saving to a file and executing it is the only way that is cross-platform, I suppose. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: passing command-line arg containing '@'
I need to pass an command-line arg that is a string which contains the '@'. Is there any way to do this and also 'tell' Perl not to interpret this as other than a '@' character? Thx. Hi, Perl would not do anything with command-line arguments unless you tell it otherwise. Check if you are using the EXPR form of eval to modify the argument list. perl -MData::Dumper -le 'print Dumper \...@argv' @this @should @work __Output__ $VAR1 = [ '@this', '@should', '@work' ]; Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Feedback, please
Hello, I would like to have someone looking over my script, which is a basic frontend for playing radio with mplayer. In particular, I'm wondering how I could get rid of all those elsif's when parsing the arguments; as you can see, there's lots of them, and I suspect that there's a better way of doing things. Any criticism on anything is highly appreciated, since I want to learn. Cheers. Hi, Looks like you forgot to provide a link to the script. If you do not want to use lots of elsifs, try using switch statements introduced by perl 5.10. http://perldoc.perl.org/perlsyn.html#Switch-statements Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: About the perl index function question
Hi, index $s, e, 3; This means position of the first 'e' on or after position 3. The position of the 'e' is counted from the start of the string. Counting starts from 0. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Can I design a website using Perl
Hi, There are many ways by which a website/application can be built using Perl. Mainly: * CGI * mod_perl * Any web framework All of the above have modules in CPAN. For simple tasks and for websites with not much traffic, you can go the CGI way. For much more complex tasks, you have the choice to choose between mod_perl or a web framework such as Catalyst. The Catalyst Web Framework (http://www.catalystframework.org/) helps in getting an application up and running in a few moments. It also has several modules backing it. The disadvantage of using Perl for web development is that it is a bit hard to deploy. However, the advantages outweigh the disadvantage by a considerable margin. Regards, Alan Haggai Alavi. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Regex to get last 3 digits of a number.
Hi, The following should work: my $number = '0111'; my ($index) = ( $number =~ /\d+(\d{3})/ ); $index would contain the last three digits: '111'. To learn about regular expressions in Perl, you can go through `perldoc perlre` and `perldoc perlretut`. The Perldoc website (http://perldoc.perl.org/) can be of help as well. Regards, Alan Haggai Alavi. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
PLEASE STOP SENDING MIALS
Re: retreive numbers from alpha-numeric string
On Tue, Sep 16, 2008 at 8:28 AM, cancer [EMAIL PROTECTED] wrote: Hi, I am using Perl on Linux server. I m writing a code which will tell us the Linux distro with version. For this the command is cat /etc/issue which is common for all the distributions of linux. Slackware :-) [EMAIL PROTECTED]:~$ cat /etc/slackware-version Slackware 12.0.0 [EMAIL PROTECTED]:~$ cat /etc/issue Welcome to \s \r (\l) [EMAIL PROTECTED]:~$ ls -la /etc/issue -rw-r--r-- 1 root root 24 2000-09-24 11:39 /etc/issue [EMAIL PROTECTED]:~$ Welcome to openSUSE 11.0 (X86-64) - Kernel \r (\l). REDHAT Red Hat Enterprise Linux Server release 5 (Tikanga) I am able to save the output in a string. Now I want a code or function which will give me only the number from the string. What Perl code have you already tried so far? If this is a class, your teacher encouraged students to come here (as in we here do not want to short circuit the student/teacher relation ie teacher sometimes needs feedback too) (improvement of lessons, and/or the sources provided for students to study and get their own answers) Where's your answer so far or otherwise what you've tried if this is not a class. See where we are put (or where that puts us) by what your approach has been so far? I'm not too high in Perl skills myself. But the next does some basic things. #!/usr/bin/perl use warnings; use strict; my @fields; while (DATA) { @fields = split; foreach (@fields) { next if /\d\)/; # no (X86-64) print $_\n if /\d+/; } } __DATA__ Slackware 12.0.0 Welcome to openSUSE 11.0 (X86-64) - Kernel \r (\l). # end of file marker -- Alan.
Re: Extract url and text from a website
Hi, Do not use regular expressions to parse HTML. Regexps will break at some point. Use HTML::Parser. Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: same variable defined twice
On Thu, May 22, 2008 at 5:57 AM, Octavian Rasnita [EMAIL PROTECTED] wrote: Hi, I've tried the following script and it works fine: use strict; my $text = 1; my $text = 2; print $text; Shouldn't perl disallow defining the $text variable a second time in the same script if using use strict? Probably not, as already has been said. And, as said, the use of: use warnings; *will* warn you. Next shows a block or lexical scope (mask does not happen) versus when in the same scope (in global, not using a separate scope block) where mask can happen. #!/usr/bin/perl use strict; use warnings; my $text = 1; # begin block next {my $text = 2; print In block we have ,$text,\n;} # block ended on previous line # so, next is outside of block print 1st Outside block we have ,$text,\n; my $text = 3; print 2nd Outside block we have ,$text,\n; # end -- Alan.
Re: same variable defined twice
On Fri, May 23, 2008 at 12:15 AM, Alan C [EMAIL PROTECTED] wrote: On Thu, May 22, 2008 at 5:57 AM, Octavian Rasnita [EMAIL PROTECTED] wrote: [ . . ] Next shows a block or lexical scope (mask does not happen) versus when in the same scope (in global, not using a separate scope block) where mask can happen. s/in global/in file scope/; IOW I meant file scope rather than global (my incorrect use of in global now stands as corrected.) [ . . ] -- Alan.
Re: log for script
On Wed, Apr 16, 2008 at 11:58 PM, [EMAIL PROTECTED] wrote: Is there any mechanism where I can take the log of entire Perl script. I mean to say that I need the log of each and every step which I am doing in Perl script. That step may include 1: input from user 2: internal Perl script commands Ultimately whatever Perl script is doing , I should know. http://search.cpan.org/~mschilli/Log-Log4perl-1.15/lib/Log/Log4perl.pm That logs. (I've only used it a little, scratched the surface, don't know much about it) Written by: M Schilli http://www.google.com/search?q=perlmeister+m+schilliie=utf-8oe=utf-8aq=trls=org.mozilla:en-US:officialclient=firefox-a -- Alan.
Howto strip html from a $calar with HTML::Parser
Hi, I saw the doc for HTML::Parser. I looked at its hstrip program in the eg folder but dunno how to strip a scalar instead of a file. I can strip a file. But I want to strip a scalar. Any help appreciated. As my code is currently, when ran, it prints text to STDOUT and the $source scalar variable holds html I do not need to print to STDOUT Is the print @ line in the sub doing this? I need to strip the html from $source What am I doing wrong whereby the html does not get stripped from $source ? -- So that I can then uncomment my __END__ So that the latter part of my program will then run. The latter part of my program works correctly; it finds a unique text string then prints it along with a specified number of subsequent lines. (This is what I want) but in order for this latter part to work, the html needs to be stripped from $source Current code is next: #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent-new(); my $url = ' http://www.wrh.noaa.gov/total_forecast/getprod.php?wfo=stosid=STOpil=ZFP'; # my $url = 'http://www.slackware.com/changelog/current.php?cpu=i386'; my $response = $ua-get( $url ); $response-is_success or $response-code == 404 # ignore 404 or die Can't get '$url': , $response-status_line; # print $response-content; # __END__ my $source = $response-content; $source =~ s/\n+/\n/g; # Strip html markup use HTML::Parser (); sub text_handler {# Ordinary text print @_; } my $p = HTML::Parser-new(api_version = 3); $p-handler( text = \text_handler, dtext); $p-parse($source); $p-eof; print ~source~\n; print $source; __END__ # print $source; my @raw = split(/\n/, $source); # print scalar( @raw ); my $line; my $stop_at; foreach ( @raw ) { $line++; if ( /CAZ017/ ) { $stop_at = $line + 40; } next unless $stop_at; print $_, \n if $line = $stop_at; } # end -- Ultimately, I want to print the CA (California) zone 17 forecast (southern Sacramento valley forecast). Probably will knock that $line + 40 down to $line + 15 or thereabouts. But, I need to strip the html from $source first. Thanks. -- Alan.
Re: Howto strip html from a $calar with HTML::Parser
; while ($readme) { #print if $line =~ /Weather Conditions at/i .. /=/; #print $line if $line =~ /Weather Conditions at/i .. /=/; print if /Weather Conditions at/i .. /SAC exec/; #print if /Weather Conditions at/i .. /^\=$/; } #print \n\n; #print @weather; } # end --- -- Alan.
Re: Leaving this list.
On Tuesday 05 June 2007 04:47, Ron Goral wrote: I am leaving this list even though I've been here for several years. While snip gets lots of spam attributed to this list exposed the email address gmail account does really good at filtering spam into a spam folder where spam is auto deleted once it's 30 days old. It's what I do, have/use a gmail account for this list. I just use the gmail with my pop3 email client of preference which for me is the rather powerful Kmail since Kmail is in KDE and I use the Linux KDE desktop. Some weeks that go by, 2 or 3 spam get past and make it to my Kmail. Other weeks, no spam whatsoever makes it to my Kmail. Ocasionally I log onto www gmail and report spam (the very very very few spam that didn't already get put into the spam folder). -- And, yes, the newsgroup post made it to the list -- made it to my gmail account and got to my Kmail on my Linux KDE desktop. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: numeric and string conversions
On Wednesday 28 March 2007 23:46, Craig Rodgers wrote: Thanks, The chr function was what I needed. It seems like there are a lot of stone cutter functions/operators in perl, I don't suppose you could recommend somewhere in the docs, on the web or in a book that would be useful in getting up to speed with these functions? I don't know about up to speed. But at least the next lists them and what they are for. (Perhaps more than that -- but, so far, I just took a quick, short look). http://perldoc.perl.org/index-functions.html http://perldoc.perl.org/perlop.html http://perldoc.perl.org/perl.html -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Learning Perl with shells operations
On Tuesday 27 March 2007 06:47, Rodrigo Tavares wrote: Hello, [ . . ] I use of stricts and warnings, and come this error compilation when i wrote into my code. Global symbol $x requires explicit package name at ./start-banco.pl line 7. Global symbol @word requires explicit package name at ./start-banco.pl line 11. Global symbol @bancos requires explicit package name at ./start-banco.pl line 17. The compilation show there are variables globals. What I can to resolve this problem ? When that happen, it's typically due to: have not used my which, when used, declares a lexical variable. This has to do with the scope of the varaiable. I don't see your latest code. Hopefully I didn't miss the mark (as in some other sort of a library/package issue). http://perl.plover.com/FAQs/Namespaces.html http://groups.google.com/group/perl.beginners/search?group=perl.beginnersq=scopeqt_g=Search+this+group http://groups.google.com/group/perl.beginners/search?group=perl.beginnersq=Global+symbolqt_g=Search+this+group -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Command line fed to Perl was Re: File::Find again
On Monday 26 March 2007 07:32, Dave Gray wrote: On 3/25/07, Alan [EMAIL PROTECTED] wrote: On Sunday 25 March 2007 18:14, Matt Herzog wrote: This is all I needed. I swear I had /($searchstring)/; in there at some point before . . . so if I pass it -s \.properties$ at the command line, it works as expetcted. Nice. That might be a shell thing? In Linux bash shell those quotes (I think) tell the shell to not interpret anything inside the quotes. bash quotes work like perl quotes: echo $PS1 echo '$PS1' It's a different case here ie not a var, instead it's a command line that's entered into a shell, such command line being passed to Perl. And the command needs to make it to Perl without getting altered before it gets to Perl. -s \.properties$ In that part of the command line, in this case the $ happens to also be a bash shell meta (or possibly interpreted) character. In this context, I was alledging that perhaps the quotes (on that command line) tell the bash shell to keep it literal (do not interpret the special character $). But, I don't know much. I guess there's even a way to run a Perl script without going through a shell in order to run the Perl script. If so, I don't know how to do it. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File::Find again
On Sunday 25 March 2007 18:14, Matt Herzog wrote: On Fri, Mar 23, 2007 at 03:09:31PM -0700, Wagner, David --- Senior Programmer Analyst --- WGO wrote: -Original Message- From: Matt Herzog [mailto:[EMAIL PROTECTED] Sent: Friday, March 23, 2007 15:00 To: Begin Perl Subject: File::Find again Hello All. I can see why people hate this module but I can't seem to let go. I point this script at a deep dir structure that has java .properties files sprinkled throughout it. Right now when I have my regex hard coded in the file, (.properties$) the search works fine. I need to be able to use the variable $searchstring at the command line. Is this even possible? If not, is there a way to exclude directories from being returned? This is all I needed. I swear I had /($searchstring)/; in there at some point before . . . so if I pass it -s \.properties$ at the command line, it works as expetcted. Nice. That might be a shell thing? In Linux bash shell those quotes (I think) tell the shell to not interpret anything inside the quotes. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File::Find again
On Friday 23 March 2007 14:59, Matt Herzog wrote: [ . . ] in the file, (.properties$) the search works fine. I need to be able to use the variable $searchstring at the command line. Is this even possible? If [ . . ] return unless ($_ =~ /\.properties$/); [ . . ] if ( /\Q$patc_fil\E$/ ) { # . . . } Someone mentioned the \Q and the \E I've used them. They work. (above, a line from one of my codes). -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl -e equivalent of short script...
hello, Good questions. I'm trying to use cmd line perl -e to do some fairly basic sed-style find/replace. Why don't you just use sed for that, if you're not doing the main program in Perl? Maybe I'm misunderstanding you, but it sounds like you're saying that you're writing shell scripts in which you're frequently calling 'perl -e'. That's like buying a Hefty bag to carry your Louis Vuitton. 3 reasons for using perl -e (a) it has the *full* regex set. My sed (under cygwin) has some limitationslike no \d. I have to do [0-9] each time. (b) I know my users will have a perl install [prerequisite from other stuff]. Dont know if they have cygwin/unix/linux (c) theory behind it being a cmd line was that as u allude to...users could look at it say I'm on unix...i'll just replace it w/ sed/awk Was able to get first few things working but stumbled when I wanted to do the following I won't quote the following; I'll just say that It took me about twenty minutes of puzzling before I realized what you're trying to do. I think. Your program is doing something resembling code coverage checking, trying to find out which items in a list are not mentioned in a number of files. Am I close? really? Sure sign I made the .pl overcomplicated then. All I'm trying to do is replace anything that matches w/ a newline. Okay, I will quote one loop: for (my $ctr = 0; $ctr scalar(@syms_info); $ctr++) { $syms_info[$ctr] = \n if ($syms_info[$ctr] =~ $bss_sym); } This is what a foreach loop is made to do; if you recode it as a foreach, you'll only have to mention 'syms_info' once, instead of three times, and you won't need $ctr or the scalar operator at all. Also, $bss_sym is from a line of input; is the input in the form of a regular expression? If not, probably you want to use 'eq' (string equality) instead of '=~' (pattern matching). true, but I'm tweaking the orig array in-place. So how to modify a given element if I dont have some index? But I'm unclear why you want to use a newline to represent matched items. Why not remove them from the list entirely? I'm sure I'm missing something. If removing would work, consider grep instead of the foreach loop. replacing w/ a newline makes diffs easier. User can diff all_syms orig i/p w/ the trimmed syms i/p and just see what got deleted. ...but I'd like a (somewhat convoluted perhaps) 1-liner w/ perl -e cmd-liner. Why do you want a 'perl -e' program, as opposed to an ordinary perl program? It's not going to be easier to read, write, understand, maintain, or debug. It's not going to run faster. It's always cool to condense a program to a one-liner. However, this sounds like a program that needs to be improved in the realm of correctness, not coolness. sounds like advice is to not bother w/ perl -e. Seems a pity. Looked like a perfect job for perl -e but perhaps its pushing it a bit. Good luck with your project! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Sucker-punch spam with award-winning protection. Try the free Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/features_spam.html
perl -e equivalent of short script...
hello folks, I'm trying to use cmd line perl -e to do some fairly basic sed-style find/replace. Was able to get first few things working but stumbled when I wanted to do the following - given an i/p (piped o/p from a previous perl -e cmd on DOS) of... dtor_list.obj: newnothrow.obj: vars.obj: _lock.obj: ...then if regex match w/ any lines in file all_fxns.txt of form... /* array_del.obj: */ -u ___dla__FPv /* array_nonew.obj: */ -u ___nwa__FUiRCQ2_3std9nothrow_t /* dtor_list.obj: */ -u ___already_marked_for_destruction /* memzero.obj: */ -u ___memzero ...then replace entry in all_fxns.txt w/ a blank line So... /* dtor_list.obj: */ -u ___already_marked_for_destruction ...should get replaced w/ an empty line. This .pl does the job just fine my $all_syms_file = all_fxns.txt; open (SYMSINFO, $all_syms_file) or die Cannot open $all_syms_file: $!; my @syms_info = SYMSINFO; close SYMSINFO; while (my $bss_sym = ) { chomp($bss_sym); for (my $ctr = 0; $ctr scalar(@syms_info); $ctr++) { $syms_info[$ctr] = \n if ($syms_info[$ctr] =~ $bss_sym); } } print @syms_info; ...but I'd like a (somewhat convoluted perhaps) 1-liner w/ perl -e cmd-liner. Seems like it should be feasible in 1/10th the code. Any thots? Many thanks indeed, Alan - Be a PS3 game guru. Get your game face on with the latest PS3 news and previews at Yahoo! Games. http://videogames.yahoo.com/platform?platform=120121
Re: How to revinent wget?
I wrote: (ftp), however, does not work which I'd guess is due to difference in communication method. Doh! (Net::FTP struck me upside the head!). (It works). Just give it a full url, either http:// or ftp:// The -c switch for continue in wget is probably not implemented in this Perl code (which we may not need unless we are on a dialup internet connection). It would be easy to change/add_in so that the url could be entered on the command line. Critiques, improvements, ideas, suggestions? (I didn't know if it's acceptable use to call a sub routine without passing any parameters) (I did it this way because otherwise I would've needed an if -- else construct). #!/usr/bin/perl use strict; use warnings; use LWP::Simple; use HTML::SimpleLinkExtor; use Net::FTP; # fully qualified url -- either an http:// or an ftp:// variety my $url = 'http://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso'; #my $url = 'ftp://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso'; my $proto_sw = 0; # pick for which protocol from $url $proto_sw = 1 if $url =~ /^ftp\:\/\//; SWITCH: for ($proto_sw) { # do either http or ftp protocol /0/do { http_protocol(); last; }; /1/do { ftp_protocol(); last; }; die unknown value for protocol switcher: $proto_sw; } sub http_protocol { my $content = get($url); die Couldn't get it! unless defined $content; my $extor = HTML::SimpleLinkExtor-new(); $extor-parse($content); my @iso_links = grep /\.md5$/, $extor-links; # .md5 # print @iso_links, \n; $url .= /; print The http url is: , $url, \n\n; print The DL files are:, \n; foreach my $link (@iso_links) { #my $iso = get($link); my $fil = $url . $link; print $fil, \n; getstore($fil,$link); } } sub ftp_protocol { $url =~ s/^ftp\:\/\///; $url =~ /^(.+?)\/(.+)/; # print $1, \n; # print $2, \n; my $host = $1; my $abs_path = \/ . $2; print The ftp Host is: , $host, \n; print Absolute path is: , $abs_path, \n\n; print The DL files are:, \n; my $ftp = Net::FTP-new($host, Debug = 0) or die Cannot connect to $host: $@; $ftp-login(anonymous,'-anonymous@') or die Cannot login , $ftp-message; $ftp-cwd($abs_path) or die Cannot change working directory , $ftp-message; #Now list all the files on the remote server and check for foreach my $file($ftp-ls) { next unless $file =~ /.+\.md5$/; # .md5 print $file, \n; # $ftp-get($file) or die Get failed , $ftp-message; } $ftp-quit; } # end -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to revinent wget?
On Wednesday 14 March 2007 09:10, siegfried wrote: I'm downloading a lot of debian images using wget these days. Can anyone suggest where I might look to find a little perl script that will download a web page, look for all the links containing .iso and then reinvent wget to download them all? I run Slackware 11.0 which has lynx onboard (the enclosed code needs lynx). The next (not meant as an example of how to code in Perl) but, nonetheless it works here on the $url that I currently have it set to (no guarantee on other, different $url). It currently downloads 7 very small text files that end with .md5 Puts a total of 8 files into current dir. (so, might want to run it from an empty dir) if /(ftp|http).+\.md5$/; that signifies files ending with .md5 So, it likely would DL .iso files if you changed that (the .md5) to: if /(ftp|http).+\.iso$/; #!/usr/bin/perl use strict; use warnings; my $url = 'ftp://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso'; my $text_only = `lynx -dump $url`; $text_only =~ s/\n+/\n/g; my @lines = split(/\n/, $text_only); my $files_2_dl; # .md5 files (small text files) foreach ( @lines ) { s/^.+(ftp\:|http\:)/$1/ and $files_2_dl .= $_\n if /(ftp|http).+\.md5$/; } # print $files_2_dl, \n; # man wget says: wget -i - # when that last dash is used, wget receives its # urls from STDIN # I do not know how to STDIN the urls to wget # system(wget -i - $files_2_dl); # only DL's 1 file # so (for now): my $urls4dl = fils2dl_w_wget.txt; open(NEW, , $urls4dl) or die cant open $urls4dl: $!; my @dwnlds = split(/\n/, $files_2_dl); foreach ( @dwnlds ) { # chomp; # system(wget $_); $_ .= \n; print NEW; } close(NEW) or die cant close $urls4dl: $!; system(wget -i $urls4dl); # end -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to revinent wget?
On Wednesday 14 March 2007 09:10, siegfried wrote: I'm downloading a lot of debian images using wget these days. Can anyone suggest where I might look to find a little perl script that will download a web page, look for all the links containing .iso and then reinvent wget to download them all? #!/usr/bin/perl use strict; use warnings; my $url = 'ftp://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso'; my $text_only = `lynx -dump $url`; $text_only =~ s/\n+/\n/g; my @lines = split(/\n/, $text_only); foreach ( @lines ) { s/^.+(ftp\:|http\:)/$1/ and system(wget $_) if /(ftp|http).+\.md5$/; } # end -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to revinent wget?
Hi. The orig post of this code did not come to my email -- but the post is on Google Groups. (I'm emailing). I got the code (as enclosed below) working when the url is http. But, ftp://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso (ftp), however, does not work which I'd guess is due to difference in communication method. Lynx just knows how to handle either ftp or http and get something returned on either so that we can grep or regex or linkextor for the files we want to download. I thought it be neat to get the next code to work for ftp too. I looked at lwptut and lwpcook amongst others. I saw something about protocols allowed which didn't appear to be what I needed to get this to also work with ftp. Can anyone assist/point me toward getting this to work for both http and ftp? #!/usr/bin/perl use strict; use warnings; use LWP::Simple; use HTML::SimpleLinkExtor; my $url = 'http://slackware.mirrors.tds.net/pub/slackware/slackware-11.0-iso'; my $content = get($url); die Couldn't get it! unless defined $content; my $extor = HTML::SimpleLinkExtor-new(); $extor-parse($content); my @iso_links = grep /\.md5$/, $extor-links; # .md5 # print @iso_links, \n; $url .= /; # print $url, \n; foreach my $link (@iso_links) { #my $iso = get($link); my $fil = $url . $link; print $fil, \n; getstore($fil,$link); } # end -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: better way to skip first few lines of file read?
TRACECSV while $. = 4; $. is not well-known to many Perl programmers. TRACECSV for 1 .. 4; thanks. Above solution is simple effective. I agree that I was gratuitously using $. when your solution is far easier to document and probably safer in my program since I have several filehandles open. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
better way to skip first few lines of file read?
hello folks, I'm parsing a file that's 1+ lines long. Since sometimes it can be 10x that size I'm doing line by line parsing as opposed to array slurp. The first 4 lines are gobbldygook and need to be skipped. Currently I'm doing... while (my $line = TRACECSV) { next unless ($. 4); # only do work if on 4th line but on a 1 line file thats 9996 wasted operations. In an array I could simply do: - for my $ct (4 .. $#trace_data) { ...the syntax for doing the same thing in line by line I/O escapes me? Anybody know? Many thanks indeed. Cheers, Alan __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
any traction on JPL?
hello folks, anything I can find on this mail list googling shows only JPL references 3 years old. Is there any active work on making Java-Perl work together? I ask because my company is moving from a COM based IDE to an Eclipse based one. There are a large set of users with existing perl scripts for regression tests etc. Other languages are in good shape since they have Java based scripting lang equivalents (Pyhton - Jython, TCL - JACL). We'd like folks to have their familiar perl env but be able to call the new Eclipse IDE Java methods. Adapters (JNI) back to orig COM/C++ methods are not as attractive since all the manpower is going into Eclipse Java APIs. Thanks, Alan - Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
smtp authentication
Tom - Yes I use real values. Dr. Ruud - You're right... the extra line is useless and I have cleaned it up accordingly. Anyways I figured the script out. Here's the final output cleaned up a little bit. Thanks for your help. #!/usr/bin/perl -w use strict; use Net::SMTP; my $mail_server = mailhost; my $username = login; my $password = password; my $msg = This is a test; my $smtp = Net::SMTP-new($mail_server, Hello = 'mailhost', Port = 587, Timeout = 60, Debug = 1) or die Can't open connection to $mail_server:$!\n; defined ($smtp-auth($username, $password)) or die Can't authenticate: $!\n; $smtp-mail('sender'); $smtp-recipient('recipient'); $smtp-data(); $smtp-datasend($msg); $smtp-dataend(); $smtp-quit; exit; __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
smtp authentication
Hey, I'm trying to send mail over my server (1and1.com). They require smtp authentication in order to send. I'm using windows XP. Here is my code: #!/usr/bin/perl -w use strict; use Net::SMTP; my $mail_server = mailhost; my $username = login; my $password = password; my $msg = This is a test; my $smtp = Net::SMTP-new($mail_server, Hello = 'mailhost', Port = 587, Timeout = 60, Debug = 1) or die Can't open connection to $mail_server:$!\n; defined ($smtp-auth($username, $password)) or die Can't authenticate: $!\n; $smtp-auth($username, $password); $smtp-mail('sender'); $smtp-recipient('recipient'); $smtp-to('recipient'); $smtp-data(); $smtp-datasend($msg); $smtp-dataend(); $smtp-quit; exit; - All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
sorting a nested array?
ello folks, ...got a bit carried away with references deeply nested structures. Net result is I have an array of the form: - $ref- reference to nested array [0] - nothing at this level to key/sort on [0] - this level contains the 'meat' ...data... {typedefName} = xyz; - would like to sort on this but its nested [1] [1] Normally for sorting on an array we can do my @funcs = sort {$a-{typedefName} cmp $b-{typedefName}} @func_recs; ...but with a key-less extra level, how would I go about sorting? Let me know if insufficient data re the problem has been supplied. Thanks, Alan - Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail Beta.
RE: Exec a script on one server that will exec other scripts on a different serv
It would seem to be that the best solution here would be to have a server script that creates a tcp/ip socket and sites on a read on the socket, in which then the client connects to the server, sends a msg, and based on that msg, the server would execute the desired action. This would be a tpical server-client network communication procedure. The server script would sit in a state in which it is waiting for the other side of the socket to be connect by the client, accept a msg, and then disconnect the client, and what for another connection. Alan From: William Paulsen (W) [EMAIL PROTECTED] To: Jerry DuVal [EMAIL PROTECTED], beginners@perl.org Subject: RE: Exec a script on one server that will exec other scripts on a different server.. Date: Thu, 8 Jun 2006 15:31:12 +0200 Adding it would be an advantage, however right now I just need setup a client side script that'll tell the server side to exec/run one of three scripts on the other server. tks William Gugulethu -Original Message- From: Jerry DuVal [mailto:[EMAIL PROTECTED] Sent: 08 June 2006 03:09 PM To: William Paulsen (W); beginners@perl.org Subject: RE: Exec a script on one server that will exec other scripts on a different server.. -Original Message- From: William Paulsen (W) [mailto:[EMAIL PROTECTED] Sent: Thursday, June 08, 2006 8:54 AM To: beginners@perl.org Subject: Exec a script on one server that will exec other scripts on a different server.. Hi, I'm trying to write a perl script that will run on one server but can instruct either socker server deamon on another server to exec any one of three applications on a different box. The reason for this is the password changes every month and the scripts that I'm currently using fails because of that. Is this possible in perl? Can you add public/private keys pairs then a password is not needed? ~~ This e-mail and its contents are subject to the Telkom SA Limited e-mail legal notice available at http://www.telkom.co.za/TelkomEMailLegalNotice.PDF ~~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response _ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reg exp speed?
hello folks, Thanks for all the advice. As several of you suggested, the winning ticket turned out to be flipping to line-by-line regex from an array-slurped input i.e. # look for potentially problematic dissassembly of the following form: - # 8004b980 003c34f4 STW.D2T1 A0,*B15--[1] my @dis_lines = ; foreach my $ln (@dis_lines) { if ($ln =~ m/.*ST[A-Z].*B15--.*[13579]]/) { print $ln; } } I think I got carried away by last problem I had which *required* a multi-line match scalar slurp without line-by-line was faster. Thanks again for all the advice. Much appreciated. FYI the script now runs in 1sec on a 9Mb file, as compared to 3min 30s previously! cheers, Alan John W. Krahn [EMAIL PROTECTED] wrote: Alan Campbell wrote: hello folks, Hello, I'm slurping in a large file and seeing a nice speedup versus line by line processing...but I'm losing it in my (likely poorly constructed!) reg-expression match I do: - # # look for potentially problematic code of the following form: - # STW b0, *SP--[3] # The reg exp tries to match: - # - anything up until 'ST' (so that we match STH, STW, STDW etc) followed by # - 1+ non-whitespace chars followed by # - 0+ whitespace chars followed by # - 0+ non-whitespace chars followed by # the string 'B15--' followed by # anything up until an odd single-digit number followed by # the ']' character # Matches all occurrences # my @match_sp = $all_lines =~ /.*ST\S+\s*\S*B15--.*[^02468]]/mg; ...and then I foreach on @match_sp to show all occurrences found... Any speedup tips most welcome. Would also appreciate a brief explanation of why this reg ex is slow (so I dont screw it up next time!) Your pattern starts with '.*' and the '*' modifier is greedy so it has to match as many non-newline characters as possible and then it back-tracks to match 'ST'. You should use the non-greedy quantifier '*?' so it won't back-track. Your character class [^02468] does indeed match odd numbers, as well as every other character not '0', '2', '4', '6' or '8'. You should probably use the character class [13579] to match _only_ odd numbers. The /m option is not required because you are not using either '^' or '$' to anchor the pattern. my @match_sp = $all_lines =~ /.*?ST\S+\s*\S*B15--.*?\[[13579]]/g; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.
reg exp speed?
hello folks, I'm slurping in a large file and seeing a nice speedup versus line by line processing...but I'm losing it in my (likely poorly constructed!) reg-expression match I do: - # # look for potentially problematic code of the following form: - # STW b0, *SP--[3] # The reg exp tries to match: - # - anything up until 'ST' (so that we match STH, STW, STDW etc) followed by # - 1+ non-whitespace chars followed by # - 0+ whitespace chars followed by # - 0+ non-whitespace chars followed by # the string 'B15--' followed by # anything up until an odd single-digit number followed by # the ']' character # Matches all occurrences # my @match_sp = $all_lines =~ /.*ST\S+\s*\S*B15--.*[^02468]]/mg; ...and then I foreach on @match_sp to show all occurrences found... Any speedup tips most welcome. Would also appreciate a brief explanation of why this reg ex is slow (so I dont screw it up next time!) Many thanks, Alan - New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
Re: 'medium' reg exp greediness?
hello, thanks for the advice. You're right - I should have given more data. The reason I'm trying to kill elements from the XML is because the size of the XML I'm dealing with can get hideous - up to 100Mb. I read Uri's article on slurping and that helps alot ( http://www.perl.com/pub/a/2003/11/21/slurp.html ) ie avoiding line by line processing gained big speedup. Basically there are a lot of legacy scripts using XML::Simple that I'd like to leverage (which were obviously done on smaller xml's!)...hence looking to pre-slurp and pre-kill unneeded entities from the input XML. I'm open to using a module but pure reg exp (non line-by-line) seems faster...and speed is important in this case due to filesize. Grateful for any ideas u may have. Cheers, Alan Jay Savage [EMAIL PROTECTED] wrote: On 4/29/06, Alan Campbell wrote: hello folks, I'm trying to do a 'medium' greediness regular expression. Here's what I mean. I need to grab all of the DW_TAG_TI_reserved stuff and kill it (italics below) DW_TAG_TI_assign_register DW_AT_location DW_OP_reg0 [snip] A couple of thoughts: If you read this list regularly, you already know the advice you're going to get: there are hundreds of xml modules on CPAN. Use them! Don't reinvent the wheel. If you really insist on doing this by hand, we need to see more code. How are you approaching this? On the surface, it looks pretty simple: { $lf = \n; local $/ = . $lf; whlie () { print unless /DW_TAG_TI_reserved/; } } Your question, though, leads me to think there's more going on. So let me just reiterate my original advice again: use a mudule. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of â will give rise to dom! - Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.
'medium' reg exp greediness?
hello folks, I'm trying to do a 'medium' greediness regular expression. Here's what I mean. I need to grab all of the DW_TAG_TI_reserved stuff and kill it (italics below) die id='0x157' tagDW_TAG_TI_assign_register/tag attribute typeDW_AT_location/type value blockDW_OP_reg0/block /value /attribute /die die id='0x8903' tagDW_TAG_TI_reserved_1/tag attribute typeDW_AT_name/type value stringC:\DOCUME~1\A0741153\LOCALS~1\Temp\TI1564:L2:2:1088629783/string /value /attribute die id='0x8951' tagDW_TAG_TI_reserved_2/tag attribute typeDW_AT_low_pc/type value addr0x1b84/addr /value /attribute /die /die die id='0x130' tagDW_TAG_variable/tag attribute typeDW_AT_name/type value stringTSK_thingyIneedToKeepThis/string /value /attribute /die I did the following for killing DW_TAG_TI_assign_register. $all_lines =~ s/die id\S*\s*tagDW_TAG_TI_assign_register.*?\/die//sg; That worked fine. But the DW_TAG_TI_reserved stuff is nested. I need medium greediness ie .* (where . also matches newline via /s) without a ? would go too far ie it would grab everything up until last /die which is too muchkills stuff I need to keep. But .*? is too lazy...it doesnt handle the nesting ie only kills up until the first /die. To further complicate life, I cant guarentee the level of nesting. Any ideas on how best to reg exp this? Or do I just need to improve/narrow my search string. Many thanks indeed. cheers, Alan - How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.
Re: perl with databases
On Sunday 19 February 2006 12:56, Octavian Rasnita wrote: [ . . ] The database I need to keep is not very very big, but too big for MySQL, and the most important thing is the speed of selections/updates. [ . . ] DB_File and BerkelyDB are two Perl modules that use the embedded database which is at/from http://www.google.com/search?q=sleepycat+softwarestart=0ie=utf-8oe=utf-8client=firefox-arls=org.mozilla:en-US:official Oracle just recently bought out Sleepycat. But this is not SQL. But it is fast and it's used for lots of things. You would need to compare your need for this versus your need for SQL and then choose which one of the two based on what your needs are. -- Alan.
compile fails at/during the use DB_File; line
Hi, Perl 5.8.8 on Slackware 10.2 As to the libdb's: (the default for Slack 10.2) appears to be onboard 3 different versions of libdb (Sleepycat) Ideas, suggestions to get it working? How to tell if it's a Perl or a C init thing? /usr/lib/perl5/5.8.8/i486-linux/auto/DB_File/DB_File.so does exist. Next, in order, (a) line # 5 from rss4, (b) the error perl returned, (c) onboard/installed Slack pkgs of libdb, and (d) libdb's (a) use DB_File; (b) [EMAIL PROTECTED]:~$ rss4 Can't load '/usr/lib/perl5/5.8.8/i486-linux/auto/DB_File/DB_File.so' for module DB_File: libdb-4.4.so: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.8/i486-linux/XSLoader.pm line 70. at /usr/lib/perl5/5.8.8/i486-linux/DB_File.pm line 251 Compilation failed in require at /home/al/bin/rss4 line 5. BEGIN failed--compilation aborted at /home/al/bin/rss4 line 5. (c) [EMAIL PROTECTED]:~$ cd /var/log/packages [EMAIL PROTECTED]:/var/log/packages$ lsag db -rw-r--r-- 1 root root 1164 2005-09-27 18:23 db3-3.3.11-i486-4 -rw-r--r-- 1 root root803 2005-09-27 18:23 db31-3.1.17-i486-1 -rw-r--r-- 1 root root 1117 2005-09-27 18:23 db4-4.2.52-i486-2 -rw-r--r-- 1 root root 1174 2005-09-27 18:22 gdb-6.3-i486-1 -rw-r--r-- 1 root root762 2005-09-27 18:23 gdbm-1.8.3-i486-3 -rw-r--r-- 1 root root 1031 2005-09-27 18:31 xxgdb-1.12-i386-1 (d) [EMAIL PROTECTED]:/var/log/packages$ cd /usr/lib [EMAIL PROTECTED]:/usr/lib$ lsag libdb -rw-r--r--1 root root 723168 2004-05-11 18:09 libdb-3.1.a -rw-r--r--1 root root 629 2004-05-11 18:09 libdb-3.1.la lrwxrwxrwx1 root root 17 2005-09-27 18:23 libdb-3.1.so - /lib/libdb-3.1.so* -rw-r--r--1 root root 842506 2004-05-11 18:30 libdb-3.3.a -r--r--r--1 root root 696 2004-05-11 18:30 libdb-3.3.la lrwxrwxrwx1 root root 17 2005-09-27 18:23 libdb-3.3.so - /lib/libdb-3.3.so* lrwxrwxrwx1 root root 11 2005-09-27 18:23 libdb-3.a - libdb-3.3.a lrwxrwxrwx1 root root 12 2005-09-27 18:23 libdb-3.so - libdb-3.3.so* -rw-r--r--1 root root 1170632 2004-05-29 23:03 libdb-4.2.a -rw-r--r--1 root root 781 2004-05-29 23:03 libdb-4.2.la lrwxrwxrwx1 root root 17 2005-09-27 18:23 libdb-4.2.so - /lib/libdb-4.2.so* lrwxrwxrwx1 root root 11 2005-09-27 18:23 libdb-4.a - libdb-4.2.a lrwxrwxrwx1 root root 12 2005-09-27 18:23 libdb-4.so - libdb-4.2.so* lrwxrwxrwx1 root root 11 2005-09-27 18:23 libdb.a - libdb-3.3.a lrwxrwxrwx1 root root 12 2005-09-27 18:23 libdb.so - libdb-3.3.so* lrwxrwxrwx1 root root9 2005-09-27 18:23 libdb4.a - libdb-4.a lrwxrwxrwx1 root root 10 2005-09-27 18:23 libdb4.so - libdb-4.so* lrwxrwxrwx1 root root 19 2005-09-27 18:31 libdbh-1.0.so.1 - libdbh-1.0.so.1.0.0* -rwxr-xr-x1 root root23172 2005-05-17 17:03 libdbh-1.0.so.1.0.0* -rwxr-xr-x1 root root 783 2005-05-17 16:48 libdbh.la* lrwxrwxrwx1 root root 19 2005-09-27 18:31 libdbh.so - libdbh-1.0.so.1.0.0* [EMAIL PROTECTED]:/usr/lib$ Oh, BTW: alias lsag='ls -la | grep' -- Alan.
Re: pseudohash
On Saturday 11 February 2006 10:10, James Marks wrote: On Feb 11, 2006, at 12:04 AM, Owen Cook wrote: On Sat, 11 Feb 2006, Beast wrote: Could someone explain what is pseudohash means? Maybe have a read of perlref, try http://perldoc.perl.org/perlref.html Owen To my amusement, when I followed your suggestion, I got: -- Perl 5.8.6 documentation -- Home Search results Search results No matches found for your query pseudohash http://www.google.com/search?q=site%3Aperldoc.perl.org+pseudohashstart=0ie=utf-8oe=utf-8client=firefox-arls=org.mozilla:en-US:official Google turned up some hits though I not have time to peruse any of the hits. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: filehandle question
On Tuesday 17 January 2006 09:30, radhika wrote: [ . . ] 409$plain_text .= $_ foreach ($fh); close $fh; --code end-- I keep getting this error: readline() on closed filehandle $fh at /home/ars/sys/libperl/site/ARS/REPORTS/AggregateFills.pm line 409. Is that above line with foreach is it a shorthand/substitute for: while ( $fh ) { $plain_text .= $_; } # end_of_code ??? yes/no ?? -- And, please of course *do* listen to Mr. Clarkson and Shawn Corey's replies on this thread/issue. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Maybe Stupid RegEx Question
Bastian Angerstein wrote: Hi I have two strings 0x1479ee und 0x1479fe. The strings a in $var1 and $var2. if I do: if ( $var2 =~ /\Q$var1\E/) It matches. how can I match an the string and not on each sign? As someone else pointed out, I am surprised that you got a match... Just out of curiosity though, why not do this: if ( $var2 eq $var1 ) Wouldn't that achieve what you want? Alan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response