Re: Problem with my code
-Original Message- From: Mihir Kamdar [EMAIL PROTECTED] $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields if u want. There are (maybe) two problems above. 1. when using hash slice,the form is @hash{'key1','key2'...},not $hash{'key1','key2'...} 2. when you say @hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line,only the first key ($cdr[2]) has got value,the other keys would get undef as their values,since $line is a scalar,but the statement expect a list on the right of '=' I think. -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: VMWARE PERL API
hi The problem was like i had to read the config file in /etc/vmware/ directory. * if (open CONFIG, '/etc/vmware/config') { my $libdir; my $line; while (defined($line = CONFIG)) { chomp $line; if ($line =~ /^\s*libdir\s*=\s*\(.*)\\s*$/) { $libdir = $1; last; } } close CONFIG; if (defined($libdir)) { my $perl_binary = $libdir . '/perl5/bin/perl'; if (-x $perl_binary) { $ENV{'VMWARE_PERL_NESTED_EXEC'} = 1; exec $perl_binary, '-I'.$libdir.'/perl5/site_perl/5.005', $0, @ARGV; } } } * this is the part that i included to get things working. ie. adding a library path. I think this stuff is going a bit complicated.. please give my some links on perl concepts. i have fome pdf files from perk.org.. but they are a bit basic and not deep into such things. please refer dome books that might by of some use to me :) can u explain this part in detail if (-x $perl_binary) { $ENV{'VMWARE_PERL_NESTED_EXEC'} = 1; exec $perl_binary, '-I'.$libdir.'/perl5/site_perl/5.005',$0, @ARGV; } thanks for ur help On 8/2/07, John W. Krahn [EMAIL PROTECTED] wrote: Jeff Pang wrote: From: vishnu [EMAIL PROTECTED] Im trying to Build an API in perl. I've included path of my installation like: sub BEGIN { push (@INC, (/usr/lib/vmware-server/perl5/site_perl/5.005/i386-linux, .)); } It's not sub BEGIN but BEGIN block, BEGIN { push @INC,/your/lib/path; } perldoc perlmod [ SNIP ] BEGIN, CHECK, INIT and END Four specially named code blocks are executed at the beginning and at the end of a running Perl program. These are the BEGIN, CHECK, INIT, and END blocks. These code blocks can be prefixed with sub to give the appearance of a subroutine (although this is not considered good style). One should note that these code blocks don't really exist as named subroutines (despite their appearance). The thing that gives this away is the fact that you can have more than one of these code blocks in a program, and they will get all executed at the appropriate moment. So you can't execute any of these code blocks by name. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- Vishnu, cell:99944 75599 if you don't make mistakes, chances are you are not stretching yourself.
Re: Problem with my code
On 8/3/07, Jeff Pang [EMAIL PROTECTED] wrote: -Original Message- From: Mihir Kamdar [EMAIL PROTECTED] $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields if u want. There are (maybe) two problems above. 1. when using hash slice,the form is @hash{'key1','key2'...},not $hash{'key1','key2'...} 2. when you say @hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line,only the first key ($cdr[2]) has got value,the other keys would get undef as their values,since $line is a scalar, but the statement expect a list on the right of '=' I think. I don't think he is trying to use the slice notation. He is using the multidimensional array emulation. This not really a good practice because it is easy to confuse it with slices. A better way to get the same functionality is $hash{@cdr[2,3,6,7]} = $line; The quotes act as a signal that you aren't looking for a slice. from perldoc perlvar $; The subscript separator for multidimensional array emulation. If you refer to a hash element as $foo{$a,$b,$c} it really means $foo{join($;, $a, $b, $c)} -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
-Original Message- From: Chas Owens [EMAIL PROTECTED] Sent: Aug 3, 2007 3:21 AM To: Jeff Pang [EMAIL PROTECTED] Cc: beginners@perl.org Subject: Re: Problem with my code On 8/3/07, Jeff Pang [EMAIL PROTECTED] wrote: -Original Message- From: Mihir Kamdar [EMAIL PROTECTED] $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields if u want. There are (maybe) two problems above. 1. when using hash slice,the form is @hash{'key1','key2'...},not $hash{'key1','key2'...} 2. when you say @hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line,only the first key ($cdr[2]) has got value,the other keys would get undef as their values,since $line is a scalar, but the statement expect a list on the right of '=' I think. I don't think he is trying to use the slice notation. He is using the multidimensional array emulation. This not really a good practice because it is easy to confuse it with slices. A better way to get the same functionality is $hash{@cdr[2,3,6,7]} = $line; The quotes act as a signal that you aren't looking for a slice. Yes I know this expression too.But why one should write something like this?It's too out of date. -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: abbreviations
Petra Vide Ogrin wrote: $text =~ m/\b\w{4,8}[^IVX]\.\s\l/g but it doesn't work - it just gets the words at the end of each sentence. So this \l at the end of the match is wrong. What should I do to make it work? Try: $text =~ m/\b\w{4,8}[^IVX]\.\s[a-z]/g -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
On 8/3/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: snip But the expression $hash{@cdr[2,3,6,7]} is the same as $hash{join($,@cdr[2,3,6,7])} You have just replaced one special variable with another and $ is a bad choice since it's default is a space character, which may easily appear in one (or all) of @cdr[2,3,6,7] A better choice is $hash{$cdr[2]}{$cdr[3]}{$cdr[6]}{$cdr[7]} but you would need four for-loops to get to the value. snip The use of the special variable $; is not why $foo{$a[1],$a[2],$a[3],$a[4]} is a bad choice; it is a bad choice because it is hard to tell if they meant to use @foo{$a[1],$a[2],$a[3],$a[4]} but screwed up the sigil. The spaces are only important if you want to recover the individual values from the key, and, since you are storing the entire record, you don't even need the key to get those values. Why would you create a nested hash? This does not appear to be a tree data. If you want to do it long hand because you don't want the spaces that using an array slice will add then simply say $hash{{$cdr[2]$cdr[3]$cdr[6]$cdr[7]} -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: library (random numbers)
Amichai Teumim wrote: ./script.pl | echo 1234 Or is this nonsensical? Very very new to Perl. This is actually shell: echo 1234 | ./script.pl Try: ./script.pl EOD 1234 5678 90 EOD -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: library (random numbers)
On Aug 3, 6:03 am, [EMAIL PROTECTED] (Amichai Teumim) wrote: After some friendly input from yitzle I might have moved further with my library. This is my script. script.pl #!/usr/bin/perl Get into the habbit of using use strict; use warnings; in all of your scripts. You will be greatful you did in the long run. With such small libraries/scripts as these, it's not as important as mistakes are far easier to debug, but getting into the habbit now will save you endless amounts of pain later on in your programming life. #require 'lib.pl'; @userArray = STDIN; my @userArray = STDIN; because 'use strict;' forces you to declare your variables. $sum = sumIt(@userArray); my $sum = sumIt(@userArray); Out of curiousity, is this a learning excercise, or do you intend to actually use this? If the latter, you should know that this wheel has already been invented. The standard List::Util module provides a sum() function: use List::Util qw/sum/; my $sum = sum(@userArray); print $sum; And this is my library according to yitzle: sub sumIt(@) 1) Don't use prototypes. They don't work like anyone expects them to. 2) This particular prototype is double-plus useless. It says that this function takes a list of values. That's what all subroutines without prototypes take. That (@) is doing nothing at all. { my $total = 0; $total += $_ for (@_); return $total; # This line might not be needed... Not needed, but again a good habbit to get into. Never rely on the blocks return the last evaluated value feature of Perl. Return explicitly, so that you don't FUBAR things when you later go back to modify your code. For example, if you had just written: sub sumIt { my $total; $total += $_ for @_; } and then later you wanted to add a warning if there hadn't been anything in @_: sub sumIt { my $total; $total += $_ for @_; warn @_ was empty, total undefined!!\n if !defined $total; } Now you've FUBARed your script. The last value evaluated will either be the (!defined $total), or the (warn ...). It won't be $total. If you'd started with the explicit return statement, you'd save yourself this problem. } sub avg(@) { my @arr = @_; my $arrSize = @arr; # scalar(@arr) is the array size - or one less (last index). Double check scalar(@arr) is the size of the array $#arr is the last index of the array. USUALLY it is a true statement that scalar(@arr) == $#arr + 1; However, this is not necessarily the case, as in Perl you can actually futz with the starting index of arrays using the $[ variable. You should never do that, of course, but you also shouldn't assume that no one in your program has. return simIt(@arr) / $arrSize; Well first, assuming you meant sumIt, not simit, there's no reason to create a new variable just to store the size of the array. Just use the array in a scalar context: return sumIt(@arr) / @arr; } 1; Now either this is wrong or I have no idea how to use it. With STDIN I need to do something like this (right?): ./script.pl | echo 1234 That says you want to run script.pl and send the output of script.pl to the process echo 1234. You actually want the other way around: echo 1234 | ./script.pl Or is this nonsensical? Very very new to Perl. Well, this bit in any event has nothing to do with Perl. Input/Output redirection is a feature of the shell, not of Perl. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
library (random numbers)
After some friendly input from yitzle I might have moved further with my library. This is my script. script.pl #!/usr/bin/perl #require 'lib.pl'; @userArray = STDIN; $sum = sumIt(@userArray); print $sum; And this is my library according to yitzle: sub sumIt(@) { my $total = 0; $total += $_ for (@_); return $total; # This line might not be needed... } sub avg(@) { my @arr = @_; my $arrSize = @arr; # scalar(@arr) is the array size - or one less (last index). Double check return simIt(@arr) / $arrSize; } 1; Now either this is wrong or I have no idea how to use it. With STDIN I need to do something like this (right?): ./script.pl | echo 1234 Or is this nonsensical? Very very new to Perl. Thanks Amichai -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: library (random numbers)
On 8/3/07, Amichai Teumim [EMAIL PROTECTED] wrote: snip sub sumIt(@) snip sub avg(@) snip Ack prototypes! They don't do what you think they do. Don't use them until you have read http://library.n0i.net/programming/perl/articles/fm_prototypes and understand it fully. Prototypes are very useful in specific areas and harmful or a waste of your time in all others. Perl 6 is adding formal parameters (which is what people mistake prototypes for), so this will not be a problem in it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
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: Problem with my code
On 8/3/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: snip Whnever you use a composite key, you have the possibility of a collision. snip Okay, I will concede that, but there is generally a character that is safe (usually the character the line was split on). In this case $hash{join ',', @cdr[2,3,6,7]} = $line; is safe due to the fact that @cdr was created using split /,/, so I would recommend that over a multidimensional hash. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Howto strip html from a $calar with HTML::Parser
On 08/03/2007 03:30 AM, Alan C wrote: [...] I do not need to print to STDOUT Is the print @ line in the sub doing this? [...] Yes. Why not append the text to $string instead of printing the text? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
El Aug 3, 2007, a las 1:45 PM, Mr. Shawn H. Corey escribió: But the expression $hash{@cdr[2,3,6,7]} is the same as $hash{join ($,@cdr[2,3,6,7])} You have just replaced one special variable with another and $ is a bad choice since it's default is a space character, which may easily appear in one (or all) of @cdr[2,3,6,7] A better choice is $hash{$cdr[2]}{$cdr[3]}{$cdr[6]}{$cdr[7]} but you would need four for-loops to get to the value. To be able to use arrays as keys there are a couple of modules out there. One is mine, based on pack/unpack : http://search.cpan.org/~fxn/Hash-MultiKey-0.06/MultiKey.pm and there's another one that is implemented as nested hashes, but I can't remember its name right now, does anybody know it? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
On 8/3/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: The use of the special variable $; is not why $foo{$a[1],$a[2],$a[3],$a[4]} is a bad choice; it is a bad choice because it is hard to tell if they meant to use @foo{$a[1],$a[2],$a[3],$a[4]} but screwed up the sigil. The spaces are only important if you want to recover the individual values from the key, and, since you are storing the entire record, you don't even need the key to get those values. Why would you create a nested hash? This does not appear to be a tree data. If you want to do it long hand because you don't want the spaces that using an array slice will add then simply say $hash{{$cdr[2]$cdr[3]$cdr[6]$cdr[7]} #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash1 = (); my %hash2 = (); my $key1 = 'ab'; my $key2 = 'c'; $hash1{$key1$key2} = 'some value'; $hash2{$key1}{$key2} = 'some value'; print \%hash1 = , Dumper \%hash1; print \%hash2 = , Dumper \%hash2; my $key3 = 'a'; my $key4 = 'bc'; $hash1{$key3$key4} = 'some other value'; $hash2{$key3}{$key4} = 'some other value'; print \%hash1 = , Dumper \%hash1; print \%hash2 = , Dumper \%hash2; snip Note that my advice is to use $hash3{@key} Which does not suffer from that problem and that I specifically said you don't want the spaces that using an array slice will add. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
abbreviations
Hi all, I have a text with a lot of abbreviations in it and would like to annotate them. I did it for the shorter ones with $text =~ m/\b\w{0,3}[^IVX]\./g and it works fine. But I would like to get the longer ones as well. The trouble with the long strings ending with a full-stop is that they are usually proper words at the end of the sentence and not abbreviations. So I was thinking of another match that would cover longer strings ending with a full-stop but limiting it with the lowercase beginning of the next word. I've tried the following $text =~ m/\b\w{4,8}[^IVX]\.\s\l/g but it doesn't work - it just gets the words at the end of each sentence. So this \l at the end of the match is wrong. What should I do to make it work? This probably requires some very basic knowledge but since I am an absolute beginner in perl I am asking for your help, best, Petra -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
Chas Owens wrote: Note that my advice is to use $hash3{@key} Which does not suffer from that problem and that I specifically said you don't want the spaces that using an array slice will add. Whnever you use a composite key, you have the possibility of a collision. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash1 = (); my %hash2 = (); my @key1 = ( 'a b', 'c' ); my @key2 = ( 'a', 'b c' ); $hash1{@key1} = 'some value'; $hash1{@key2} = 'some other value'; $hash2{$key1[0]}{$key1[1]} = 'some value'; $hash2{$key2[0]}{$key2[1]} = 'some other value'; print \%hash1 = , Dumper \%hash1; print \%hash2 = , Dumper \%hash2; __END__ -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
Chas Owens wrote: On 8/3/07, Jeff Pang [EMAIL PROTECTED] wrote: -Original Message- From: Mihir Kamdar [EMAIL PROTECTED] $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields if u want. There are (maybe) two problems above. 1. when using hash slice,the form is @hash{'key1','key2'...},not $hash{'key1','key2'...} 2. when you say @hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line,only the first key ($cdr[2]) has got value,the other keys would get undef as their values,since $line is a scalar, but the statement expect a list on the right of '=' I think. I don't think he is trying to use the slice notation. He is using the multidimensional array emulation. This not really a good practice because it is easy to confuse it with slices. A better way to get the same functionality is $hash{@cdr[2,3,6,7]} = $line; The quotes act as a signal that you aren't looking for a slice. from perldoc perlvar $; The subscript separator for multidimensional array emulation. If you refer to a hash element as $foo{$a,$b,$c} it really means $foo{join($;, $a, $b, $c)} But the expression $hash{@cdr[2,3,6,7]} is the same as $hash{join($,@cdr[2,3,6,7])} You have just replaced one special variable with another and $ is a bad choice since it's default is a space character, which may easily appear in one (or all) of @cdr[2,3,6,7] A better choice is $hash{$cdr[2]}{$cdr[3]}{$cdr[6]}{$cdr[7]} but you would need four for-loops to get to the value. -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Sending HTML Email Using EMAIL::MIME::CreateHTML
I am using the Email::MIME:CreateHTML module to send html formatted emails. It all works fine until I try to change the To line to a scalar so that I can mass mail to different individuals. Has anyone used this module in a manner like this before? Thanks, my $email = [EMAIL PROTECTED]; while(DAT) { $line = TRIM($_); $html = $html . $_; if($line eq /body) { my $email = Email::MIME-create_html( header = [ From = '[EMAIL PROTECTED]', To = '$email', Subject = 'Some Subject', ], body = $html, ); my $sender = Email::Send-new({mailer = 'SMTP'}); $sender-mailer_args([Host = 'tiger.georgetowncollege.edu']); $sender-send($email); $html = ; } } close(DAT); Travis Hervey Programmer Analyst Georgetown College 400 East College Street Georgetown KY, 40324 Tel: 1-502-863-8001 Fax: 1-502-686-8884 Email: [EMAIL PROTECTED]
Re: Problem with my code
Chas Owens wrote: The use of the special variable $; is not why $foo{$a[1],$a[2],$a[3],$a[4]} is a bad choice; it is a bad choice because it is hard to tell if they meant to use @foo{$a[1],$a[2],$a[3],$a[4]} but screwed up the sigil. The spaces are only important if you want to recover the individual values from the key, and, since you are storing the entire record, you don't even need the key to get those values. Why would you create a nested hash? This does not appear to be a tree data. If you want to do it long hand because you don't want the spaces that using an array slice will add then simply say $hash{{$cdr[2]$cdr[3]$cdr[6]$cdr[7]} #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash1 = (); my %hash2 = (); my $key1 = 'ab'; my $key2 = 'c'; $hash1{$key1$key2} = 'some value'; $hash2{$key1}{$key2} = 'some value'; print \%hash1 = , Dumper \%hash1; print \%hash2 = , Dumper \%hash2; my $key3 = 'a'; my $key4 = 'bc'; $hash1{$key3$key4} = 'some other value'; $hash2{$key3}{$key4} = 'some other value'; print \%hash1 = , Dumper \%hash1; print \%hash2 = , Dumper \%hash2; __END__ -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
Chas Owens wrote: Okay, I will concede that, but there is generally a character that is safe (usually the character the line was split on). In this case $hash{join ',', @cdr[2,3,6,7]} = $line; is safe due to the fact that @cdr was created using split /,/, so I would recommend that over a multidimensional hash. Safe until the format of the input changes. If, for example, you tried this on a CSV (comma-separated-values) file, it would fail since commas can be escaped. That is why $; is set to the default value of ASCII \034, a non-printable control character that is unlikely to appear in text. But if you have your heart set on a composite key: { local( $ ) = $;; $hash{@cdr[2,3,6,7]} = $line; } -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sending HTML Email Using EMAIL::MIME::CreateHTML
On Fri Aug 3 13:22:11 2007, Travis Hervey wrote: I am using the Email::MIME:CreateHTML module to send html formatted emails. It all works fine until I try to change the To line to a scalar so that I can mass mail to different individuals. Has anyone used this module in a manner like this before? Thanks, my $email = [EMAIL PROTECTED]; while(DAT) { $line = TRIM($_); $html = $html . $_; if($line eq /body) { my $email = Email::MIME-create_html( header = [ From = '[EMAIL PROTECTED]', To = '$email', Subject = 'Some Subject', ], body = $html, ); my $sender = Email::Send-new({mailer = 'SMTP'}); $sender-mailer_args([Host = 'tiger.georgetowncollege.edu']); $sender-send($email); $html = ; } } close(DAT); get rid of the single quotes around $email. a variable inside single quotes is just text. a variable inside double quotes will do what you expect. d. -- == $mysig = EOS; while(1){ } daniël [EMAIL PROTECTED], [EMAIL PROTECTED] http://0x64.nl gmail talk: devogon EOS pgpaKxSuqDP50.pgp Description: PGP signature
Re: Problem with my code
On 8/3/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: Okay, I will concede that, but there is generally a character that is safe (usually the character the line was split on). In this case $hash{join ',', @cdr[2,3,6,7]} = $line; is safe due to the fact that @cdr was created using split /,/, so I would recommend that over a multidimensional hash. Safe until the format of the input changes. If, for example, you tried this on a CSV (comma-separated-values) file, it would fail since commas can be escaped. That is why $; is set to the default value of ASCII \034, a non-printable control character that is unlikely to appear in text. But if you have your heart set on a composite key: { local( $ ) = $;; $hash{@cdr[2,3,6,7]} = $line; } snip They composite key breaks at the same time as the split, so both would need to be modified and \034 isn't any safer. It all depends on your data. Also, the short cut of using @cdr[2,3,6,7] is pointless if you aren't going to use the default value of $, it is shorter to type $hash{join \034, @cdr[2,3,6,7]} = $line; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: VMWARE PERL API
On 8/3/07, vishnu [EMAIL PROTECTED] wrote: snip I think this stuff is going a bit complicated.. please give my some links on perl concepts. i have fome pdf files from perk.org.. but they are a bit basic and not deep into such things. please refer dome books that might by of some use to me :) snip Programming Perl (the Camel): http://www.oreilly.com/catalog/pperl3/ Perl Best Practices: http://www.oreilly.com/catalog/perlbp/index.html Object Oriented Perl: http://www.manning.com/conway/ Higher-Order Perl: http://hop.perl.plover.com/ And, of course, the perldocs themselves (see perldoc perl or http://perldoc.perl.org/) snip can u explain this part in detail if (-x $perl_binary) { $ENV{'VMWARE_PERL_NESTED_EXEC'} = 1; exec $perl_binary, '-I'.$libdir.'/perl5/site_perl/5.005',$0, @ARGV; } snip -x is a file test operator, it test to see if the file exists and is executable. So this is making sure it can execute the file whose name is in $perl_binary. %ENV is a hash that holds the current state of the environment. Changing a value in the hash changes the environmental variable associated with it. So this is setting the environmental variable VMWARE_PERL_NESTED_EXEC to 1. exec is a function that replaces the currently running process with the one specified. $0 is the name of the currently running script @ARGV are the arguments to the script So this is replacing the current version of the Perl interpreter with the one specified in the VMWare config file. It is probable, but I am not certain, that the VMWARE_PERL_NESTED_EXEC environmental variable is there to prevent infinite recursion. Now, why VMWare needs it's version of Perl instead of the system copy is a mystery to me. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: VMWARE PERL API
On 8/3/07, Chas Owens [EMAIL PROTECTED] wrote: On 8/3/07, vishnu [EMAIL PROTECTED] wrote: snip I think this stuff is going a bit complicated.. please give my some links on perl concepts. i have fome pdf files from perk.org.. but they are a bit basic and not deep into such things. please refer dome books that might by of some use to me :) snip Programming Perl (the Camel): http://www.oreilly.com/catalog/pperl3/ Perl Best Practices: http://www.oreilly.com/catalog/perlbp/index.html Object Oriented Perl: http://www.manning.com/conway/ Higher-Order Perl: http://hop.perl.plover.com/ And, of course, the perldocs themselves (see perldoc perl or http://perldoc.perl.org/) snip can u explain this part in detail if (-x $perl_binary) { $ENV{'VMWARE_PERL_NESTED_EXEC'} = 1; exec $perl_binary, '-I'.$libdir.'/perl5/site_perl/5.005',$0, @ARGV; } snip -x is a file test operator, it test to see if the file exists and is executable. So this is making sure it can execute the file whose name is in $perl_binary. %ENV is a hash that holds the current state of the environment. Changing a value in the hash changes the environmental variable associated with it. So this is setting the environmental variable VMWARE_PERL_NESTED_EXEC to 1. exec is a function that replaces the currently running process with the one specified. $0 is the name of the currently running script @ARGV are the arguments to the script So this is replacing the current version of the Perl interpreter with the one specified in the VMWare config file. It is probable, but I am not certain, that the VMWARE_PERL_NESTED_EXEC environmental variable is there to prevent infinite recursion. Now, why VMWare needs it's version of Perl instead of the system copy is a mystery to me. Yes, the VMWARE_PERL_NESTED_EXEC is there to stop it from recursing forever, but your code does not seem to be using it. It appears as if VMWare wants to use its version of perl instead of the systems version. This will probably cause problems for you since VMWare's version is 5.005_03, and the current version is 5.8.8. There are lots of things that have been added in the eight years since 5.005_03 was released and if you ask questions on this list you will probably be told to do things like open my $fh, '', '/etc/vmware/config' or die could not open /etc/vmware/config:$!; But that form of open was added in Perl 5.6 (I think) and you will not be able to use it. If you are paying for VMWare support I would suggest opening a trouble ticket and asking why they are using such an old version of Perl. #!/usr/bin/perl print running\n; unless ($ENV{'VMWARE_PERL_NESTED_EXEC'}) { open CONFIG, '/etc/vmware/config' or die could not open config file:$!; my $libdir; my $line; while (defined($line = CONFIG)) { chomp $line; if ($line =~ /^\s*libdir\s*=\s*\(.*)\\s*$/) { $libdir = $1; last; } } close CONFIG; if (defined($libdir)) { my $perl_binary = $libdir . '/perl5/bin/perl'; if (-x $perl_binary) { $ENV{'VMWARE_PERL_NESTED_EXEC'} = 1; exec $perl_binary, '-I'.$libdir.'/perl5/site_perl/5.005', $0, @ARGV; } } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Problem with my code
On Aug 3, 6:54 am, [EMAIL PROTECTED] (Mihir Kamdar) wrote: I appreciate your comments and have tried to make changes as per your suggestions. Plz have a look at the below and comment if any further changes are required. This is turning out to be a good learning for me. Most of the things I would point out have already been mentioned in this thread but here are a couple I haven't noticed. #!/usr/bin/perl -w The -w switch has now been replaced with use warnings; Unless compatibility with old versions of Perl is an issue you should use the new version. You should also use strict; unless (exists $times{$file}){ Nothing ever sets anything into %times so that condition is always false. Unless you are actually expecting %times to contain false values then it's more idiomatic to omit the exists() my $line; You are still have a very minor case of premature declaration. my %hash; opendir my $dh1,$parent_path or die $!; open (my $IN_FILE,,$parent_path/$file) or die $!. Parent file not found for $parent_path/$file; while ($line=readline($IN_FILE)) { my @cdr=split (/,/, $line) ; $hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields if u want. } close $IN_FILE ; closedir $dh1 ; open (my $OUT_FILE,,$write_path/$file.out) or die $!; while (my($key, $value) = each %hash) { print $OUT_FILE $value; } close $OUT_FILE; If you are not bothering to checking the return value of close() then you may as well simply omit the explicit close() if the handle is about to go out of scope anyhow. This applies to all close() and closedir() in your script. } BTW: Your indentation is a bit random. In small programs like this it's not much of an issue. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
automatically open ports
Im not sure where to post this as Im really looking for the functionality not specifically that it have to be in the perl language. How would I make something that would automatically open the correct ports for a certain machine without my having to be at the machine goto 192.168.1.1 in a browser and open the ports manually? Can this be done easily? Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: automatically open ports
On Fri, 2007-08-03 at 15:49 -0700, [EMAIL PROTECTED] wrote: Im not sure where to post this as Im really looking for the functionality not specifically that it have to be in the perl language. How would I make something that would automatically open the correct ports for a certain machine without my having to be at the machine goto 192.168.1.1 in a browser and open the ports manually? Can this be done easily? I don't understand what you want. a) Do you want a process to be brought up at boot or automatically when the port is addressed b) You would like a system that is somehow brought up and closed automatically before and after use? -- Ken Foskey FOSS developer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: automatically open ports
-Original Message- From: [EMAIL PROTECTED] Sent: Aug 4, 2007 6:49 AM To: beginners@perl.org Subject: automatically open ports Im not sure where to post this as Im really looking for the functionality not specifically that it have to be in the perl language. How would I make something that would automatically open the correct ports for a certain machine without my having to be at the machine goto 192.168.1.1 in a browser and open the ports manually? Can this be done easily? I don't know what's your intent for this.Do you mean when there's a connection to this host,it should open a port to accept the connection,at other time it shouldn't open that port?AFAIK,this is impossible.Though using some tools like PF port forwarding or LVS,you can't see the ports opened on a host but they are really on there,it's nothing you wanted here. Instead you can always open a port on the host and accept the connection,but use firewall (like iptables) to filter the info you wanted and drop the info you unwanted. Opening a port generally need to build a socket server.In perl it's easy to do,see 'perldoc IO::Socket' for the description. -- Jeff Pang [EMAIL PROTECTED] http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: XML to inMemory Hash
Hi All, Thanks for the valuable inputs, I am planning to solve my memory issue by making the XML into Chunks using Xml::Twig and using simplify( ) in XML::Twig to convert that chunks back into the Hash data structure. Is that advicable method to proceed to reduce my Memory size.So that after processing that chunk i will purge my memory (purge in XML::Twig) Thanks in advance, Prabu Jenda Krynicky [EMAIL PROTECTED] wrote: From: Rob Dixon Prabu Ayyappan wrote: I want to convert a huge XML file into an inMemory Hash. I tried using XML::Simple. But its taking huge memory space and time to convert it into Hash. While loading a XML file of 300MB its taking more memory space and time. Is there any better method to load this XML to memory ? Is there any benchmarks available ? If your file is huge and you want it in memory then you must expect it to take take a while to parse and occupy a huge memory space. Almost anything is better than XML::Simple, but no module can easily make your data any smaller. Actually not. Almost any other module that parses the whole file and then gives you the data will take up more memory. XML::Simple ignores a lot of the details that it thinks are unimportant and produces a farily minimal structure with no links to siblings, no complex blessed structures etc. You'd need to use something that gives you more control over the generated structure, so that you can skip unimportant tags and attributes etc. (Yeah, shameless plug. XML::Rules) You should reassess your solution to see if you can work with only part of the data in memory. I suggest you look at XML::Twig for processing XML in chunks. Agreed. If you can work in chunks you'd definitely need much less memory. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ - Pinpoint customers who are looking for what you sell.
Re: Howto strip html from a $calar with HTML::Parser
Thanks for the replies. I've added them to my searchable data. My forgetfullness worsens as I get older. I'd totally forgotten that I'd once done this with HTML::Strip And I began reinventing the wheel the other day. Lynx too, forgot about that (Slackware 12.0 right now). Anyways, here's a more featured weather prog. that I'd written a while back but had forgotten about the other day. It's for weather. Prints both the current conditions and the current forecast. Makes use of the clweather app at http://freshmeat.net/projects/clweather/ Does some (I think) interesting things using the DateTime module. Also uses HTML::Strip Uses LWP Uses Text::Autoformat -- #!/usr/bin/perl -w use strict; use DateTime; # Alan_C with help from others on portions herein # locate station 4 letter identifiers # http://www.nws.noaa.gov/tg/siteloc.shtml # at next url, scroll to bottom, finds text_only_forecast # http://www.wrh.noaa.gov/total_forecast/index.php?wfo=stozone=caz017county=cac067 # ftp://weather.noaa.gov/data/observations/state_roundup/ca/caz017.txt # ftp://weather.noaa.gov/data/observations/metar/decoded # ftp://weather.noaa.gov/data/observations/metar/stations # http://weather.noaa.gov/cgi-bin/mgetmetar.pl?=KSAC # Sac area by zone hazard/warnings # http://www.wrh.noaa.gov/warnings.php?wfo=stozone=CAZ017pil=XXXHWOSTOproductType=HAZARDOUS%20WEATHER%20OUTLOOK # Pismo, San Luis forecast # http://www.wrh.noaa.gov/total_forecast/text_only.php?wfo=loxzone=caz034fire=county=cac079dgtl=1lat=35.14278lon=-120.64028 my $url_4cast = ' http://www.wrh.noaa.gov/total_forecast/text_only.php?wfo=stozone=caz017fire=county=cac067dgtl=lat=38.51000lon=-121.4900 '; print STUF; clweather -s KSAC (default if none/nothing specified/entered) clweather -s (see stn list, enter 4 letter code) KSMF Sac Metro || KMHR Mather || KSAC Sac executive KOXR || KSBP San Luis Obispo, Pismo Beach 1 weather SAC (Slack expect script) STUF print \nenter (nothing) OR a 4 letter stn code OR a 1: ; chomp(my $wthr_choice = STDIN); print \n; unless ($wthr_choice) { $wthr_choice = 'KSAC'; } if ($wthr_choice =~ /[A-Z]{4}|[A-Z]{2}\d\d/) { # system(clweather -s $wthr_choice); my @report = `clweather -s $wthr_choice`; foreach ( @report ) { last if /^ob/i; print unless /\/ \d{4}\.\d{2}.\d{2} \d{4} UTC/; if (/\/ \d{4}\.\d{2}.\d{2} \d{4} UTC/) { my $utc_line = $_; $utc_line =~ s/^.+\/ \d{4}\.//; $utc_line =~ s/(\d{2})\.(\d{2}) (\d{2})(\d{2}) UTC/$1 $2 $3 $4/; chomp($utc_line); # (substitution) (no match nothing happens) if string begins with 1 instead of 0 $utc_line =~ s/^0//; my @parsed_utc_fields = split(/ /,$utc_line); my $source = DateTime-new(year = 2006, month = $parsed_utc_fields[0], day = $parsed_utc_fields[1], hour = $parsed_utc_fields[2], minute = $parsed_utc_fields[3], time_zone = 'UTC'); my $result = $source-clone() -set_time_zone( 'America/Los_Angeles' ); # print $source-strftime(%F %r %Z), \n, #$result-strftime(%F %r %Z), - Sacto, CA - * |\n; print $result-strftime(%F %r %Z), \/ , $_; # print $utc_line\n; # print yes matched\n; # print [EMAIL PROTECTED]; } } #print @report; print STUFF; [ summer UTC - 7 || EDT -2 ] [ winter UTC - 8 || EDT -3 ] STUFF $wthr_choice = 9; # print `lynx -dump $url_4cast`; use LWP::UserAgent; #: bin/lwp_dwnld download get www lwp slack changelog my $ua = LWP::UserAgent-new(); # my $url = 'http://0daycheck.eastgame.net/0day/archives/20060901.html'; # my $url = 'http://www.slackware.com/changelog/current.php?cpu=i386'; my $response = $ua-get( $url_4cast ); $response-is_success or $response-code == 404 # ignore 404 or die Can't get '$url_4cast': , $response-status_line; # print $response-content; my $raw_html = $response-content; # $raw_html =~ s/\n+/\n/g; $raw_html =~ s/\br\/\n/gi; # print $raw_html; use HTML::Strip; my $hs = HTML::Strip-new(); my $clean_text = $hs-parse( $raw_html ); $hs-eof; # $clean_text =~ s/\n+/\n/g; # print $clean_text; my $line_quantity = 24; # desired number of lines my @lines = split(/\n/, $clean_text); # print scalar( @lines ); my $curr_line = '0'; my ($stop_at, $post); foreach ( @lines ) { $curr_line++; # print $curr_line $_\n if /ChangeLog for Intel/; if ( /^Area Forecast For/i ) { $stop_at = $curr_line + $line_quantity; } next unless $stop_at; s/(^.{2})/\.$1/ unless /^Area Forecast For|^Issued/i; $post .= $_\n if $curr_line = $stop_at; } # print $post; use Text::Autoformat qw(autoformat); my $post_formatted; $post_formatted = autoformat($post, {left=0, right=72, all=1}); $post_formatted =~ s/\n+/\n/g; print $post_formatted, \n; } if ($wthr_choice == 1) { # system(weather SAC); #my @weather = `weather SAC`; #foreach my $line (@weather) { #STDIN = `weather SAC`; #while (STDIN) { my $pid; my $readme; $pid = open $readme, -|, weather, SAC or die cant fork: $!\n; print pid is: $pid\n;