XML [AntiVir checked]
Hi, Which Module could you recommend for the use of the XML (XML::Simple, XML::Parser and XML::Writer, XML::DOM, XML::PATH...) ? Thanks in advance! KN -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: XML [AntiVir checked]
Naji, Khalid wrote: Hi, Which Module could you recommend for the use of the XML (XML::Simple, XML::Parser and XML::Writer, XML::DOM, XML::PATH...) ? To add to what Wiggins said, I would also take a look at the XML::LibXML family of modules, and look at SAX parsing. These are newer than some of the modules you listed. Also, be sure to go to http://perl-xml.sourceforge.net/ and read the FAQ there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XML [AntiVir checked]
On Tue, Oct 11, 2005 at 04:05:53PM +0200, Naji, Khalid wrote: Which Module could you recommend for the use of the XML (XML::Simple, XML::Parser and XML::Writer, XML::DOM, XML::PATH...) ? Which form of transport would you recommend for getting from one place to another? It depends on your specific needs. -- David Dorward http://dorward.me.uk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Win32::OLE, ADODB.Stream and ADODB.Command problem.
Hello all, I'm trying to use Win32::OLE (version 0.1703) and the ADODB objects to retrieve XML being produced by a stored procedure on SQL server. I used the following code as a guide: http://msdn.microsoft.com/library/en-us/dnsqlmag2k/html/adoxmlListing_02.txt If I create a VB project using the above code as a reference I can get the data out of the server without any problems. I can also retrieve the data with the osql program. However, the following perl code gives me this error: Error is -- OLE exception from ADODB.Command: Object or provider is not capable of performing requested operation. Win32::OLE(0.1703) error 0x800a0cb3 in METHOD/PROPERTYGET Execute -- in file Z:\XXI\Core\Install\SQL\DBcreate\test_xml.plx, package main, line 36 --- use strict; use Win32::OLE qw/in with/; use Win32::OLE::Const 'Microsoft ActiveX Data Objects 2.8 Library'; ++$|; my $connStr = q{Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Globalfs;Data Source=GFSDBmaster;Use Procedure for Prepare=0;Connect Timeout=4;Trusted_Connection=Yes}; my $cnConn = Win32::OLE-new('ADODB.Connection'); $cnConn-Open($connStr); chkW32LastErr(); my $cmCmd = Win32::OLE-new('ADODB.Command'); with($cmCmd, 'ActiveConnection' = $cnConn, 'CommandType' = adCmdStoredProc, 'CommandText' = 'dbo.report_a_table_with_XML' ); $cmCmd-Parameters-Append($cmCmd-CreateParameter('@table_name', adVarChar, adParamInput, 64, 'Branch')); $cmCmd-Parameters-Append($cmCmd-CreateParameter('@show_check_constraints', adTinyInt, adParamInput, 1, 1)); $cmCmd-Parameters-Append($cmCmd-CreateParameter('@style_sheet', adVarChar, adParamInput, 64, 'TableDump.xsl')); for my $param (in $cmCmd-Parameters) { print Param: , $param-Name, Value: , $param-Value, \n; } # Create a stream to handle the response my $sResponseStream = Win32::OLE-new('ADODB.Stream'); $sResponseStream-Open(); $cmCmd-{'Properties'}-{'Output stream'}-{'Value'} = $sResponseStream; $cmCmd-Execute({ 'Options' = adExecuteStream }); chkW32LastErr(); print $sResponseStream-ReadText(); sub chkW32LastErr { my $warnonly = shift; my $lastError = Win32::OLE-LastError(); if ($lastError) { my ($package, $filename, $line) = caller(); unless ($warnonly) { die qq{Error is\n--\n$lastError\n--\nin file $filename, package $package, line $line\n}; } else { print STDERR qq{Warning is\n--\n$lastError\n--\nin file $filename, package $package, line $line\n}; } } return $lastError; } --- I believe the following line is not assigning the $sResponseStream object to the Output stream property: $cmCmd-{'Properties'}-{'Output stream'}-{'Value'} = $sResponseStream; If I check the value of the Output stream property after the assignment with Win32::OLE-QueryObjectType() it indicates that it is not a valid Win32::OLE object. Am I doing the assignment incorrectly? I can't imagine this being a limitation of Win32::OLE. Thanks, Luke -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
compare two files
hi, Is there a best way to find some lines which exists in both two files? Someone has show me a method but it seems a little low efficiency. The code is as below: open (T1,1.txt) or die $!; open (T2,2.txt) or die $!; while(my $line=T2){ chomp $line; print $line,\n unless diff($line); } sub diff { my $line=shift; my $ok=0; while(T1){ chomp; if ($_ eq $line) { $ok=1; last; } } return $ok; } close T2; close T1; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Plz help
Hi All As i was continuing with perl i created a program to churn out individual directory names from a given path in windows.Here is the program: #use warnings; #use strict; Print Enter the path:; my $dir=STDIN; chomp($dir); my @DIR=split ///, $dir; print $DIR[0]; but it throws an error Search pattern not terminated Plz help. -- Thankx Regards Roopak Kr Prajapat
Re: compare two files
On Oct 11, 2005, at 11:18, Jeff Pan wrote: Is there a best way to find some lines which exists in both two files? Someone has show me a method but it seems a little low efficiency. The code is as below: Have you searched CPAN for diff modules? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Plz help
On Oct 11, 2005, at 11:37, The Roopak Times wrote: Hi All As i was continuing with perl i created a program to churn out individual directory names from a given path in windows.Here is the program: #use warnings; #use strict; Print Enter the path:; my $dir=STDIN; chomp($dir); my @DIR=split ///, $dir; print $DIR[0]; but it throws an error Search pattern not terminated The regexp for split should have the slash escaped (/\//), or m// delimiters could be changed (m{/}) to avoid backslashes, which do not contribute to readability (except for negative values of contribute :-). Just for the record, the standard module File::Spec does that. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Plz help
The Roopak Times wrote: Hi All As i was continuing with perl i created a program to churn out individual directory names from a given path in windows.Here is the program: #use warnings; #use strict; Print Enter the path:; my $dir=STDIN; chomp($dir); my @DIR=split ///, $dir; print $DIR[0]; but it throws an error Search pattern not terminated Plz help. -- Thankx Regards Roopak Kr Prajapat You need to use a slash to escaped - /\// -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Net::Telnet Updating Prompt?
Hello, I have a small issue with net::telnet 3.03. The Device I want to connect aus an OS-Level CLI and a Application-Level CLI. I have to log in to OS-Level to gai Access to Application level. Now, the problem is, the command prompt of the application is different from the prompt of the Os (hanging the OS-Level Prompt is not Possible, because its embedded). So Net::Telnet logs in and save the prompt. So it don´t need to rematch the prompt with the given expression. Is it possible to update the internal Object-attribute ($last_prompt)? Is there an easy way? Any idea at all? thanks a lot for any comment. Bastian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Plz help
The Roopak Times wrote: Hi All Hello, As i was continuing with perl i created a program to churn out individual directory names from a given path in windows.Here is the program: #use warnings; #use strict; Print Enter the path:; my $dir=STDIN; chomp($dir); my @DIR=split ///, $dir; print $DIR[0]; but it throws an error Search pattern not terminated Plz help. $ perl -le' use File::Spec; print for File::Spec-splitdir( some/dir/to/look/for/files ); ' some dir to look for files 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: :Telnet Updating Prompt?
Bastian Angerstein [EMAIL PROTECTED] asked: [net::Telnet] Is it possible to update the internal Object-attribute ($last_prompt)? From the documentation: last_prompt - last prompt read $string = $obj-last_prompt; $prev = $obj-last_prompt($string); With no argument this method returns the last prompt read by cmd() or login(). See prompt(). With an argument it sets the last prompt read to $string and returns the previous value. Normally, only internal methods set the last prompt. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: compare two files
Jeff Pan wrote: hi, Hello, Is there a best way to find some lines which exists in both two files? Your code logic says that you want to find lines in '2.txt' that are NOT in '1.txt'. Someone has show me a method but it seems a little low efficiency. Not only that but it doesn't work correctly. If a line is not found in '1.txt' then diff() will ALWAYS return 0. The code is as below: open (T1,1.txt) or die $!; open (T2,2.txt) or die $!; while(my $line=T2){ chomp $line; print $line,\n unless diff($line); } sub diff { my $line=shift; my $ok=0; while(T1){ chomp; if ($_ eq $line) { $ok=1; last; } } return $ok; } close T2; close T1; The usual way to do this is to use a hash: open T1, '', '1.txt' or die open '1.txt' $!; open T2, '', '2.txt' or die open '2.txt' $!; my %hash; while ( T2 ) { $hash{ $_ }++ } while ( T1 ) { print if exists $hash{ $_ } } __END__ 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: keeping track of the 'age' of a file
ZHAO, BING wrote: But, I figured it might be a good idea to save the file for like a week then delete it, if I know some kind of function like clock(as wild as it can get..), date etc, so after a week or so, the perl script would delete the file. The classic way to do this kind of thing is to run find(1) from cron periodically: 0 2 * * * find /some/path -type f -mtime +7 -exec rm -f {} \; If you want to do this from Perl, you either need to use cron, or write a long-running daemon-type process. cron is the best way to do it. The easiest way to check the age of a file is with Perl's -M operator: unlink $somefile if -M $somefile 7; ## file is older than 7 days You can also use the find2perl utility (part of File::Find module) to convert the find command above into Perl code. Or, you can use Randal's nifty File::Finder module (http://search.cpan.org/~merlyn/File-Finder-0.53/) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: compare two files
Jeff Pan wrote: hi, Is there a best way to find some lines which exists in both two files? I usually use the Unix comm(1) utility. Its very efficient, but the input files need to be sorted. Google for ppt comm and you can find a Perl version. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: compare two files
Your code logic says that you want to find lines in '2.txt' that are NOT in '1.txt'. thanks for all answerers. yeah,I have put less attention on that code,and have made a fatal logic error. but the way mentioned by John, putting file's all contents to a hash, maybe somewhat less efficiency when the file is large much.is it? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
automatically submitting web forms.
Hello List, I would like to be able to automagically submit a form to a server. The server requires that I give it a sequence of letters (a protein) in one box, my email, and select several radio buttons to my chosen output. In this case the server is PSIPRED protein structure prediction server @ ucl. I have no idea how to go about doing this and was wondering if someone would be kind enough to point me in the right direction (a book web site etc). I guess POST or something like that? Thanks. Dan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: automatically submitting web forms.
On 10/11/05, Dan Klose [EMAIL PROTECTED] wrote: I would like to be able to automagically submit a form to a server. Take a look at WWW::Mechanize http://search.cpan.org/dist/WWW-Mechanize/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: automatically submitting web forms.
On Oct 11, 2005, at 16:23, Dan Klose wrote: I would like to be able to automagically submit a form to a server. The server requires that I give it a sequence of letters (a protein) in one box, my email, and select several radio buttons to my chosen output. In this case the server is PSIPRED protein structure prediction server @ ucl. I have no idea how to go about doing this and was wondering if someone would be kind enough to point me in the right direction (a book web site etc). I guess POST or something like that? Have a look at WWW::Mechanize. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Using Perl Modules
Hello, Is there a way possible by which I can use a perl module without installing it on the system? Some sort of equivalent for #include /home/madhurk/myClass.h which exists in C/C++ -- Thanks Madhur -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: automatically submitting web forms.
On Tue, 2005-10-11 at 16:44 +0200, Xavier Noria wrote: On Oct 11, 2005, at 16:23, Dan Klose wrote: I would like to be able to automagically submit a form to a server. The server requires that I give it a sequence of letters (a protein) in one box, my email, and select several radio buttons to my chosen output. In this case the server is PSIPRED protein structure prediction server @ ucl. I have no idea how to go about doing this and was wondering if someone would be kind enough to point me in the right direction (a book web site etc). I guess POST or something like that? Have a look at WWW::Mechanize. Hi, Thanks for your suggestions. I am going to give it a try... However there is another way I am also going for. If you have lynx you can use: lynx =cmd_log=FOO to make a series of commands for a page. you can then use: lynx -cmd_script=FOO to rerun that submission. Thanks again. Dan. -- fxn -- Daniel Klose PhD Student - Taylor Group Mathematical Biology National Institute for Medical Research The Ridgeway Mill Hill London NW7 1AA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Using Perl Modules
On Oct 11, Madhur Kashyap said: Is there a way possible by which I can use a perl module without installing it on the system? Some sort of equivalent for #include /home/madhurk/myClass.h which exists in C/C++ I take it you mean, how can I tell Perl to look in a certain place for a module? By telling it so, with the 'lib' pragma: #!/usr/bin/perl use lib /home/japhy/modules; use MySpecialModule; # /home/japhy/modules/MySpecialModule.pm Read 'perldoc lib'. -- Jeff japhy Pinyan% How can we ever be the sold short or RPI Acacia Brother #734% the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? http://princeton.pm.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: automatically submitting web forms.
On Oct 11, 2005, at 17:27, Dan Klose wrote: Thanks for your suggestions. I am going to give it a try... However there is another way I am also going for. If you have lynx you can use: lynx =cmd_log=FOO to make a series of commands for a page. you can then use: lynx -cmd_script=FOO Interesting, looks like a hack compared to using WWW::Mechanize, but it's your choice. Is there a way to pass parameters to the -cmd_script run to override previous form values? Or do you need to edit it? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: automatically submitting web forms.
On Tue, 2005-10-11 at 17:47 +0200, Xavier Noria wrote: On Oct 11, 2005, at 17:27, Dan Klose wrote: Thanks for your suggestions. I am going to give it a try... However there is another way I am also going for. If you have lynx you can use: lynx =cmd_log=FOO to make a series of commands for a page. you can then use: lynx -cmd_script=FOO Interesting, looks like a hack compared to using WWW::Mechanize, but it's your choice. It is a hack... but I just wanted it done quickly (five minutes ago). I will use WWW::Mechanize as I will have to do this for several web tools and this approach is too slack! Is there a way to pass parameters to the -cmd_script run to override previous form values? Or do you need to edit it? As far as I am aware (not very) no, I just did an edit All I did was open lyxn on that page with the key logging, then wrote a script to change my protein sequence each time. -- fxn -- Daniel Klose PhD Student - Taylor Group Mathematical Biology National Institute for Medical Research The Ridgeway Mill Hill London NW7 1AA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: hi
Please respond to the list. I'm not always available to answer questions. Now for your questions, loosely numbered: 1,3) You probably either included use strict or perhaps included some other code that used strict. That enforces the requirement to lexically scope your variables, among other things. 2) Lexically scoping your variables does not affect your ability to use your variables at all. It just means that they automatically get created at the 'my' statement and destroyed at the end of the code block. If you do need a variable to exist throughout the entire script, you can declare it at the top of your script or use 'our' instead of 'my'. And finally, the question you didn't ask, but I'll answer anyway. I would seriously recommend adding 'use strict' and 'use warnings' in all of your scripts. It can be a real pain at first when you're not used to using it, but it can save you a lot of time in the long run. Keep an eye on the list and you can get a lot of good examples. This question comes up a lot with people who are self-taught. I had to go back and learn to use strict after coding for about a year, and I really wish I had started sooner. A few examples of how adding 'use strict' can possibly save you time: 1. You're looping through an array, using a variable inside the loop. Something fails and the variable doesn't get updated. You don't realize until hours later that all of your output is worthless because half of the loops were just repeating the same value as the loop before it. By declaring the variable using 'my' inside the loop, you can avoid this because the variable will be automatically reinitialized each time. 2. You can't figure out why your program isn't generating the expected output. You spend an hour putting debug statements throughout your script, only to find that you misspelled the name of the variable in your print statement. Perl was happy to oblige you by creating a new, empty variable with that name and printing it for you. By adding 'use strict' to the top of your script, you can avoid this because Perl will complain about the variable not being declared. Check out 'perldoc strict' for more detailed info. -Original Message- From: ZHAO, BING [mailto:[EMAIL PROTECTED] Sent: Monday, October 10, 2005 4:20 PM To: Timothy Johnson Subject: Re: hi why do I need to specify $,%,@ using 'my', sometime I do need them to be global so that I can use their property, like scalar @shrimp to get a #, and I have beening programming for a while, and I seldom use my, and this is the 1st time unix has generated such kind of warning, why? thank you very much. bing -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: HOA idiocy.
THIS is what I have this works I don really know if this is what you where looking for you can access elements such I did in the print statement it peints c use strict; use warnings; my %HOA = ( one = ['a','b','c'], two = ['c','z','s'], ); print $HOA{one}[2]\n; On 10/10/05, Dan Klose [EMAIL PROTECTED] wrote: Hello list. I have a hash of arrays but when I come to run the script I get the following error: Odd number of elements in hash assignment at ./all2seq.pl line 15. I can't for the life of me work out why I am getting this error! I have never hand written a HOA and so I have tried this: my %properties = ( aliphatic = qw[I L V], aromatics = qw[F Y W H], phobic = qw[I L V M C F Y W H K T G A], charged = qw[H K R E D], polar = qw[Y W H K R E D Q N S C T], positive = qw[R K H], small = qw[V P A G C S N D T], tiny = qw[G A C S], ); I have tried with and without the on the keys. This is probably something very trivial but I just can't work out what it is. If someone could make the pain go away that would be great. Thanks and apologies. Dan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Regex matching problem
Hi, I've got a .txt with 25 of numerically named lines (example). (Example): 1. First Name: 2. Last Name: 3. Age: 4. Company: 5. Quality of the service: ... 25. Would you recommend our services: I'm trying to strip everything after the colon so I'm just left with the answer. In case there is no answer to a question I'm trying to leave it as a -. Where am I going wrong? All I get is the default - in case no answers is given ... #!/usr/bin/perl # strip_answers.pl use strict; use warnings; # array to store the stripped results my @information; # open a filehandle to output.txt (where the results are stored) in read mode open (IN, '', 'output.txt') or die Can't open output.txt: $!\n; # while the filehandle is open, read each line and see if it matches # the regular expression while (IN) { # iterate though the filehandle 25 times (one for each question). I set $i to 1 as # the first question begins with the number 1 for (my $i=1; $i26; $i++) { # see if the regexp matches if ($_ =~ /^$i\..+:\s(.+)/) { $information[$i] = $1; # if there is no match, set the value to - } else { $information[$i] = -; } } } close IN or die Can't close output.txt: $!\n; # cycle through theh array to check the results foreach (1..$#information) { print $information[$_]\n; } Thanking everyone in advance. Cheers, Juan Manuel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Regex matching problem
On Oct 11, Juan Manuel Casenave said: 1. First Name: 2. Last Name: 3. Age: #!/usr/bin/perl # strip_answers.pl use strict; use warnings; # array to store the stripped results my @information; # open a filehandle to output.txt (where the results are stored) in read mode open (IN, '', 'output.txt') or die Can't open output.txt: $!\n; # while the filehandle is open, read each line and see if it matches # the regular expression while (IN) { # iterate though the filehandle 25 times (one for each question). I set $i to 1 as # the first question begins with the number 1 for (my $i=1; $i26; $i++) { Here's where your logic fails. Your outer while loop is reading a line; your inner for loop is doing the same thing 26 times! In addition, you're starting $i at 1, which means your setting $information[1], and never $information[0] (which is where arrays start). How about this: my @info; while (IN) { # stop after the 25th line ($. holds line number) last if $. 25; # get the stuff after the : my $answer = (split /:/, $_, 2)[1]; # set $answer to - if $answer doesn't # have a non-whitespace character in it $answer = - if $answer !~ /\S/; push @info, $answer; } And then you loop through it like so: for my $idx (0 .. $#info) { print $idx + 1, : $info[$idx]\n; } -- Jeff japhy Pinyan% How can we ever be the sold short or RPI Acacia Brother #734% the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? http://princeton.pm.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
Perl equivalent of JavaScript match
Hi. I need to grab regex matches from a string in perl. The string is an enum data type in Mysql. i.e. enum('Berks','Carbon','Lehigh','Montgomery') So basically I need a match on alphabetic chars between single quotes. No problem. But I'd like to be able to grab each match and store it in an array (in as few lines as possible). I was told that split has an option that grabs delimiter matches instead of dropping delimiters and returning what's between them. Any ideas? Thanks. Frank __ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Regex matching problem
Juan Manuel Casenave wrote: Hi, I've got a .txt with 25 of numerically named lines (example). (Example): 1. First Name: 2. Last Name: 3. Age: 4. Company: 5. Quality of the service: ... 25. Would you recommend our services: I'm trying to strip everything after the colon so I'm just left with the answer. In case there is no answer to a question I'm trying to leave it as a -. Where am I going wrong? All I get is the default - in case no answers is given ... #!/usr/bin/perl # strip_answers.pl use strict; use warnings; # array to store the stripped results my @information; # open a filehandle to output.txt (where the results are stored) in read mode open (IN, '', 'output.txt') or die Can't open output.txt: $!\n; # while the filehandle is open, read each line and see if it matches # the regular expression while (IN) { # iterate though the filehandle 25 times (one for each question). I set $i to 1 as # the first question begins with the number 1 You are working too hard. For each question, you already have the index(1 thru nn), so you don't need to go through this 25 times each time. Also don't need to have $_ =~ since unless you override that is what is used. So you could do something like: here is a small script pulling a null field on 1: #!perl use strict; use warnings; use Data::Dumper; $_ = '1. First Name:'; my @information = (); if ( /^(\d{1,2})\..+:\s*(.{0,})/ ) { $information[$1] = $2; if ( $2 eq '' ) { $information[$1] = '-'; } } print Dumper([EMAIL PROTECTED]); Output: [C:/CurrWrka/00CommonPerl] aapl006f $VAR1 = [ undef, '-' ]; [C:/CurrWrka/00CommonPerl] I have done the trivial case of no data. You only need verify that it will work with data. Wags ;) for (my $i=1; $i26; $i++) { # see if the regexp matches if ($_ =~ /^$i\..+:\s(.+)/) { $information[$i] = $1; # if there is no match, set the value to - } else { $information[$i] = -; } } } close IN or die Can't close output.txt: $!\n; # cycle through theh array to check the results foreach (1..$#information) { print $information[$_]\n; } Thanking everyone in advance. Cheers, Juan Manuel. *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
fork + objects + logging
fork(): I'm trying to put a perl wrapper around some clunky java code to make it play nicer. The best arrangement I have come up with is to use: open(JVM, java_app.sh |); I suppose I could use system() as well, but if I read correctly the STDOUT from the java application would become the STDOUT of my perl application. I'm pretty sure I don't want to do that. So for now I'm going to capture it and see if there is anything interesting in it. BTW: Building this application by creating the test modules before the code has been interesting. I'm not 100% test first then write, but I'm getting better. Is it typical/reasonable to consider one test script for each function? Currently I have a mostly procedural module approach with a big fat while(1) { my $pid = fork; if ( $pid ) { # PARENT ... } else { # CHILD ... open(JVM, java_app.sh |); ... exit 0; } } kind of code model to get the work done. I'm curios if this could be and should be dumped into an Object. Any reason not to fork() inside an Object? I'm not sure it makes sense, since each Object would 'exit 0;' on itself. Kind of a bizarre approach. I'm a little hesitant to fork() too much stuff where I'm at. It's a Sun box and there are some very real problems with forking when compiled under gcc. Somewhere there's a bug but it took a better man than me to find the report on the internet. Logging: I am using a package Log::Dispatch to do my logging. Is there any penalty to loading the same modules for Log::Dispatch into multiple Packages (Main plus all my custom package/modules)? IIRC this should share the memory but allow each package space to see the Log::Dispatch methods with no penalty memory or speed. True? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl equivalent of JavaScript match
Frank Geueke [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi. I need to grab regex matches from a string in perl. The string is an enum data type in Mysql. i.e. enum('Berks','Carbon','Lehigh','Montgomery') So basically I need a match on alphabetic chars between single quotes. No problem. But I'd like to be able to grab each match and store it in an array (in as few lines as possible). I was told that split has an option that grabs delimiter matches instead of dropping delimiters and returning what's between them. Any ideas? Thanks. Frank Here is what I would use: $ perl -mwarnings -mstrict my $data = q|enum('Berks','Carbon','Lehigh','Montgomery')|; my @vals = $data =~ m|'(.+?)'|g; # the expression you want print( map $_\n, @vals ); Ctrl-D Berks Carbon Lehigh Montgomery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl equivalent of JavaScript match
Hi Todd, I'm completely new to perl. I'm have to work in biology using perl, postgresql (as database) and clustalw or multalin (as the alignment tool). I'm stating my problem briefly: In the postgresql db the data is clustered using complete linkage clustering. I've to connect to that db, fetch those data, feed it to the multiple alignment tool, run it and show the results. All these needs to be automated using perl. I'll be obliged if you help me with this. Thanks, Angshu On 10/11/05, Todd W [EMAIL PROTECTED] wrote: Frank Geueke [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi. I need to grab regex matches from a string in perl. The string is an enum data type in Mysql. i.e. enum('Berks','Carbon','Lehigh','Montgomery') So basically I need a match on alphabetic chars between single quotes. No problem. But I'd like to be able to grab each match and store it in an array (in as few lines as possible). I was told that split has an option that grabs delimiter matches instead of dropping delimiters and returning what's between them. Any ideas? Thanks. Frank Here is what I would use: $ perl -mwarnings -mstrict my $data = q|enum('Berks','Carbon','Lehigh','Montgomery')|; my @vals = $data =~ m|'(.+?)'|g; # the expression you want print( map $_\n, @vals ); Ctrl-D Berks Carbon Lehigh Montgomery -- 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