Re: Reading/writing binary
Raymond Wan wrote: Hi Chas., Jenda, On Mon, May 11, 2009 at 6:00 PM, Chas. Owens chas.ow...@gmail.com wrote: On Mon, May 11, 2009 at 04:50, Jenda Krynicky je...@krynicky.cz wrote: From: Raymond Wan rwan.w...@gmail.com I'm on a Linux system too; I guess I've used it for so long, I forgot about the situations when binary/text does matter (i.e., Windows). I see...so it doesn't matter. That would make sense since I just pipe to stdout right now and whether I'm sending text [ie., human-readable characters] or not, it all seems to work fine... Well ... it seems, but it doesn't have to. Based on the locale settings, if you do not binmode() the filehandle or open it with the right IO layer specified, the stuff you print may undergo some charset conversions. perldoc -f binmode says On some systems (in general, DOS and Windows-based systems) binmode() is necessary when you're not working with a text file. For the sake of portability it is a good idea to always use it when appropriate, and to never use it when it isn't appropriate. Also, people can set their I/O to be by default UTF-8 encoded Unicode, not bytes. In other words: regardless of platform, use binmode() on binary data, like for example images. snip or the more modern: open my $fh, :raw, $filename or die could not open $filename: $!; from perldoc perlio[1] The :raw layer is defined as being identical to calling binmode($fh) - the stream is made suitable for passing binary data i.e. each byte is passed as-is. The stream will still be buffered. 1. http://perldoc.perl.org/PerlIO.html I see. I'm not writing image data, but my own data (sequence of 4-byte integers), so I guess I should be using binmode anyway. So, of the two (binmode and :raw), the latter is the newer/more modern method? With so many ways to do things in Perl, I often don't know which one is the more accepted one. Or you could also use the open pragma: perldoc open Thank you! I'll be sure to use :raw, even if I'm just writing to stdout. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Array Initialization
On Wed, May 13, 2009 at 01:59, John W. Krahn jwkr...@shaw.ca wrote: snip What's your point? I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that my() happens when the code is compiled so it is *not* re-run every time through the loop. is very wrong. my runs every time through the loop creating a new variable each time (as demonstrated by my code and benchmark). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Testing a scalier for two possible values at once
I need to test a scalier to see if its value is not two possibilities, because this test is being done inside a while loop I can not use an elsif statement without things getting ugly. I have tried it like this if ($scalier nq 'A') || ($scalier nq 'B') { but that just gave me a syntax error when I tried to run it. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Testing a scalier for two possible values at once
You wrote on 05/13/2009 02:17 AM: I need to test a scalier to see if its value is not two possibilities, because this test is being done inside a while loop I can not use an elsif statement without things getting ugly. I have tried it like this if ($scalier nq 'A') || ($scalier nq 'B') { but that just gave me a syntax error when I tried to run it. It's ne not nq. hth Alex -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Testing a scalier for two possible values at once
On Wed, May 13, 2009 at 11:25:40AM +0200, Alexander Koenig wrote: You wrote on 05/13/2009 02:17 AM: I need to test a scalier to see if its value is not two possibilities, because this test is being done inside a while loop I can not use an elsif statement without things getting ugly. I have tried it like this if ($scalier nq 'A') || ($scalier nq 'B') { but that just gave me a syntax error when I tried to run it. It's ne not nq. You'll also need to get your logic correct or you might find that reducing to if (1) {} -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Testing a scalier for two possible values at once
Adam Jimerson wrote: I need to test a scalier to see if its value is not two possibilities, because this test is being done inside a while loop I can not use an elsif statement without things getting ugly. I have tried it like this if ($scalier nq 'A') || ($scalier nq 'B') { but that just gave me a syntax error when I tried to run it. That should be: if ( $scalier ne 'A' $scalier ne 'B' ) { John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
How does printf able to receive a pointer when passing it a string constant?
I have a c code that looks like this: #includestdio.h main (){ char girl[] = anna; char boy[] = jude; stringcopy(boy, girl); /* copy boy to girl */ printf(%s, girl); } void stringcopy(char *b, char *g){ while ((*g++ = *b++) != '\0') ; } It prints fine... However if I replace the stringcopy call arguments with jude, anna it compiles fine but i get segmentation fault when running. How come printf can accept variable names as well as constant strings such as: printf (%s, girl); and printf (Hello World\n); My stringcopy function only accepts pointers. Shouldn't I be passing pointer to the first element of anna when passing the string constant anna?? ) How does printf print a string constant then? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How does printf able to receive a pointer when passing it a string constant?
On Wed, May 13, 2009 at 07:48, Michael Alipio daem0n...@yahoo.com wrote: I have a c code that looks like this: And C isn't Perl, perhaps you should ask these sort of questions on a C list or newsgroup[1]? Or maybe Stack Overflow[2]? snip However if I replace the stringcopy call arguments with jude, anna it compiles fine but i get segmentation fault when running. snip Because they are string constants and you are trying to modify the second string. You aren't allowed to do that. snip How come printf can accept variable names as well as constant strings such as: printf (%s, girl); and printf (Hello World\n); snip Because printf only reads from the pointer, it doesn't modify it. snip My stringcopy function only accepts pointers. Shouldn't I be passing pointer to the first element of anna when passing the string constant anna?? ) snip You can point to it, but you can't modify it. 1. http://groups.google.com/group/comp.lang.c/topics 2. http://www.stackoverflow.com -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How does printf able to receive a pointer when passing it a string constant?
On 5/13/09 Wed May 13, 2009 4:48 AM, Michael Alipio daem0n...@yahoo.com scribbled: I have a c code that looks like this: #includestdio.h main (){ char girl[] = anna; char boy[] = jude; stringcopy(boy, girl); /* copy boy to girl */ printf(%s, girl); } void stringcopy(char *b, char *g){ while ((*g++ = *b++) != '\0') ; } It prints fine... However if I replace the stringcopy call arguments with jude, anna it compiles fine but i get segmentation fault when running. How come printf can accept variable names as well as constant strings such as: printf (%s, girl); and printf (Hello World\n); Because printf does not attempt to change its arguments. My stringcopy function only accepts pointers. Shouldn't I be passing pointer to the first element of anna when passing the string constant anna?? ) stringcopy modifies its second argument. Your compiler is not letting you modify a string constant. That way, different parts of your program can share the same string constant without one part being affected by what another part does. How does printf print a string constant then? Easily, because it does not attempt to modify it. May I ask you a question? Why are you posting C questions to a Perl mailing list? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Array Initialization
Chas. Owens wrote: On Wed, May 13, 2009 at 01:59, John W. Krahn jwkr...@shaw.ca wrote: snip What's your point? I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that my() happens when the code is compiled so it is *not* re-run every time through the loop. is very wrong. Yep, that's it. John, honestly I thought that you had made a 'typo', and that my little snippet would be sufficient to call your attention to it. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
deleting subdirectories only in Win32
Hello, When trying to delete subdirectories and their files on WinXP SP3, the following code also removes the root directory of the subdirectories. Can I get some assistance? I want to keep C:\my\data intact but I am losing the \data folder # # Code to remove all files and subdirectories under C:\my\data # perl -e use File::Path; rmtree('C:/my/data',{keep_root = 1, safe = 1});
Help with LWP
Hi, Here is a beginner's LWP code that is not working. The script is supposed to query the NCBI website with a user defined term: tuberculosis. The term is entered into a search box. The user chooses a database from a drop-down menu and then hits the Search button. Here is the code: #!/usr/bin/perl -w use strict; use LWP; my $query= tuberculosis; my $option= 30; my $go= Go; my $site= NcbiHome; my $ua= LWP::UserAgent-new; my $response= $ua-post('http://www.ncbi.nlm.nih.gov/', [ term= $query, db= 4, # use the Genome database (value=4) submit= Go, SITE= NcbiHome ] ); if ($response-is_success) { print $response-content().\n; # or whatever } else { die $response-status_line; } All this script returns is the NCBI homepage. Any idea what I am doing wrong? TIA, Anjan -- = anjan purkayastha, phd bioinformatics analyst whitehead institute for biomedical research nine cambridge center cambridge, ma 02142 purkayas [at] wi [dot] mit [dot] edu 703.740.6939
Re: Help with LWP
ANJAN PURKAYASTHA wrote: Hi, Here is a beginner's LWP code that is not working. The script is supposed to query the NCBI website with a user defined term: tuberculosis. The term is entered into a search box. The user chooses a database from a drop-down menu and then hits the Search button. Here is the code: #!/usr/bin/perl -w use strict; use LWP; my $query= tuberculosis; my $option= 30; my $go= Go; my $site= NcbiHome; my $ua= LWP::UserAgent-new; my $response= $ua-post('http://www.ncbi.nlm.nih.gov/', [ term= $query, db= 4, # use the Genome database (value=4) submit= Go, SITE= NcbiHome ] ); if ($response-is_success) { print $response-content().\n; # or whatever } else { die $response-status_line; } All this script returns is the NCBI homepage. Any idea what I am doing wrong? - You are not posting the request to the script that handles search queries. - The site deals with cookies, and it's possible that the script requires one or more cookie to be sent as part of the request. Those are two obvious things, but there might be more into it. Why not simply ask them? -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help with LWP
2009/5/13 Jim Gibson jimsgib...@gmail.com: On 5/13/09 Wed May 13, 2009 2:17 PM, ANJAN PURKAYASTHA anjan.purkayas...@gmail.com scribbled: Hi, if ($response-is_success) { print $response-content().\n; # or whatever } else { die $response-status_line; } All this script returns is the NCBI homepage. Try using the URL of the CGI program that processes the form on that page: http://www.ncbi.nlm.nih.gov/coreutils/dispatch.cgi The URL Jim has given you will work but it will a return a 302 moved. You'll need to scape the html for the results page. HTH, Dp. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help with LWP
On 5/13/09 Wed May 13, 2009 2:17 PM, ANJAN PURKAYASTHA anjan.purkayas...@gmail.com scribbled: Hi, Here is a beginner's LWP code that is not working. The script is supposed to query the NCBI website with a user defined term: tuberculosis. The term is entered into a search box. The user chooses a database from a drop-down menu and then hits the Search button. Here is the code: #!/usr/bin/perl -w use strict; use LWP; my $query= tuberculosis; my $option= 30; my $go= Go; my $site= NcbiHome; my $ua= LWP::UserAgent-new; my $response= $ua-post('http://www.ncbi.nlm.nih.gov/', [ term= $query, db= 4, # use the Genome database (value=4) submit= Go, SITE= NcbiHome ] ); if ($response-is_success) { print $response-content().\n; # or whatever } else { die $response-status_line; } All this script returns is the NCBI homepage. Try using the URL of the CGI program that processes the form on that page: http://www.ncbi.nlm.nih.gov/coreutils/dispatch.cgi -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help with LWP
Yes tried the URL; http://www.ncbi.nlm.nih.gov/coreutils/dispatch.cgi. Got a 302 Found at lwp_test.pl line 23 error message. Thanks Anjan On Wed, May 13, 2009 at 5:57 PM, Dermot paik...@googlemail.com wrote: 2009/5/13 Jim Gibson jimsgib...@gmail.com: On 5/13/09 Wed May 13, 2009 2:17 PM, ANJAN PURKAYASTHA anjan.purkayas...@gmail.com scribbled: Hi, if ($response-is_success) { print $response-content().\n; # or whatever } else { die $response-status_line; } All this script returns is the NCBI homepage. Try using the URL of the CGI program that processes the form on that page: http://www.ncbi.nlm.nih.gov/coreutils/dispatch.cgi The URL Jim has given you will work but it will a return a 302 moved. You'll need to scape the html for the results page. HTH, Dp. -- = anjan purkayastha, phd bioinformatics analyst whitehead institute for biomedical research nine cambridge center cambridge, ma 02142 purkayas [at] wi [dot] mit [dot] edu 703.740.6939
Push to AoA
Hi all, I'm trying to push a scalar onto an array. The array I'm trying to push() to is the first element of another array. I can't figure out what I'm missing. It would be appreciated if someone could point me in the right direction. if (-e $data_file) { $graph_data = retrieve $data_file; $x_axis = $graph_data-[0][0]; $x_axis++; # start pushing the next days data into the aoa push ($graph_data-[0], ($x_axis)); store $graph_data, $data_file; } Cheers, Steve smime.p7s Description: S/MIME Cryptographic Signature
Re: Push to AoA
On 5/13/09 Wed May 13, 2009 4:48 PM, Steve Bertrand st...@ibctech.ca scribbled: Hi all, I'm trying to push a scalar onto an array. The array I'm trying to push() to is the first element of another array. I can't figure out what I'm missing. It would be appreciated if someone could point me in the right direction. if (-e $data_file) { $graph_data = retrieve $data_file; $x_axis = $graph_data-[0][0]; $x_axis++; # start pushing the next days data into the aoa push ($graph_data-[0], ($x_axis)); store $graph_data, $data_file; } Your program shouldn't even compile. I get: Type of arg 1 to push must be array (not array element) at ... The first argument of push should be an array, not a scalar (even if that scalar is a reference to an array). push( @{$graph_data-[0]}, $x_axis ); (the parentheses around $x_axis are unnecessary.) If you are having more trouble, use the Data::Dumper module to inspect the contents of your AoA: use Data::Dumper; print Dumper(\$graph_data); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Push to AoA
Jim Gibson wrote: On 5/13/09 Wed May 13, 2009 4:48 PM, Steve Bertrand st...@ibctech.ca scribbled: Hi all, I'm trying to push a scalar onto an array. The array I'm trying to push() to is the first element of another array. I can't figure out what I'm missing. It would be appreciated if someone could point me in the right direction. if (-e $data_file) { $graph_data = retrieve $data_file; $x_axis = $graph_data-[0][0]; $x_axis++; # start pushing the next days data into the aoa push ($graph_data-[0], ($x_axis)); store $graph_data, $data_file; } Your program shouldn't even compile. I get: Type of arg 1 to push must be array (not array element) at ... That is where I was at as well. I just wanted to provide a code snippet that provided proper context. The first argument of push should be an array, not a scalar (even if that scalar is a reference to an array). push( @{$graph_data-[0]}, $x_axis ); I'll have to do a bit of reading, because I can't remember why the braces are important here. All I know is that it works ;) If you are having more trouble, use the Data::Dumper module to inspect the contents of your AoA: I was using Dumper, but I was getting results that I didn't expect, and I didn't know why. However, with your help, things are looking good. I'm now on track to start pushing onto all of the arrays: pearl# ./simscan-stats.pl yesterday ***5 $VAR1 = [ [ 1, '2', '3', '4', '5' ], [ 854 ], [ 388 ], [ 287 ], [ 511 ], [ 146 ], [ 365 ] ]; Thanks! Steve smime.p7s Description: S/MIME Cryptographic Signature