Re: Need to check file
sigh.. so sorry for not being more exact... I did use the quotes if (-e 'filename.dat') I guess I will have to find out the full path... Thanks Lou - Original Message - From: Bee [EMAIL PROTECTED] To: Luinrandir Hernsen [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, October 14, 2004 4:54 PM Subject: Re: Need to check file I have successfully checked a file in the same dir , my question is do I have to chdir when doing a if (-e filename.dat) I don't think you will get success without a quote for 'filename.dat'. It could be the return value for sub filename concating sub dat, be nothing. I tried looking for files in other dirs using if (-e .../html) etc.. but with no success. By giving the full path ( not url ) of the file, you will get your job done without chdir. HTH, Bee -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RegExp
Mandar Rahurkar wrote: Hi, Hello, I have a bunch of text (multiple paragraphs). I want to find a sentence like 'Susan * the water' (No its not a HW problem). Here's what I am doing: #! /usr/bin/perl use strict; use warnings; $file=temp.txt; my $file = 'temp.txt'; open(fp,$file) or die Cant open $file :$!\n; open(FP,$file) or die Can not open $file : $!\n; local $/=; why ?? while (fp) { while(FP) { while( /(susan)(\D+)[the|water]\b/xig ) { print $1 $2\n } } this catches sentences like: susan swam in the water for long time whereas i wud like susan swam in the water What am i doing wrong ? (\D+) matches more than you expect. What do you mean in Susan * the water with the *? A word with no digits? Try /(susan)\s+([a-zA-Z]+)\s+the water/ Mayeb if your a bit more descriptive of what you are trying to get HTH :) Lee.M - JupiterHost.Net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
how to assign an external command aoutput to an array
I have to assign output of ssh [EMAIL PROTECTED] sar -u 1 1|awk '/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }' to an array. The output looks like: 0 0 0 100 if I did: my @pippo=qx'ssh [EMAIL PROTECTED] sar -u 1 1|awk \'/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }\''; it assigns the entire output to $pippo[0] instead of to give each number in output to a differenet array element. Please can you give me any hints? Thank You -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how to assign an external command aoutput to an array
Ok Ok i found solution: my $got_value=qx'.'; my @values=split / /,$got_value: Thank You - Original Message - From: Mauro [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, October 15, 2004 9:23 AM Subject: how to assign an external command aoutput to an array I have to assign output of ssh [EMAIL PROTECTED] sar -u 1 1|awk '/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }' to an array. The output looks like: 0 0 0 100 if I did: my @pippo=qx'ssh [EMAIL PROTECTED] sar -u 1 1|awk \'/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }\''; it assigns the entire output to $pippo[0] instead of to give each number in output to a differenet array element. Please can you give me any hints? Thank You -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
ntlm auth
Hi all, I changed my work, I'm behind MS proxy, I need authenticate on our proxy (NTLM). But I can't get it to work: use LWP::Debug qw(+); use LWP::UserAgent; use HTTP::Request::Common; my $url = 'http://www.google.com'; # Set up the ntlm client and then the base64 encoded ntlm handshake message my $ua = new LWP::UserAgent(keep_alive=1); my $proxy = '10.1.1.3:8080'; my $user = 'xxx'; my $pass = 'yyy'; $ua-credentials($proxy, '', $user, $pass); $ua-agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; iOpus-I-M; .NET CLR 1.1.4322)'); $request = GET $url; print --Performing request now...---\n; $response = $ua-request($request); print --Done with request---\n; if ($response-is_success) {print It worked!- . $response-code . \n} else {print It didn't work!- . $response-code . \n} = I always get: LWP::UserAgent::new: () --Performing request now...--- LWP::UserAgent::request: () LWP::UserAgent::send_request: GET http://www.google.com LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::UserAgent::request: Simple response: Internal Server Error --Done with request--- It didn't work!-500 = I am on the intranet with no domain, I am in workgroup MDI Any help on this ? Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ntlm auth
Ing. Branislav Gerzo [IBG], on Friday, October 15, 2004 at 10:45 (+0200) typed: IBG I changed my work, I'm behind MS proxy, I need authenticate on our IBG proxy (NTLM). But I can't get it to work: I tried 'NTLM Authorization Proxy Server' v.0.9.7. ( http://www.geocities.com/rozmanov/ntlm/ ) it works great with Opera browser, and also with my perl scripts, I just set proxy like this: $ua-proxy(http = 'http://localhost:5865'); and everything is fine. :) -- ...m8s, cu l8r, Brano. [Liberal Tactic #9: If you can't refute the message, attac] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
IO::Socket - i can't get it to read the data
greetings, This program listens on a port for an incoming connection. Once someone connected it asks for a name and a password. but for some reason I can't get it to read the name/password entered. what am i missing please... while (($client,$client_address) = $server-accept()) { # Get the client ip ($client_port, $c_ip) = sockaddr_in($client_address); $clientip = inet_ntoa($c_ip); print $client \nname\n; chomp ($cl_name = $client); print $client pass\n; chomp ($cl_pass = $client); print $client \n$cl_name $cl_pass $clientip\n; } e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: IO::Socket - i can't get it to read the data
ok it seems like the chomp it stuffin it up ? if i removed it i get the correct data but with a \n On Friday 15 October 2004 11:56, Etienne Ledoux wrote: greetings, This program listens on a port for an incoming connection. Once someone connected it asks for a name and a password. but for some reason I can't get it to read the name/password entered. what am i missing please... while (($client,$client_address) = $server-accept()) { # Get the client ip ($client_port, $c_ip) = sockaddr_in($client_address); $clientip = inet_ntoa($c_ip); print $client \nname\n; chomp ($cl_name = $client); print $client pass\n; chomp ($cl_pass = $client); print $client \n$cl_name $cl_pass $clientip\n; } e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: IO::Socket - i can't get it to read the data
Would anybody have any idea why chomp is deleting the value ? No matter how I try and do it. I even tried s/\n//,$value . afterwards I have a empty value. I don't understand what I'm doing wrong here and everywhere i check this it seems to be the right way to do it. ?!?! e. On Friday 15 October 2004 12:16, Etienne Ledoux wrote: ok it seems like the chomp it stuffin it up ? if i removed it i get the correct data but with a \n On Friday 15 October 2004 11:56, Etienne Ledoux wrote: greetings, This program listens on a port for an incoming connection. Once someone connected it asks for a name and a password. but for some reason I can't get it to read the name/password entered. what am i missing please... while (($client,$client_address) = $server-accept()) { # Get the client ip ($client_port, $c_ip) = sockaddr_in($client_address); $clientip = inet_ntoa($c_ip); print $client \nname\n; chomp ($cl_name = $client); print $client pass\n; chomp ($cl_pass = $client); print $client \n$cl_name $cl_pass $clientip\n; } e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RegExp
From: JupiterHost.Net [EMAIL PROTECTED] Mandar Rahurkar wrote: I have a bunch of text (multiple paragraphs). I want to find a sentence like 'Susan * the water' (No its not a HW problem). Here's what I am doing: #! /usr/bin/perl use strict; use warnings; $file=temp.txt; my $file = 'temp.txt'; open(fp,$file) or die Cant open $file :$!\n; open(FP,$file) or die Can not open $file : $!\n; local $/=; why ?? Because otherwise the FP would read individual lines. And the sentence can easily be split to several lines. If you set $/ to then the file is read in paragraphs, not lines. That is each FP now returns several lines until it finds an empty one. while (fp) { while(FP) { while( /(susan)(\D+)[the|water]\b/xig ) \D means non-digit, What's wrong with sentence Susan filled 3 glasses with the water? And the \D+ matches as much text as it can, it won't stop on the first the water. [the|water] means exactly the same as for example [aehrtw|]. Not what you meant right? I believe you want something like this: while (/(susan[^.?!]+the\s+water\b)/ig) { print $1,\n; } 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/ http://learn.perl.org/first-response
strict getopt()
Hello together, I have a new problem. What can I do to use getopt() and use strict? If I use strict I have to declare all of my variables. And if I do this, perl ignores my getopt(s) single-chars. Is this normal? What can I do to solve this? I want to use perl with -w option and the strict pracma. Is this posible? Gruss Christian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RegExp
local $/=; why ?? Because otherwise the FP would read individual lines. And the sentence can easily be split to several lines. If you set $/ to then the file is read in paragraphs, not lines. That is each FP now returns several lines until it finds an empty one. You rock Jenda! I always learn something new from you. Thanks Lee.M - JupiterHost.Net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: IO::Socket - i can't get it to read the data
On Oct 15, Etienne Ledoux said: Would anybody have any idea why chomp is deleting the value ? No matter how I try and do it. I even tried s/\n//,$value . afterwards I have a empty value. I don't understand what I'm doing wrong here and everywhere i check this it seems to be the right way to do it. ?!?! The problem is that your data ends in \r\n, and the \r is a carriage return. If you print jeff\rABC, you'd *see* ABCf, because the \r causes the cursor to go to the beginning of the line, thus overwriting previous letters. In your case, apparently the IP address is longer than both the username and the password, so the IP is all you're seeing. ($user = $client) =~ s/\r?\n$//; ($pass = $client) =~ s/\r?\n$//; That should work for you. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: strict getopt()
On Oct 15, Christian Stalp said: What can I do to use getopt() and use strict? Declare your variables with our() if you're using Perl 5.6 or better; otherwise, declare them with 'use vars'. If I use strict I have to declare all of my variables. And if I do this, perl ignores my getopt(s) single-chars. Is this normal? What can I do to solve this? I want to use perl with -w option and the strict pracma. Is this posible? If you're using Perl 5.6, don't use -w anymore, use the warnings pragma. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: counting gaps in sequence data
On Thu, 14 Oct 2004 16:11:42 -0600, Michael Robeson [EMAIL PROTECTED] wrote: Yeah, I have just submitted that same question verbatim to the bio-perl list. I am still running through some ideas though. I have both Bioinformatics perl books. They are not very effective teaching books. The books spend too much time on using modules. Though while I understand the usefulness of not having to re-write code, it is a bad idea for beginners like me. Because re-writing code at first gives me a lot of practice. Some of the scripts in the books use like 3-5 modules, so it gets confusing on what is going on. I mean the books are not useless, but they definitely are structured for a class with a teacher. :-) -Mike Hi again, Mike! I've thrown together the following code. I have not commented this! If you have some questions, just ask. I hard coded the sequences for my ease-of-use. It looked to me like you have figured out how to grab the sequences out of a file and throw them in a hash. This code uses some deep nested references, and therefore, some crazy dereferences. Have fun with it, I know I did! Things that might look weird: check out perldoc -f split for info on using a null-string to split with (That's were I found it!) and of course perldoc perlref for all the deep nested references and dereferencing stuff! I'm currently reading Learning Perl Objects, References Modules by Randal Schwartz. I highly recommend it. It helped a lot in this exercise. Here's the code: use warnings; use strict; my %sequences = ( 'Human' = acgtt---cgatacg---acgact-t, 'Chimp' = acgtt---cgatacg---acgact-t, 'Mouse' = acgata---acgatcgacgt, ); my %results; foreach my $species( keys %sequences ) { my $is_base_pair_gap = 0; my $base_pair_gap; my $base_pair_gap_pos; my $position = 1; foreach( split( / */, $sequences{$species} )) { if( /-/ ) { unless( $is_base_pair_gap ) { $base_pair_gap_pos = $position; } $is_base_pair_gap = 1; $base_pair_gap .= $_; } elsif( $is_base_pair_gap ) { push @{$results{$species}{length($base_pair_gap)}}, $base_pair_gap_pos; $is_base_pair_gap = 0; $base_pair_gap = undef; } $position++; } } foreach my $species( keys %results ) { print $species:\n; foreach my $base_pair_gap( keys %{$results{$species}} ) { printNumber of $base_pair_gap base pair gaps:\t, scalar( @{$results{$species}{$base_pair_gap}}), \n; print at position(s) , join( ',', @{$results{$species}{$base_pair_gap}} ), .\n; } print \n; } The heart of this code is this line: push @{$results{$species}{length($base_pair_gap)}}, $base_pair_gap_pos; there is a %results hash which has keys that are the different species, and values that point to another hash. THAT hash (the inner hash) has keys that are the length of the base-pair-gaps, and values that point to an array. The array holds a list of the positions of those base-pair gaps! The first base pair gap in the human sequence is '---' at the 6th character. That looks like this (warning: pseudo code for clarity!) %results-{'Human'}-{ 3 }-[6] When we find the second '---' gap, we add it's position to the array: %results-{'Human'}-{ 3 }-[6,16] Then, we find a new base-pair-gap ('-') so we add a new key to inner hash: %results-{'Human'}-{ 3 }-[6,16] -{ 5 }-[25] Next, we move on to the next species ... %results-{'Human'}-{ 3 }-[6,16] -{ 5 }-[25] -{'Mouse'}-{ 3 }-[7] So, finally, with Data::Dumper, we can see the %results hash when the code is done processing the sequence: %results = { 'Human' = { '3' = [ 6, 16 ], '5' = [ 25 ] }, 'Mouse' = { '4' = [ 17 ], '3' = [ 7 ] }, 'Chimp' = { '3' = [ 6, 16 ], '5' = [ 25 ] } }; I hope this is helpful! This really was a lot of fun. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: strict getopt()
Declare your variables with our() if you're using Perl 5.6 or better; otherwise, declare them with 'use vars'. All right, it works now, thank you very much. If you're using Perl 5.6, don't use -w anymore, use the warnings pragma. warnings? How does this works? #!/usr/bin/perl warnings or use warnings; ? I just tested it, and both were accepted. Gruss Christian -- Christian Stalp Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI) Obere Zahlbacher Straße 69 55131 Mainz Tel.: 06131/ 17-6852 E-Mail: [EMAIL PROTECTED] Internet: www.imbei.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: counting gaps in sequence data
Errin, Thanks so much! I will spend the weekend going over what you've posted. Looks like I will learn a lot from this post alone. This stuff is so addictive. I can spend hours doing this and not realize it. If I am successful or not is another story! :-) I'll definitely let you know if I have any trouble. -Cheers! -Mike On Oct 15, 2004, at 7:22 AM, Errin Larsen wrote: On Thu, 14 Oct 2004 16:11:42 -0600, Michael Robeson [EMAIL PROTECTED] wrote: Yeah, I have just submitted that same question verbatim to the bio-perl list. I am still running through some ideas though. I have both Bioinformatics perl books. They are not very effective teaching books. The books spend too much time on using modules. Though while I understand the usefulness of not having to re-write code, it is a bad idea for beginners like me. Because re-writing code at first gives me a lot of practice. Some of the scripts in the books use like 3-5 modules, so it gets confusing on what is going on. I mean the books are not useless, but they definitely are structured for a class with a teacher. :-) -Mike Hi again, Mike! I've thrown together the following code. I have not commented this! If you have some questions, just ask. I hard coded the sequences for my ease-of-use. It looked to me like you have figured out how to grab the sequences out of a file and throw them in a hash. This code uses some deep nested references, and therefore, some crazy dereferences. Have fun with it, I know I did! Things that might look weird: check out perldoc -f split for info on using a null-string to split with (That's were I found it!) and of course perldoc perlref for all the deep nested references and dereferencing stuff! I'm currently reading Learning Perl Objects, References Modules by Randal Schwartz. I highly recommend it. It helped a lot in this exercise. Here's the code: use warnings; use strict; my %sequences = ( 'Human' = acgtt---cgatacg---acgact-t, 'Chimp' = acgtt---cgatacg---acgact-t, 'Mouse' = acgata---acgatcgacgt, ); my %results; foreach my $species( keys %sequences ) { my $is_base_pair_gap = 0; my $base_pair_gap; my $base_pair_gap_pos; my $position = 1; foreach( split( / */, $sequences{$species} )) { if( /-/ ) { unless( $is_base_pair_gap ) { $base_pair_gap_pos = $position; } $is_base_pair_gap = 1; $base_pair_gap .= $_; } elsif( $is_base_pair_gap ) { push @{$results{$species}{length($base_pair_gap)}}, $base_pair_gap_pos; $is_base_pair_gap = 0; $base_pair_gap = undef; } $position++; } } foreach my $species( keys %results ) { print $species:\n; foreach my $base_pair_gap( keys %{$results{$species}} ) { printNumber of $base_pair_gap base pair gaps:\t, scalar( @{$results{$species}{$base_pair_gap}}), \n; print at position(s) , join( ',', @{$results{$species}{$base_pair_gap}} ), .\n; } print \n; } The heart of this code is this line: push @{$results{$species}{length($base_pair_gap)}}, $base_pair_gap_pos; there is a %results hash which has keys that are the different species, and values that point to another hash. THAT hash (the inner hash) has keys that are the length of the base-pair-gaps, and values that point to an array. The array holds a list of the positions of those base-pair gaps! The first base pair gap in the human sequence is '---' at the 6th character. That looks like this (warning: pseudo code for clarity!) %results-{'Human'}-{ 3 }-[6] When we find the second '---' gap, we add it's position to the array: %results-{'Human'}-{ 3 }-[6,16] Then, we find a new base-pair-gap ('-') so we add a new key to inner hash: %results-{'Human'}-{ 3 }-[6,16] -{ 5 }-[25] Next, we move on to the next species ... %results-{'Human'}-{ 3 }-[6,16] -{ 5 }-[25] -{'Mouse'}-{ 3 }-[7] So, finally, with Data::Dumper, we can see the %results hash when the code is done processing the sequence: %results = { 'Human' = { '3' = [ 6, 16 ], '5' = [ 25 ] }, 'Mouse' = { '4' = [ 17 ], '3' = [ 7 ] }, 'Chimp' = { '3' = [ 6, 16
Questions related to draw graphy using perl
Dear all. I am a new user of Perl with some experience in perl data extraction with pattern matching, but never did anything with making graphy using perl. I need to draw a chromosome copy number graphy and p-values. The data looks are as follow: SNP id physical location copy number meta p-value SNP_A-1507380120264678 1.207953-20 SNP_A-1507487120319466 1.261954-20 SNP_A-1517022120783585 0.957751-20 SNP_A-1511651121478764 0.957812-20 SNP_A-151681817549 2.0043180.722914 SNP_A-1516270122257923 3.2988680.967391 SNP_A-1512747122611515 1.419261-14.5074 SNP_A-1519155123556896 0.740608-14.5074 SNP_A-1517539124789024 1.202693-14.5074 SNP_A-1511157124890914 1.222511-14.5074 The physical location should be the place where the p-value and copy number should be along the vertical line. The SNP id could be treated as annotation. I have some open source code available for drawing a chromosome with cytobands writing in perl. The final gool is to put this graph of copy number beside the chromosome map, which make me think that it will be easier using perl to do draw this copy number map. My questions to you is: Is it possible to create graphy like this using perl? The graphy in my mind should look like this and it will be better to use histogram bar for meta p-values. ---| --| | -| Thanks in advance, Aiguo Li
Re: Questions related to draw graphy using perl
On Fri, 15 Oct 2004, Li, Aiguo (NIH/NCI) wrote: Is it possible to create graphs like this using perl? The graph in my mind should look like this and it will be better to use histogram bar for meta p-values. ---| --| | -| Interesting -- that's not one of the typical data visualization techniques that most canned tools (from Perl's GD::Graph to, say, Excel's chart abilities) usually provide, as far as I know. :-) Usually on this list, it's expected that people give an overview of what they've tried so far, including modules used and code written. In this case though, you're asking an interesting but advanced question, and you would probably be better off by taking this to the bioperl list: Overview: http://lists.perl.org/showlist.cgi?name=bioperl-l Homepage: http://bioperl.org/mailman/listinfo/bioperl-l Archives: http://bioperl.org/pipermail/bioperl-l/ Subscribe / Unsubscribe: http://bioperl.org/mailman/listinfo/bioperl-l But that said, if you get no help over there, by all means ask away on this list. I'm certainly not trying to drive away interesting questions. :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reference syntax...
I'm reading Perl ORM book right now, and I'd just like to know what is generally more accepted... This format: @$array or this: @{$array} Tks, Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reference syntax...
I'm reading Perl ORM book right now, and I'd just like to know what is generally more accepted... Both are accepted since they work :-)... This format: @$array I generally stick with this until I need the below option. It is less cluttered and shorter to type (though the first is more important than the second). or this: @{$array} Usually when you need this is when you have multiple depths of references and the syntax becomes ambiguous to the interpreter. Something like, @{$hashref-{$scalar}} In this case without the {} the interpreter can't tell if you mean, (@$hashref) -{$scalar} or @ ( $hashref-{$scalar} ) The parens are NOT normal syntax, I am using them to show grouping. Tks, Steve Helps? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: emacs and perl
I know how to do the like, I have been an emacs user for some time now. Cperl mode is much better than regular perl mode. I was looking for a way to run my code in emacs, not write or edit code, thats someting I can do already. I know I can run a shell in another buffer, under my code and that works ok, but it would be nice to run my code to see how it functions while im writing. Thats what im trying to figure out here. Thanks, Jon On Thu, Oct 14, 2004 at 11:01:40AM -0400, Steve Bertrand wrote: On Wed, 13 Oct 2004 22:24:11 -0500, Jon Mosco [EMAIL PROTECTED] wrote: I was wondering if anyone had some advice or pointers for perl and emacs. I want to be able to run my programs in a window similar to the way you can with 'compile' mode with c. If anyone has some tips or pointers, please let me know. Jon M. P.S. I already know about eshell and the like. an interesting idea- but there is one minor detail... is it that necessary? i usually run with two terminals - one for editing and one for typing './foo.pl'. Now, there might be an advantage to what you want- maybe a GUI like stepping function. Now /that/ would be neat :)I'd love to learn how to do that with vi. on occasion i'd run with the perl debugger to step through the code, but i can't for the life of me remember how to do that now... anyway, i like the idea of seeing the script as a whole while testing it. I've got a setup with a dual-head video card, and two monitors and then my laptop. Normally, one monitor is always situated with my webmail client for email, and my notebook is SSH'd into the devel box for running the program. However, I still find it a pain to switch keyboards, or switching shells all the time, so I have recently begun tredging through the emacs tutorial, because I too want to run my code in a second window within the same application. The tutorial for emacs is great to get started, then there are extensive docs online for advanced usage. If you open a Perl script with emacs: # emacs myscript.pl ..then emacs automagically loads itself in Perl mode. Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Piping output to and from external perl routine
Is there an easy way to pipe output to an external perl routine and then pipe the output of that routine back in for more processing? In particular I want to use LWP::UserAgent to grab a web page, pipe the output to Tom Christiansen's striphtml routine (http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz) and then pipe that output back in for some subsequent processing. Something like: my $ua = new LWP::UserAgent; my $request = new HTTP::Request('GET', $myURL); my $response = $ua-request($request); my $page = $response-content; open(STRIPHTML, |striphtml.pl) || die(Can\'t open striphtml: $!\n); print STRIPHTML $page; close(STRIPHTML); # maybe not such a good idea? This works fine so far... But now what? How do I get the output of striphtml.pl back in to do some more processing on it? I know I can do this with a temporary file, but I loathe using them when reasonable alternatives might be available... Thanks! -Dan --- Dan Fish - [EMAIL PROTECTED] A -good- dive buddy will be there if you run out of air, a -great- one will be there before you run out! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Piping output to and from external perl routine
Is there an easy way to pipe output to an external perl routine and then pipe the output of that routine back in for more processing? In particular I want to use LWP::UserAgent to grab a web page, pipe the output to Tom Christiansen's striphtml routine (http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz) and then pipe that output back in for some subsequent processing. Something like: my $ua = new LWP::UserAgent; my $request = new HTTP::Request('GET', $myURL); my $response = $ua-request($request); my $page = $response-content; open(STRIPHTML, |striphtml.pl) || die(Can\'t open striphtml: $!\n); print STRIPHTML $page; close(STRIPHTML); # maybe not such a good idea? This works fine so far... But now what? How do I get the output of striphtml.pl back in to do some more processing on it? I know I can do this with a temporary file, but I loathe using them when reasonable alternatives might be available... Thanks! -Dan Check out IPC::Open3 and IPC::Open2, perldoc IPC::Open3 perldoc perlopentut Haven't looked at striphtml but I suspect this could be done with a module inside of the main source rather than shelling out to another program. Or by pulling in the program as a lib and calling its code directly?? http://danconia.org --- Dan Fish - [EMAIL PROTECTED] A -good- dive buddy will be there if you run out of air, a -great- one will be there before you run out! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RegExp
Thanks Guys this is good however what does character class inside the square brackets mean.. I think I need to get mastering regular expressions book.. Mandar while (/(susan[^.?!]+the\s+water\b)/ig) { print $1,\n; } 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/ http://learn.perl.org/first-response
Installing Perl DBI and Oracle DBD in AIX 5.1
Hi there, I have an AIX 5.1 machine and I wish to use the perl DBI and oracle DBD in this machine. I have tried to install them by downloading DBI-1.45.tar and DBD-Oracle-2.15.tar files from http://www.cpan.org/ So, I uncompressed the DBI-1.45.tar file and followed the README file instructions. First, I runned the folowing command: perl Makefile.PL this created the Makefile So, I tried to run the make command, but I got the following error: cc_r -c-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -qlonglong -O-DVERSION=\1.45\ -DXS_VERSION=\1.45\ -I/usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE Perl.c /bin/sh: cc_r: not found. make: 1254-004 The error code from the last command is 127. So, I changed the compiler from cc_r to cc, runned make again and got this error message: cc -c-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -qlonglong -O-DVERSION=\1.45\ -DXS_VERSION=\1.45\ -I/usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE Perl.c /usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE/reentr.h, line 610.16: 1506-007 (S) struct drand48_data is undefined. /usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE/reentr.h, line 717.16: 1506-007 (S) struct random_data is undefined. make: 1254-004 The error code from the last command is 1. Stop. Can somebody help me to get the job done? thanks in advance, Pablo Salinas _ Do You Yahoo!? Información de Estados Unidos y América Latina, en Yahoo! Noticias. Visítanos en http://noticias.espanol.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Installing Perl DBI and Oracle DBD in AIX 5.1
Hi there, I have an AIX 5.1 machine and I wish to use the perl DBI and oracle DBD in this machine. I have tried to install them by downloading DBI-1.45.tar and DBD-Oracle-2.15.tar files from http://www.cpan.org/ This is a rather difficult combination and I know there has been lots of discussion about installing DBI on AIX and with Oracle on the dbi-users list, you may want to check the archives for it for help. http://www.mail-archive.com/[EMAIL PROTECTED]/ So, I uncompressed the DBI-1.45.tar file and followed the README file instructions. First, I runned the folowing command: perl Makefile.PL this created the Makefile So, I tried to run the make command, but I got the following error: cc_r -c-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -qlonglong -O-DVERSION=\1.45\ -DXS_VERSION=\1.45\ -I/usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE Perl.c /bin/sh: cc_r: not found. make: 1254-004 The error code from the last command is 127. So, I changed the compiler from cc_r to cc, runned make again and got this error message: I am assuming the installer pulled cc_r from the config for Perl, check it with perl -V. Modules generally have to be built with the same compiler used to build Perl which is why you would get this second set of errors. Is 'cc_r' not installed on the system? Was the Perl installed with a binary, or built on a different system? I suspect you will need to match up the compiler of Perl with the ones you have available. cc -c-D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -q32 -D_LARGE_FILES -qlonglong -O-DVERSION=\1.45\ -DXS_VERSION=\1.45\ -I/usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE Perl.c /usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE/reentr.h, line 610.16: 1506-007 (S) struct drand48_data is undefined. /usr/opt/perl5/lib/5.8.0/aix-thread-multi/CORE/reentr.h, line 717.16: 1506-007 (S) struct random_data is undefined. make: 1254-004 The error code from the last command is 1. Stop. Can somebody help me to get the job done? thanks in advance, Pablo Salinas If you don't get a satisfactory answer from this list I would definitely try the dbi-users list they are very good about helping with installations. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: RegExp
Thanks Guys this is good however what does character class inside the square brackets mean.. I think I need to get mastering regular expressions book.. Read: # perldoc perlretut and: # perldoc perlre which will help give you an understanding of regex's. This is only my opinion of course, and I still have a long way to go with this, but character classes are well defined and described within. Note that all Perl books seem great (as far as my reading) so let me know if you actually buy/read the book and how it is. (I just bought Perl -- Objects, References and Modules, and it's great so far (O'Reilly of course)). Just my .02 Steve Mandar while (/(susan[^.?!]+the\s+water\b)/ig) { print $1,\n; } 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/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how to assign an external command aoutput to an array
Mauro wrote: I have to assign output of ssh [EMAIL PROTECTED] sar -u 1 1|awk '/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }' to an array. The output looks like: 0 0 0 100 if I did: my @pippo=qx'ssh [EMAIL PROTECTED] sar -u 1 1|awk \'/%usr%sys%wio %idle/ { getline ; printf %i %i %i %i, $2, $3, $4, $5 }\''; it assigns the entire output to $pippo[0] instead of to give each number in output to a differenet array element. Please can you give me any hints? You could probably do it something like this (UNTESTED): open PIPE, 'ssh [EMAIL PROTECTED] sar -u 1 1 |' or die Cannot open pipe from ssh: $!; my @pippo; while ( PIPE ) { next unless /%usr%sys%wio %idle/; push @pippo, ( split ' ', PIPE )[ 1 .. 4 ]; } close PIPE or warn $! ? Error closing ssh pipe: $! : Exit status $? from ssh; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reference syntax...
Wiggins d Anconia wrote: Usually when you need this is when you have multiple depths of references and the syntax becomes ambiguous to the interpreter. Something like, @{$hashref-{$scalar}} In this case without the {} the interpreter can't tell if you mean, Yes, the interpreter can tell because of precedence. @$hashref-{$scalar} is the same as @{$hashref}-{$scalar} which in this case will produce an error. (@$hashref) -{$scalar} or @ ( $hashref-{$scalar} ) The parens are NOT normal syntax, I am using them to show grouping. perldoc perldsc [snip] CAVEAT ON PRECEDENCE Speaking of things like @{$AoA[$i]}, the following are actually the same thing: $aref-[2][2] # clear $$aref[2][2]# confusing That's because Perl's precedence rules on its five prefix dereferencers (which look like someone swearing: $ @ * % ) make them bind more tightly than the postfix subscripting brackets or braces! This will no doubt come as a great shock to the C or C++ programmer, who is quite accustomed to using *a[i] to mean what's pointed to by the i'th element of a. That is, they first take the subscript, and only then deref- erence the thing at that subscript. That's fine in C, but this isn't C. The seemingly equivalent construct in Perl, $$aref[$i] first does the deref of $aref, making it take $aref as a reference to an array, and then dereference that, and finally tell you the i'th value of the array pointed to by $AoA. If you wanted the C notion, you'd have to write ${$AoA[$i]} to force the $AoA[$i] to get evaluated first before the leading $ dereferencer. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Piping output to and from external perl routine
Dan Fish wrote: Is there an easy way to pipe output to an external perl routine and then pipe the output of that routine back in for more processing? In particular I want to use LWP::UserAgent to grab a web page, pipe the output to Tom Christiansen's striphtml routine (http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz) and then pipe that output back in for some subsequent processing. Something like: my $ua = new LWP::UserAgent; my $request = new HTTP::Request('GET', $myURL); my $response = $ua-request($request); my $page = $response-content; open(STRIPHTML, |striphtml.pl) || die(Can\'t open striphtml: $!\n); print STRIPHTML $page; close(STRIPHTML); # maybe not such a good idea? This works fine so far... But now what? How do I get the output of striphtml.pl back in to do some more processing on it? I know I can do this with a temporary file, but I loathe using them when reasonable alternatives might be available... Copy and paste Tom's code into your program. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reference syntax...
- Original Message - From: John W. Krahn [EMAIL PROTECTED] To: Wiggins d Anconia [EMAIL PROTECTED]; Perl Beginners [EMAIL PROTECTED] Sent: Friday, October 15, 2004 11:30 PM Subject: Re: Reference syntax... Wiggins d Anconia wrote: Usually when you need this is when you have multiple depths of references and the syntax becomes ambiguous to the interpreter. Something like, @{$hashref-{$scalar}} In this case without the {} the interpreter can't tell if you mean, Yes, the interpreter can tell because of precedence. @$hashref-{$scalar} is the same as @{$hashref}-{$scalar} which in this case will produce an error. (@$hashref) -{$scalar} or @ ( $hashref-{$scalar} ) The parens are NOT normal syntax, I am using them to show grouping. perldoc perldsc [snip] CAVEAT ON PRECEDENCE Speaking of things like @{$AoA[$i]}, the following are actually the same thing: $aref-[2][2] # clear $$aref[2][2]# confusing That's because Perl's precedence rules on its five prefix dereferencers (which look like someone swearing: $ @ * % ) make them bind more tightly than the postfix subscripting brackets or braces! This will no doubt come as a great shock to the C or C++ programmer, who is quite accustomed to using *a[i] to mean what's pointed to by the i'th element of a. That is, they first take the subscript, and only then deref- erence the thing at that subscript. That's fine in C, but this isn't C. The seemingly equivalent construct in Perl, $$aref[$i] first does the deref of $aref, making it take $aref as a reference to an array, and then dereference that, and finally tell you the i'th value of the array pointed to by $AoA. If you wanted the C notion, you'd have to write ${$AoA[$i]} to force the $AoA[$i] to get evaluated first before the leading $ dereferencer. and just above it there is an interesting example... for $i (1..10) { @array = somefunc($i); $AoA[$i] = [ @array ]; } The square brackets make a reference to a new array with a *copy* of what's in @array at the time of the assignment. This is what you want. if one has a ref to HoH how would he make a copy of it using simular syntax ?? I know it can be done like this use Storable qw(dclone); my $HOH_REF_COPY = dclone($HOH_REF) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response