perl module for graphs lines point
Hi , Is there a perl module to plot graphs with lines point. Thanks, -Bandeep
Re: Problem with parsing csv file and writing into two separate files
Hi Lauri, Lauri Nikkinen wrote: I would like to parse a .csv file and write certain records into two separate files. The program below writes the records easily into the csvtmp.csv but the second file is only created with no records written. I cannot see the problem here, the second file is produced easily if the first loop is discarded. Any ideas? Thanks. -L == #!/bin/perl use warnings; use strict; use Text::CSV_XS; use Tie::Handle::CSV; my $fh = Tie::Handle::CSV->new(csv_parser => Text::CSV_XS->new({binary => 1}), file => 'rek.csv', header => 1); #Write into the first file my $outfile = 'csvtmp.csv'; open (OUTFILE, ">", $outfile) or die $!; while (my $csv_line = <$fh>) { print OUTFILE $csv_line->{'Name'} . ": " . $csv_line->{'Surname'} . "\n"; } From what I can tell, in your first loop, you are reading in from the input file and exhaust the input file (reached End-of-File [EOF]) to leave this while loop. So, when you enter the second while loop (which comes after and I have cut), the input file has been exhausted and there is nothing to do. if you want to read again with the second while loop, you can either: 1) close the file handle ($fh) and re-open it 2) Seek to the beginning of the file between the two while loops (http://perldoc.perl.org/functions/seek.html) 3) Open it once, read all the lines into a buffer and then use that buffer (an array, etc.) to output it to your two output files. And I'm sure there are many other options available... Ray -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Problem with parsing csv file and writing into two separate files
Hello, I would like to parse a .csv file and write certain records into two separate files. The program below writes the records easily into the csvtmp.csv but the second file is only created with no records written. I cannot see the problem here, the second file is produced easily if the first loop is discarded. Any ideas? Thanks. -L == #!/bin/perl use warnings; use strict; use Text::CSV_XS; use Tie::Handle::CSV; my $fh = Tie::Handle::CSV->new(csv_parser => Text::CSV_XS->new({binary => 1}), file => 'rek.csv', header => 1); #Write into the first file my $outfile = 'csvtmp.csv'; open (OUTFILE, ">", $outfile) or die $!; while (my $csv_line = <$fh>) { print OUTFILE $csv_line->{'Name'} . ": " . $csv_line->{'Surname'} . "\n"; } close OUTFILE; #Write into the second file my $outfile2 = 'csvtmp2.csv'; open (OUTFILE2, ">", $outfile2) or die $!; while (my $csv_line = <$fh>) { if ($csv_line->{'Company'} =~ m/Middle./) { print OUTFILE2 $csv_line->{'Surname'} . ": " . $csv_line->{'Company'} . "\n"; } } close OUTFILE2; close $fh; == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: problem with Net::SSH::Perl
On Mon, Nov 17, 2008 at 13:42, monnappa appaiah <[EMAIL PROTECTED]> wrote: > Hi All, > > I wanted to write a script which could login into the server and > execute a command and return the output for that i used "Net::SSH::Perl" > module > > but when i run the script (i'm running on the windows machine) i'm getting > this error "The getpwuid function is unimplemented at > C:/Perl/site/lib/Net/SSH/Perl.pm line > 110. > Press any key to continue . . ." > > can someone tell me what this error means and what shud i do to make this > script work.find my code below > > > #!/usr/bin/perl -w > use strict; > use Net::SSH::Perl; > > my $host = "10.10.10.5"; > my $user = "user1"; > my $password = "pass1"; > > my $ssh = Net::SSH::Perl->new($host); > $ssh->login($user, $password); > my ($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$user"); > print "$stdout\n"; > > > Thanks, > Monnappa > Sounds like you are on MS Windows. Take a look at this thread: http://www.perlmonks.org/?node_id=613394 -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Two questions about split and map in a cookbook recipe
Telemachus wrote: On Mon Nov 17 2008 @ 10:21, John W. Krahn wrote: Set paragraph mode. while (<>) { Read a paragraph into $_. In your example a paragraph is: " field:value field:value field:value " my @fields = split /^([^:]+):\s*/m; Since there are multiple lines in a paragraph they use /^/m to work on one line at a time. That pattern splits into three fields, the field before '([^:]+):\s*', which will be '' for the first line, the field enclosed in parentheses '[^:]+', and the field after '([^:]+):\s*'. shift @fields; The first field is always empty so remove it. push(@Array_of_Records, { map /(.*)/, @fields }); Store the fields as a hash at the end of @Array_of_Records. The filter /(.*)/ ensures that no newlines are included in the keys or values of the hash. Thanks for your careful explanation. I was just in the process of writing that I had worked out that the map keeps newlines out. I'll push my luck and ask two further questions. First, what exactly is the "null field" at the start of my first line, or where does it come from? split always (unless the third argument is 1) splits into at least two fields. If you have the string $x = ':' then split( /:/, $x, -1 ) will return the two strings '' and '' (zero length strings). In the version you wrote of my data, you visualized it with a space, *NO*, I did not use a space, that was two quotes with nothing in between. but it's not (normally) visible. (This may just be something very simple about computers and how they represent text that I don't know.) Second, if I know that my records only have newlines at the end of lines is there any larger advantage to using the map construct above instead of simply chomp @fields? TIMTOWTDI See my example at the end of the post. chomp() removes the value of the $/ variable and since the value of the $/ variable was changed in the example it wouldn't do what you expected for chomp @fields. (One advantage of chomp for me is that I'm in no danger of misunderstanding it later.) John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Two questions about split and map in a cookbook recipe
On Mon, Nov 17, 2008 at 13:21, John W. Krahn <[EMAIL PROTECTED]> wrote: snip >> push(@Array_of_Records, { map /(.*)/, @fields }); > > Store the fields as a hash at the end of @Array_of_Records. The filter > /(.*)/ ensures that no newlines are included in the keys or values of the > hash. snip Huh, that is nifty, I always end up writing something like push @a, { map { chomp; $_ } @fields }; and being dissatisfied with the verbosity. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
problem with Net::SSH::Perl
Hi All, I wanted to write a script which could login into the server and execute a command and return the output for that i used "Net::SSH::Perl" module but when i run the script (i'm running on the windows machine) i'm getting this error "The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Perl.pm line 110. Press any key to continue . . ." can someone tell me what this error means and what shud i do to make this script work.find my code below #!/usr/bin/perl -w use strict; use Net::SSH::Perl; my $host = "10.10.10.5"; my $user = "user1"; my $password = "pass1"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $password); my ($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$user"); print "$stdout\n"; Thanks, Monnappa
Re: Two questions about split and map in a cookbook recipe
On Mon Nov 17 2008 @ 10:21, John W. Krahn wrote: > Set paragraph mode. > >> while (<>) { > > Read a paragraph into $_. In your example a paragraph is: > > " field:value > field:value > field:value > > " > >> my @fields = split /^([^:]+):\s*/m; > > Since there are multiple lines in a paragraph they use /^/m to work on > one line at a time. That pattern splits into three fields, the field > before '([^:]+):\s*', which will be '' for the first line, the field > enclosed in parentheses '[^:]+', and the field after '([^:]+):\s*'. > > >> shift @fields; > > The first field is always empty so remove it. > > >> push(@Array_of_Records, { map /(.*)/, @fields }); > > Store the fields as a hash at the end of @Array_of_Records. The filter > /(.*)/ ensures that no newlines are included in the keys or values of > the hash. Thanks for your careful explanation. I was just in the process of writing that I had worked out that the map keeps newlines out. I'll push my luck and ask two further questions. First, what exactly is the "null field" at the start of my first line, or where does it come from? In the version you wrote of my data, you visualized it with a space, but it's not (normally) visible. (This may just be something very simple about computers and how they represent text that I don't know.) Second, if I know that my records only have newlines at the end of lines is there any larger advantage to using the map construct above instead of simply chomp @fields? (One advantage of chomp for me is that I'm in no danger of misunderstanding it later.) Thanks again, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Two questions about split and map in a cookbook recipe
Telemachus wrote: Good morning, Hello, I'm using a recipe from The Perl Cookbook (11.10 for anyone browsing at home) to produce a record structure from items in a text file. The text file itself has a simple structure: field:value field:value field:value field:value field:value etc. That is, the records are separated by a blank line and they contain key/value pairs, joined by a colon. The code I'm working with is this: $/ = ""; Set paragraph mode. while (<>) { Read a paragraph into $_. In your example a paragraph is: " field:value field:value field:value " my @fields = split /^([^:]+):\s*/m; Since there are multiple lines in a paragraph they use /^/m to work on one line at a time. That pattern splits into three fields, the field before '([^:]+):\s*', which will be '' for the first line, the field enclosed in parentheses '[^:]+', and the field after '([^:]+):\s*'. shift @fields; The first field is always empty so remove it. push(@Array_of_Records, { map /(.*)/, @fields }); Store the fields as a hash at the end of @Array_of_Records. The filter /(.*)/ ensures that no newlines are included in the keys or values of the hash. } It works well to produce an array of hashes, and I can manipulate it from there without trouble. However, I want to understand this section better. First question: why does the split command produce a leading null field? (My best guess is that the regex [^:]+ captures anything that is not a colon, and that includes a null field?!?) Second question: what is the map doing in the last line, and why is it written with // delimiters? (Best guess, it is including everything from fields within parentheses (forcing the items to be treated as a list?) and you can't use {} because of the outer {} to create the hash reference?!?) Sorry if this is very long. I wanted to make sure to include enough information to make the questions clear. Another way to the same thing would be: $/ = ""; while (<>) { push @Array_of_Records, { /^([^:]+):\s*(.*)/mg }; } John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: can you substitute equation with variable?
On Mon, Nov 17, 2008 at 11:04, Richard Lee <[EMAIL PROTECTED]> wrote: snip > but I am suprised that perl doesn't have neutral equator.. How would you suggest it handle my $boolean = " 123 " magic_smart_compare "123"; string compare is false numeric compare is true both look like numbers to looks_like_number both have a string value set (i.e. a SVpv value) and no numeric value set (i.e. no SViv or SVnv values) There is no way Perl can decided what to do; it doesn't have enough information. This is why you must choose how you are going to compare the values. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: algorithm permute
On Mon, Nov 17, 2008 at 10:13 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: >> >> You haven't installed anything. You've downloaded and untarred/ >> gunzipped the source. You still have to run >> perl Makefile.PL >> make >> make test >> make install >> >> That final command will copy the installed module to the real library >> directory. THAT is the path that you need for use lib. >> >> perldoc perlmod >> for more information >> >> Paul Lalli > > I would like to rewind a bit and see why this could be happening. I am > really curious about this. > As I mentioned in my original mail, a working file stopped all of a sudden. > Now I have 3 terminals open. All 3 are on same machine .. > > I have done uname -a to confirm this. > In 2 terminals, the script errors out with: > perl StTrAuto.pl > Can't locate Algorithm/Permute.pm in @INC (@INC contains: > /u/basappas/local/perl/perm_install/lib/perl5/site_perl > /hwnet/activestate/perl-5.6/lib/5.6.1/i686-linux-thread-multi > /hwnet/activestate/perl-5.6/lib/5.6.1 > /hwnet/activestate/perl-5.6/lib/site_perl/5.6.1/i686-linux-thread-multi > /hwnet/activestate/perl-5.6/lib/site_perl/5.6.1 > /hwnet/activestate/perl-5.6/lib/site_perl .) at StTrAuto.pl line 5. > BEGIN failed--compilation aborted at StTrAuto.pl line 5. > > On the 3 rd terminal, it works fine. > > The machine is same, the script is same. What about user? You clearly have different configurations for the different sessions, the question is why. I've seen two different user names appear in the @INC and use lib paths you you've posted to the group. My suspicion is that you've installed the module as one user, but then tried to run the script as another. since you're installing the modules to local directories as an unprivileged user rather than the to global perl /lib directories as a superuser, you're having path and permissions issues. It also appears that you have installed the Algorithm::Permute module for the default Perl 5.8.5 installation on your machine, but your problematic scripts are invoking an Active State Perl 5.6 that you have installed in a non-standard location. If you're going to use multiple versions of Perl on the same machine, you need to be very careful about choosing the right combination of interpreters and modules for each script. 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.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: can you substitute equation with variable?
Chas. Owens wrote: On Mon, Nov 17, 2008 at 04:47, Richard Lee <[EMAIL PROTECTED]> wrote: but it would only be worthwhile if you used $compare a lot after setting it once; otherwise it would be simpler to just say sub compare { my ($x, $y) = @_; return looks_like_number($x) ? $x == $y : $x eq $y; } Hi Chas, This is nice and I will try it... but I am suprised that perl doesn't have neutral equator.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: algorithm permute
On Mon, Nov 17, 2008 at 7:13 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > On the 3 rd terminal, it works fine. So, on the third terminal, you can ask it which module it is finding that the others aren't: perldoc -l Algorithm::Permute > I ran "env" and redirected output to a file from 2 terminals. There > are lot of differences. PERL5LIB, perhaps? You can use that environment variable to try out a module without installing it "for real". Another one to check is PATH; you could be using a different perl binary without realizing it. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Two questions about split and map in a cookbook recipe
Good morning, I'm using a recipe from The Perl Cookbook (11.10 for anyone browsing at home) to produce a record structure from items in a text file. The text file itself has a simple structure: field:value field:value field:value field:value field:value etc. That is, the records are separated by a blank line and they contain key/value pairs, joined by a colon. The code I'm working with is this: $/ = ""; while (<>) { my @fields = split /^([^:]+):\s*/m; shift @fields; push(@Array_of_Records, { map /(.*)/, @fields }); } It works well to produce an array of hashes, and I can manipulate it from there without trouble. However, I want to understand this section better. First question: why does the split command produce a leading null field? (My best guess is that the regex [^:]+ captures anything that is not a colon, and that includes a null field?!?) Second question: what is the map doing in the last line, and why is it written with // delimiters? (Best guess, it is including everything from fields within parentheses (forcing the items to be treated as a list?) and you can't use {} because of the outer {} to create the hash reference?!?) Sorry if this is very long. I wanted to make sure to include enough information to make the questions clear. Thanks in advance, Telemachus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: algorithm permute
> > You haven't installed anything. You've downloaded and untarred/ > gunzipped the source. You still have to run > perl Makefile.PL > make > make test > make install > > That final command will copy the installed module to the real library > directory. THAT is the path that you need for use lib. > > perldoc perlmod > for more information > > Paul Lalli I would like to rewind a bit and see why this could be happening. I am really curious about this. As I mentioned in my original mail, a working file stopped all of a sudden. Now I have 3 terminals open. All 3 are on same machine .. I have done uname -a to confirm this. In 2 terminals, the script errors out with: perl StTrAuto.pl Can't locate Algorithm/Permute.pm in @INC (@INC contains: /u/basappas/local/perl/perm_install/lib/perl5/site_perl /hwnet/activestate/perl-5.6/lib/5.6.1/i686-linux-thread-multi /hwnet/activestate/perl-5.6/lib/5.6.1 /hwnet/activestate/perl-5.6/lib/site_perl/5.6.1/i686-linux-thread-multi /hwnet/activestate/perl-5.6/lib/site_perl/5.6.1 /hwnet/activestate/perl-5.6/lib/site_perl .) at StTrAuto.pl line 5. BEGIN failed--compilation aborted at StTrAuto.pl line 5. On the 3 rd terminal, it works fine. The machine is same, the script is same. I ran "env" and redirected output to a file from 2 terminals. There are lot of differences. By now, I am pretty sure this is the cause for the script failing. But there are so many differences I am not able to make out what variable is causing script to konk. Regards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: can you substitute equation with variable?
On Mon, Nov 17, 2008 at 04:47, Richard Lee <[EMAIL PROTECTED]> wrote: > say something like == or eq .. > > Can you sub them w/ varilable like $unknown ? > > Let me be more specific. > Let's say I don't know what the variable will hold > > I guess I can say something like, > > sub check_unknown { > my $unknown = shift; ## it's either digits or letters but both will > be same kind > my $unknown1 = shift; ## it's either digits or letters > > my $result = ( $unknown =~ /^\d+$/ ) ? '==' : 'eq'; > if ( $unknown $result $unknown1 ) { >do something... > } > } > > But obviously above dont work.. can someone shed some light on this? > > thanks! Well, you could say something like this #!/usr/bin/perl use strict; use warnings; use Scalar::Util qw/looks_like_number/; sub compare { my ($x, $y) = @_; my $compare = looks_like_number($x) ? sub { shift == shift } : sub { shift eq shift }; return $compare->($x, $y); } print join(" :: ", compare("x", "y"), compare("x", "x"), compare("5", "6"), compare("5", "5"), compare("0", "x"), ), "\n"; but it would only be worthwhile if you used $compare a lot after setting it once; otherwise it would be simpler to just say sub compare { my ($x, $y) = @_; return looks_like_number($x) ? $x == $y : $x eq $y; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
can you substitute equation with variable?
say something like == or eq .. Can you sub them w/ varilable like $unknown ? Let me be more specific. Let's say I don't know what the variable will hold I guess I can say something like, sub check_unknown { my $unknown = shift; ## it's either digits or letters but both will be same kind my $unknown1 = shift; ## it's either digits or letters my $result = ( $unknown =~ /^\d+$/ ) ? '==' : 'eq'; if ( $unknown $result $unknown1 ) { do something... } } But obviously above dont work.. can someone shed some light on this? thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/