RE: if else elsif
-Original Message- From: Chris Stinemetz [mailto:cstinem...@cricketcommunications.com] Sent: Thursday, March 17, 2011 14:16 To: beginners Subject: if else elsif I am trying to return new values based on if else. I understand the idea of using if else, but I am not sure I have placed in the right place. I was assuming I would want to insert it before the array is sorted. Thank you in advance. This mailing list is helping me understand perl greatly! I am getting the following error: Use of uninitialized value within @data in pattern match (m//) at ./DOband.pl line 19, $fh line 485. #!/usr/bin/perl use warnings; use strict; my $filepath = 'C:/temp/PCMD'; my $outfile = 'output.txt'; open my $fh, '', $filepath or die ERROR opening $filepath: $!; open my $out, '', $outfile or die ERROR opening $outfile: $!; my @array; while ($fh) { next unless /;/; chomp; my @data = ( split /;/ )[31,32,38,39,261]; if (@data[39] =~ /15/) { 2 } else { 1 } You are only pulling 5 elements into @data, yet as part of your test, you are looking at the 39th element, but you really element 3. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us push @array, join \t, @data; } @array = sort { my @aa = split /\t/, $a; my @bb = split /\t/, $b; $aa[0] = $bb[0] or $aa[1] = $bb[1] or $aa[2] = $bb[2]; } @array; print $out $_\n foreach @array; close $out; #RTD 1 unit = 4 chips RUM Field 16 0 - 2^16 - 1 milliseconds Chris Stinemetz -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Testing File Contents
-Original Message- From: Matt [mailto:lm7...@gmail.com] Sent: Wednesday, March 02, 2011 11:25 To: beginners@perl.org Subject: Re: Testing File Contents # Untested use strict; use warnings; open my $fh, '', my_file; while($fh){ if ($_ !~ /my_string/) { # Do something } } This triggers on EVERY line of the file that does not contain the string. I just want to trigger once if its no where in the file. Add a simple switch which is set to zero. Then look for the value you want. When found then you should be able to set to nonzero and leave the while. Then you should be able to check: if switch is not true, then send the email... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us The other way would be on shell - # Untested grep my_string my_file if [ $? -eq 1 ] then echo Do something fi ~Parag On Wed, Mar 2, 2011 at 9:55 AM, Matt lm7...@gmail.com wrote: I am looking for a simple way to test if a file does not contain a string. This is on a linux box. if myfile does not contain mystring { #do_something; } The file is basically a list of names and I want to test that a certain name is not in there. Is there an easy way to do that? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Getting LineFeed for Excel within q quoted field
-Original Message- From: John Delacour [mailto:johndelac...@gmail.com] Sent: Wednesday, January 05, 2011 18:32 To: Perl Beginners Subject: Re: Getting LineFeed for Excel within q quoted field At 17:56 -0600 04/01/2011, Wagner, David wrote: I am generating an CSV and want a couple of fields to have soft returns in them. I went into Excel and added a couple of soft returns to a couple of different fields and then saved the modified file back to a CSV. If you run this script you will have what you seem to want. So far as I know any line ending whether CR LF or CRLF is a new row signal and if you want new lines within a cell then you need to *enclose the cell contents in double quotes.* #!/usr/bin/perl use strict; my $csv=temp.csv; open CSV, $csv; print CSV qq~1,2,3\n4\n5\n6,7,8~; [Wags] [Wags] For something that should have been relatively easy, this has been a real pain in getting to work as I would have expected it to. I am using printf to do my printing and in this case, was using sprintf to place into a hash and when done, then I was doing the write to the file. I was placing within double quotes, but still ending up with the question marks within Excel. So I tried the binmode approach, but ended up a mixed bag there. Now everything was LF and the two columns that had the data with soft returns, the first one showed the question marks while the second column everything looked good. So to get things in what I believe was a correct setup and using the binmode which was giving me what I thought Excel wanted, I replaced my \n with \r\n and did the \x0a for the soft returns. Now when it is opened in Excel, there are no question marks in either of the two columns that I am doing soft returns.. To me, this was way too much work for something that should have been relatively easy to accomplish. If I was doing anything OTHER than the \x0a, it was done. But since Perl is trying to help me, it took me down a road of way too much work to get this accomplished. I appreciate all the inputs and suggestions. Without them, I would not have completed what I needed to do. Thanks so much... Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us close CSV; `start excel.exe $csv`; On the Mac, and I guess on UNIX, then you need to use \r instead of \n to have the multiple lines show in the cell. As a new row signal the \n \r or \r\n will work fine on both platforms regardless of the different new line conventions. #!/usr/bin/perl use strict; my $csv=temp.csv; open CSV, $csv; print CSV qq~1,2,3\r4\r5\n6,7,8~; close CSV; `open -a 'Microsoft Excel' '$csv'`; JD -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Getting LineFeed for Excel within q quoted field
-Original Message- From: John Delacour [mailto:johndelac...@gmail.com] Sent: Thursday, January 06, 2011 11:33 To: beginners@perl.org Subject: RE: Getting LineFeed for Excel within q quoted field At 11:55 -0600 06/01/2011, David Waner wrote: From: John Delacour [mailto:johndelac...@gmail.com] #!/usr/bin/perl use strict; my $csv=temp.csv; open CSV, $csv; print CSV qq~1,2,3\n4\n5\n6,7,8~; For something that should have been relatively easy, this has been a real pain in getting to work as I would have expected it to. ...So to get things in what I believe was a correct setup and using the binmode which was giving me what I thought Excel wanted, I replaced my \n with \r\n and did the \x0a for the soft returns. Now when it is opened in Excel, there are no question marks in either of the two columns that I am doing soft returns.. You are still making a mountain out of a molehill. The first point is that there is no such character as a 'soft return'. The term is used loosely in wordprocessor-speak etc. to refer to an apparent new line that is due to word wrapping. If you think you see returns in this paragraph then you are mistaken. Make the window wider and, unless you're using a very inadequate mailer, you will discover it is one line without returns that stretches to fill the width of the window. You day you used \x0A for your imaginary 'soft returns' when all you're doing is respecting Excel's convention of using \n for the in-cell hard return in a Windows document. Why not just use \n, which is precisely the same thing? Ok, I did exactly as stated and only used \n for all the processing within my script for writing out the csv that I am after. Excel does NOT do the right thing in a text wrapped column with \n. What I now get is two question marks and no wrap at all. When you say there are no 'soft returns', I accept that, but when I use \x0a and open the column to the widest elemnt I have in that column, they all line up as I expect. I may be making a mountain out of a molehill, but everything that I am seeing says, to get it correctly displayed in Excel, only the \x0a should be used in column which has double quotes around it. I even tried your simple script and with that, the question marks are part of the output. I really don't know what 'binmode' has to do with anything either. You're dealing in this case with plain text and you're working only in Windows so all that's needed is to discover what rules Excel goes by and respect them. That is what I have been doing. Crlf is what I see in the text file for end of lines and lf is what I see for keeping my columns in a correctly setup display of data. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us JD -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Getting LineFeed for Excel within q quoted field
-Original Message- From: Rob Dixon [mailto:rob.di...@gmx.com] Sent: Thursday, January 06, 2011 21:49 To: David Wagner Cc: beginners@perl.org Subject: Re: Getting LineFeed for Excel within q quoted field At 11:55 -0600 06/01/2011, David Wagner wrote: For something that should have been relatively easy, this has been a real pain in getting to work as I would have expected it to. ...So to get things in what I believe was a correct setup and using the binmode which was giving me what I thought Excel wanted, I replaced my \n with \r\n and did the \x0a for the soft returns. Now when it is opened in Excel, there are no question marks in either of the two columns that I am doing soft returns.. Hi David The strings \n and \x0A are identical - it is the translation done by Perl's IO system that makes the difference. From this description it looks like you have things working. The question marks in the fields were surely a bad sign? Please say if you still need help. - Rob I appreciate the response. Yes, I have it going, but to me it seems like there should be an easier way of doing it. I ended up replacing each \n with \r\n and doing the \x0a. Then when I am ready to write out the csv, then I do binmode on the output file and it writes out correctly. So the bottom line becomes if using hex changes and it stands for some pre-defined value or variable within Perl, then one has to take some extra ordinary measures to make things work... Slow but sure... Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Getting LineFeed for Excel within q quoted field
Original Message- From: Parag Kalra [mailto:paragka...@gmail.com] Sent: Wednesday, January 05, 2011 16:42 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: Perl Beginners Subject: Re: Getting LineFeed for Excel within q quoted field Ok. May be I need to understand your scenario in better way. Kindly correct me if I am wrong. So this is what my understanding is: 1. Your aim is to generate a CSV file 2. You are parsing a flat text file and substituting ^ with new line character (0a) 3. But when you are viewing the file in Excel the new character is not added [Wags] Not quite. I look at the file using Hex application. What I see in the file is 0d0a where I would expect to ONLY see 0a. As another test, I changed the 0a to 0f and Ran my script. When I look at the file, it ONLY has the 0f. So what I am thinking is That Perl sees the 0a and says he is not doing it right, so we will replace with a 0d0a since on Windows. Simplistic, but that is what I am seeing. So how do I tell Perl to leave alone on 0a. Do I have to play with $? Or ??? Making no sense to me at this point... So what are the thoughts now??? If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us 4. And reason as per what you think is that Excel is expecting 0a but what is getting inserted is 0d0a 5. Also I assume you are doing all these experiments on Windows box. The reason I am asking this is because both Linux and Windows treat new line character in different way. Have a look - http://www.perlmonks.org/index.pl?node_id=68687 And from the same reference it appears to me that if you want to add only 0a, may be you need to handle the csv file in ascii format Cheers, Parag On Wed, Jan 5, 2011 at 3:28 PM, Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com wrote: -Original Message- From: Parag Kalra [mailto:paragka...@gmail.com] Sent: Wednesday, January 05, 2011 12:13 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: Perl Beginners Subject: Re: Getting LineFeed for Excel within q quoted field It may have to do something how you are opening the file handler of CSV file. The data you seen in the csv file may depend on which encoding you have used while creating the file. Couple of questions: 1. I believe currently you are view the file on Windoze, when you view the file on Unix, do you still see the graphics. [Wags] I am viewing with Scite and also a Hex editor. But even when I am doing the change using s/\^/\x0a/g I am seeing in the file itself as 0d0a and not just the 0a. Obviously I am missing something very basic at this point. Excel is expecting a 0a indicating a soft return, and I have verified I am using the right code, but comes out incorrectly. What am I missing?? Thanks much for any insight.. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us 2. Is graphics visible on most of the editors or have you used only 1 editor? Cheers, Parag On Tue, Jan 4, 2011 at 3:56 PM, Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com wrote: I am generating an CSV and want a couple of fields to have soft returns in them. I went into Excel and added a couple of soft returns to a couple of different fields and then saved the modified file back to a CSV. I opened in a editor and reviewed what was there. What I saw was: xxx(lf) # shows as LF verses the std end of line for windows of CR/LF Yyyy(lf) I left the editor and double clicked again and brought into Excel. The data had the soft returns. So I added the following to my processing: for ( @MyWorka ) { if ( /\^/ ) { s/\^/\x0a/g; # I have tried the \r and even \n and when opened in # Excel always has the graphic explained below } } Whereever there is a ^ replace with a hex A which to me is a LineFeed ( incorrectly as I have read ). I run and create my csv. I double click the file and it opens in Excel. It appears to be working, but where each linefeed is you get a little graphic with a question mark inside a circle. In a way it is doing the soft returns, but obviously not correctly. Any thoughts on what I am doing incorrectly?? Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Getting LineFeed for Excel within q quoted field
-Original Message- From: Parag Kalra [mailto:paragka...@gmail.com] Sent: Wednesday, January 05, 2011 12:13 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: Perl Beginners Subject: Re: Getting LineFeed for Excel within q quoted field It may have to do something how you are opening the file handler of CSV file. The data you seen in the csv file may depend on which encoding you have used while creating the file. Couple of questions: 1. I believe currently you are view the file on Windoze, when you view the file on Unix, do you still see the graphics. [Wags] I am viewing with Scite and also a Hex editor. But even when I am doing the change using s/\^/\x0a/g I am seeing in the file itself as 0d0a and not just the 0a. Obviously I am missing something very basic at this point. Excel is expecting a 0a indicating a soft return, and I have verified I am using the right code, but comes out incorrectly. What am I missing?? Thanks much for any insight.. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us 2. Is graphics visible on most of the editors or have you used only 1 editor? Cheers, Parag On Tue, Jan 4, 2011 at 3:56 PM, Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com wrote: I am generating an CSV and want a couple of fields to have soft returns in them. I went into Excel and added a couple of soft returns to a couple of different fields and then saved the modified file back to a CSV. I opened in a editor and reviewed what was there. What I saw was: xxx(lf) # shows as LF verses the std end of line for windows of CR/LF Yyyy(lf) I left the editor and double clicked again and brought into Excel. The data had the soft returns. So I added the following to my processing: for ( @MyWorka ) { if ( /\^/ ) { s/\^/\x0a/g; # I have tried the \r and even \n and when opened in # Excel always has the graphic explained below } } Whereever there is a ^ replace with a hex A which to me is a LineFeed ( incorrectly as I have read ). I run and create my csv. I double click the file and it opens in Excel. It appears to be working, but where each linefeed is you get a little graphic with a question mark inside a circle. In a way it is doing the soft returns, but obviously not correctly. Any thoughts on what I am doing incorrectly?? Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Getting LineFeed for Excel within q quoted field
I am generating an CSV and want a couple of fields to have soft returns in them. I went into Excel and added a couple of soft returns to a couple of different fields and then saved the modified file back to a CSV. I opened in a editor and reviewed what was there. What I saw was: xxx(lf) # shows as LF verses the std end of line for windows of CR/LF Yyyy(lf) I left the editor and double clicked again and brought into Excel. The data had the soft returns. So I added the following to my processing: for ( @MyWorka ) { if ( /\^/ ) { s/\^/\x0a/g;# I have tried the \r and even \n and when opened in # Excel always has the graphic explained below } } Whereever there is a ^ replace with a hex A which to me is a LineFeed ( incorrectly as I have read ). I run and create my csv. I double click the file and it opens in Excel. It appears to be working, but where each linefeed is you get a little graphic with a question mark inside a circle. In a way it is doing the soft returns, but obviously not correctly. Any thoughts on what I am doing incorrectly?? Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: glob files and subdirectories
-Original Message- From: Noah [mailto:noah-l...@enabled.com] Sent: Wednesday, December 08, 2010 12:42 To: Perl Beginners Subject: glob files and subdirectories Hi there, what is the easiest way to get all the filenames like *html in the root directory and all subdirectories? The glob command appears to just sit at the root directory. [Wags] Use File::Find. Part of base Perl load. Has examples, etc. Will go to subdirectories, etc. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us Cheers, Noah -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Word boundaries
-Original Message- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: Tuesday, July 20, 2010 15:06 To: Perl Beginners Subject: Re: Word boundaries Rob Dixon wrote: On 20/07/2010 16:22, Chandan Kumar wrote: Small confusion about word boundaries. word boundaries matches anything between non-word character and word character ,right. Not quite. Quite. /\b/ matches any (zero-length) point in a string between a word and a non-word character, Correct. or between a word character and the beginning or end of the string, Incorrect. It matches *only* between \w and \W characters. But for the test you were doing, you could have added this: (\b{0,1}\W\b) which would have gotten you the ? as the output, but unsure that that is what you really wanted... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: XML Parser Error
-Original Message- From: Open Source [mailto:open.sou...@gmx.com] Sent: Thursday, April 15, 2010 11:41 To: Beginners, Perl Subject: XML Parser Error I'm getting this error: Undefined subroutine XML::Simple::XMLin called at ./sample.pl line 3. Here's my code and input file: use XML::Simple; use Data::Dumper; $data = XMLin(sample.xml); print Dumper($data); ?xml version='1.0'? employee nameJohn/name age43/age genderM/gender departmentOperations/department /employee -- I took your code, copied, made a file called sample.xml. Ran and it worked without error. I am running on XP Sp3, AS 5.10.1. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Services 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://Fedex.com/us To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: being smart about script structure
-Original Message- From: Bryan R Harris [mailto:bryan_r_har...@raytheon.com] Sent: Friday, December 11, 2009 15:10 To: Beginners Perl Subject: Re: being smart about script structure Seems like a waste to do step 2 in a subroutine since we only do it once, but it does fill the main body of the script with code-noise that makes it harder to debug overall logic problems... Not much logic here, but certainly in more complex scripts. A waste of what exactly? You don't have a limited budget of sub keywords. I guess I figured you had to build in structure (variables?) to be able to pass things back and forth from subroutines that normally you wouldn't have to set up. For example, if I'm populating a complex variable @d with lots of pointers, hashes, arrays, etc. within, if I populate that within a subroutine, how do I get it back out conveniently without it making a whole nother copy of it outside? If it's 500 MB, isn't that horribly inefficient? Plus, I have to keep track of it. You pass as a refernce as ni called_sub(\...@d); Now when you update, you are updating @d and not a copy. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us Subroutines are not just about code reuse. Which is more readable: my $x = [ # Big complex data structure # ... # ... # ... # ... ]; my $y = [ # Big complex data structure # ... # ... # ... # ... ]; for my $p ($x) { for my $q ($y) { #Big # complex # multi-statement # manipulation # of # $p # and # $q } } Or this: my $x = populate_x(); my $y = populate_y(); for my $p (@$x) { for my $q (@$y) { process_pq($p, $q); } } Or even: my $x = populate_x(); my $y = populate_y(); process_xy($x, $y); # xy_process now contains the for loops I guess my only struggle there is that any perl person can read the perl code. At first glance, I have no clue what populate_x() does because you gave it a name that's not in the camel book. The point is that in the first version, you are constantly bouncing from the big-picture ideas to the low-level messy details. By abstracting code out into subroutines populate_x(), populate_y() and process_xy(), you have the main script which deals in big ideas, and three subroutines which deal with messy details. A subroutine should do one thing, and do it well. This is terrific advice. Any suggestions? Where can I read more on this stuff? What questions should I be asking that I'm not smart enough to ask? The best that I can suggest is to read other people's code and ask other people to read your code. Think of a specific example and come up with a plan of how you would code it, and ask for criticism. No other perl programmers here, unfortunately. Good advice, though. - Bryan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: printf
-Original Message- From: Aimee Cardenas [mailto:aim...@sfbrgenetics.org] Sent: Tuesday, October 27, 2009 15:53 To: Perl Beginners Subject: printf Hi, All! I need to fix the width of some strings padding with leading spaces if necessary. I wanted to use printf but I don't know if you can put a variable in the format part the the printf statement. For example, if I wanted to use the following format type: printf OFILE %7s\n, $str; Yes you can. printf OFILE %*s\n, $varlen, $var; If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us but instead of '7' have a variable such as $w there, how might I do this? Or is there a better function for what I'm trying to do? Thanks, Aimee Cardenas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Building a fmt line for printf with a carriage return
I thought I had done this before, but I guess not. I build a formt line for printf like: q[%-3s%-4s%5s%6s]; But I want to insert a carriage return after say %-4s( I have a nubmer of fields and depending on the size, it is not a constant after column 2, but could be column 3 or 23. I have tried: q[%-3s%-4s] . qq[\\n] . q[%5s%6s] or q[%-3s%-4s\n%5s%6s] But no matter what I do, it does not generate the carriage return. Shows up in the line. I know I am missing some very basic point, but has escaped me. Here is the sample script I was playing with: #!/usr/bin/perl use strict; use warnings; my $MyLine1 = q[%2d %5s %6s]; my $MyLine2 = q[%2d %5s \n%6s]; printf ${MyLine1}\n, 2, q[abc], q[def]; printf $MyLine2\n, 2, q[abc], q[def]; Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: match pattern
-Original Message- From: raphael() [mailto:raphael.j...@gmail.com] Sent: Friday, September 18, 2009 10:40 To: Perl BEGIN Subject: match pattern Hi How do I pick out matching words if there are more than one on the same line? Example INFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com -- while () { if ( m!(www.\S+.com)!s ) { # print $1\n; # print $\n; print; }; } -- Here is one way: while (DATA) {# used __DATA__ for testing while ( m!(www.\S+.com)!ig ) { # print $1\n; # print $\n; print $1 . \n; }; } You only need to add the open for the output. The script looked like: #!/usr/bin/perl use strict; use warnings; while (DATA) { while ( m!(www.\S+.com)!ig ) { # print $1\n; # print $\n; print $1 . \n; }; } __DATA__ www.site01.com www.site02.com www.site03.com www.site04.com If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us I want to get all the 'match' in the INFILE.TXT on separate lines to OUTFILE.TXT www.site01.com www.site02.com www.site03.com www.site04.com But all I get is www.site01.com www.site04.com If I try $1 or $ I only get two instances of 'match' from the first in the line. Any help is appreciated -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Printing a hash of hashes of arrays
-Original Message- From: Ian [mailto:pcs...@gmail.com] Sent: Thursday, August 27, 2009 11:43 To: beginners@perl.org Subject: Printing a hash of hashes of arrays Pure beginners question. I'm creating a hash of arrays like this : $ihash{$3}{$1} = [...@itab]; For now I was able to get the data using Dumper but I need to create a pretty report. How do I loop over this hash/hash of arrays to print it out? You did not give any real details as to what the data would look like other than hash and array. What is in the array? Numbers? Alpha? AlphaNumic? Here is a shot which is very simplistic: #!/usr/bin/perl use strict; use warnings; my %ihash = (); $ihash{a}{a} = [1,2,3,4,5]; $ihash{a}{b} = [2,3,4,5,6]; $ihash{b}{a} = [3,4,5,6,7]; my $wrkkeya; my $wrkkeyb; for $wrkkeya (sort keys %ihash) { for $wrkkeyb ( sort keys %{$ihash{$wrkkeya}} ) { printf %-3s%-3s , $wrkkeya, $wrkkeyb; for (@{$ihash{$wrkkeya}{$wrkkeyb}} ) { printf %3d, $_; } print \n; } } Output: a a 1 2 3 4 5 a b 2 3 4 5 6 b a 3 4 5 6 7 A start... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us Thank you. -- Ian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: one liner in Windows to replace string
-Original Message- From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Monday, August 24, 2009 10:46 To: Beginners Perl Cc: tony1234567...@yahoo.co.uk Subject: one liner in Windows to replace string perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\test.txt I created the file and ran the one liner. Made the changes as expected. Created the back up,etc. Running as 5.8.9 build 825 under XP SP 1 If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us Trying to replace a string with this one line perl ... in Windows it does not seem to work ... File test.txt contents is ... CONSTANT 100 CONSTANT 200 nothing changes ... acts as if it does not 'see' the CONSTANT string. Help because it looks like it should work !!! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: one liner in Windows to replace string
From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Monday, August 24, 2009 13:20 To: Shawn H. Corey; Wagner, David --- Senior Programmer Analyst --- CFS Cc: Beginners Perl Subject: Re: one liner in Windows to replace string I am happy that it works with double quotes BUT now, when I try to get all files in a directory with a certain extension, the following does not work ... perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\*.txt Tony, This becomes dependent upon what shell you are running under. If I run your command minus \ on \* under my Korn shell, it pulls in all the times. What I did was substitute s/// to print and it gave me all the files I wanted. My command was; perl -p -e 'print' *.aapl001q.txt But when I run under cmd32.exe, then it does not work and I get the following error: Can't open *.aapl001q.txt: Invalid argument. If you have access to the Perl CookBook, it has several ways of replicating the glob type feature within the script itself. You can use keyword glob or as in @list = *.txt or @list = glob(*.txt). You can also hand on a readdir and use grep to pull what you want into a array. Some thoughts... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us does not like th leading * in the file name when I try to pull all .txt files ... Help again. From: Shawn H. Corey shawnhco...@gmail.com To: Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com Cc: Tony Esposito tony1234567...@yahoo.co.uk; Beginners Perl beginners@perl.org Sent: Monday, 24 August, 2009 12:57:27 Subject: Re: one liner in Windows to replace string Wagner, David --- Senior Programmer Analyst --- CFS wrote: I ran under windows with what Tony sent, both the cmd and a korn shell and both worked and updated as expected.. If you have any questions and/or problems, please let me know. Thanks. What version of Windows? The last time I used Windows was XP and it would see single quotes as: perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\test.txt which, of course, don't work. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: one liner in Windows to replace string
From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Monday, August 24, 2009 14:09 To: Shawn H. Corey Cc: Wagner, David --- Senior Programmer Analyst --- CFS; Beginners Perl Subject: Re: one liner in Windows to replace string Looks good but it bombs ... the Perl interpreter crashes from the DOS prompt ... using version 5.10.0 build 1005 from ActiveState. I am running AS 5.8.9 and when I run from cmd32.exe, it never comes back to me again. If I run under MKS Korn shell, then all is fine using the code that Shawn provides. I am not doing the update, but just printing out 14 files using the glob concept. So 5.10 aborts and 5.8.9 hangs. Not a good setup, but it is Windows. ;)) If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us But it was better than what I had, that's for sure This makes for a bit of a mind teaser thanks to it being on Windoze ... :-) From: Shawn H. Corey shawnhco...@gmail.com To: Tony Esposito tony1234567...@yahoo.co.uk Cc: Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com; Beginners Perl beginners@perl.org Sent: Monday, 24 August, 2009 14:49:47 Subject: Re: one liner in Windows to replace string Tony Esposito wrote: I am happy that it works with double quotes BUT now, when I try to get all files in a directory with a certain extension, the following does not work ... perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\***.txt does not like th leading * in the file name when I try to pull all .txt files ... Help again. perl -p -i.bak -e beg...@argv=map{glob}@ARGV}s/CONSTANT/VARIABLE/ C:\*.txt -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy.
RE: one liner in Windows to replace string
-Original Message- From: Shawn H. Corey [mailto:shawnhco...@gmail.com] Sent: Monday, August 24, 2009 11:00 To: Tony Esposito Cc: Beginners Perl Subject: Re: one liner in Windows to replace string Tony Esposito wrote: perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\test.txt Trying to replace a string with this one line perl ... in Windows it does not seem to work ... File test.txt contents is ... CONSTANT 100 CONSTANT 200 nothing changes ... acts as if it does not 'see' the CONSTANT string. Help because it looks like it should work !!! Windows does not work with single quotes: I ran under windows with what Tony sent, both the cmd and a korn shell and both worked and updated as expected.. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us perl -p -i.bak -e s/CONSTANT/VARIABLE/ C:\test.txt -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: one liner in Windows to replace string
-Original Message- From: Shawn H. Corey [mailto:shawnhco...@gmail.com] Sent: Monday, August 24, 2009 11:57 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: Tony Esposito; Beginners Perl Subject: Re: one liner in Windows to replace string Wagner, David --- Senior Programmer Analyst --- CFS wrote: I ran under windows with what Tony sent, both the cmd and a korn shell and both worked and updated as expected.. If you have any questions and/or problems, please let me know. Thanks. What version of Windows? The last time I used Windows was XP and it Windows XP with SP2. As stated, I run an old Korn shell from MKS and it worked there. But I also tried the cmd32.exe and it also worked there. So unsure why it is, but it does. Makes the copy, etc.. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us would see single quotes as: perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\test.txt which, of course, don't work. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: script to compare dates
-Original Message- From: Mihir Kamdar [mailto:kamdarmihi...@gmail.com] Sent: Tuesday, August 18, 2009 08:55 To: Steve Bertrand Cc: beginners Subject: Re: script to compare dates I dont have Datetime module installed. Is there a way without using DateTime?? You don't need it. You can with a little work generate what you need. I don't have access to an open setup, so here is a shot at using what you already have in a normal load. You will need to modify and possibly add some checks, but all doable using std libs: #!/usr/bin/perl use strict; use warnings; use Time::Local 'timelocal'; my %MonthNameToNbr = qw( JAN 0 FEB 1 MAR 2 APR 3 MAY 4 JUN 5 JUL 6 AUG 7 SEP 8 OCT 9 NOV 10 DEC 11); my $checkdateinsecs = timelocal(0, 0, 0, 31, $MonthNameToNbr{q[mar]}, 109); # generate check date once printf checkdateinsecs: %d\n, $checkdateinsecs; my $day; my $month; my $year; my @cdr = (); while ( DATA ) { chomp; next if ( /^\s*$/ ); @cdr = split(/\s*,\s*/, $_); if ( $cdr[0] !~ /^.(\d+)\S(\S{3})\S(\d+)/ ) { #print some type of error and either continue or die printf (%5d)in error:\n%s\n, $., $_; next; } $day = $1; $month = uc($2); $year = $3; my $dateinsecs = timelocal(0, 0, 0, $day, $MonthNameToNbr{$month}, $year+100); next if ( ! ( ($dateinsecs $checkdateinsecs ) and $cdr[1] =~ /2.*/ ) ); # do your other processing printf dateinsecs: %d was greater (%d)\n, $dateinsecs, $.; } __DATA__ *04-NOV-08*,2 *04-apr-09*,3 *xx-dec-08*,2 *04-apr-09*,2 Output: [C:/CurrWrka/00Commonprlprod/src] aapl013s checkdateinsecs: 1233385200 (3)in error: *xx-dec-08*,2 dateinsecs: 1238824800 was greater (4) On Tue, Aug 18, 2009 at 7:37 AM, Steve Bertrand st...@ibctech.ca wrote: Mihir Kamdar wrote: Hi, I want to write a script whose input data would be a csv file and records would be as follows:- 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08* ,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09* ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08* ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0 Here I want to compare whether the 5th field, which is the date field is *earlier than 31-Mar-09 and 2nd field value is 2.* If yes, then I will take that record and store it in another file. Please help me as to how do I compare dates, preferably with some sample code. I started coding for this as below, but am stuck on how to compare date in my input with another date. #!/usr/bin/perl use strict; use warnings ; open (my $IN_FILE,,testdata.txt) or die $!. file not found ; while (my $line=readline($IN_FILE)) { my @cdr=split (/,/, $line) ; if($cdr[5] . . } For fun, and to try out a few things I came across in Damian's book. I use DateTime to manage all aspects of dates and times. The code below assumes that all records will always be in the exact same format. Criticism welcome: #!/usr/bin/perl use strict; use warnings; use DateTime::Format::Strptime; my $EXTRACTION_LAYOUT = '@16 A1 @40 A9'; VOUCHER_RECORD: while ( my $record = DATA ) { my ( $important_num, $date_string ) = unpack $EXTRACTION_LAYOUT, $record; next VOUCHER_RECORD if $important_num != 2; my $static_date = DateTime-new( year = 2009, month = 3, day = 31 ); # turn the extracted date string into a DateTime object my $date_formatter = new DateTime::Format::Strptime( pattern = '%d-%b-%y' ); my $voucher_date = $date_formatter-parse_datetime($date_string); # compare the DateTime compiled dates if ( DateTime-compare( $static_date, $voucher_date )) { print Voucher ${voucher_date} is prior to ${static_date} . and the important number is 2\n; } } __DATA__ 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*,1,INR,, VOUCHER_BATCH_20080919_00014,2C,,0 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*,10,INR, ,VOUCHER_BATCH_20080919_00024,1K,,0 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*,10,INR, ,VOUCHER_BATCH_20080919_00024,1K,,0 Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Automating the resetting of Power Options
-Original Message- From: Kevin Safford [mailto:saffo...@uk.ibm.com] Sent: Monday, August 03, 2009 04:37 To: beginners@perl.org Subject: Re: Automating the resetting of Power Options Wagner, David --- Senior Programmer Analyst --- CFS wrote: So does anyone have a Perl script/module that will allow me to reset the Power options automatically? I would perfer to be abel to set what I want it to be, so it can be done automatically without my intervention ( I can handle finding an existing script that can call the Perl, but I have no idea where to start ). I don't know how you'd do it in Perl. Have you tried C:\WINDOWS\system32\powercfg.exe in a batch file? I did not from a batch program, but executed it manually and it shows a dialog box which is not really what I am after. I want to be able to set and forget about it, knowing that if I do a restart, it will handle getting ti set to what I need. I appreciate the response.. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us -- Kevin Safford -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Automating the resetting of Power Options
Whenever I have to reboot ( Windows XP Sp2 ), which I try to keep to a minimum, it resets the power options. I have no control of that, but I can also go in a set to what I want it to be. Unfortunately I get side tracked at times after a re-boot and next thing I am at home and when I try to remote connect to my desktop, I cannot. So does anyone have a Perl script/module that will allow me to reset the Power options automatically? I would perfer to be abel to set what I want it to be, so it can be done automatically without my intervention ( I can handle finding an existing script that can call the Perl, but I have no idea where to start ). Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Having problems getting data back to STDOUT once I assign it to a file
-Original Message- From: Patrick K Christopher TANAGER [mailto:pchristop...@tanagerinc.com] Sent: Tuesday, July 21, 2009 11:04 To: Wagner, David --- Senior Programmer Analyst --- CFS; Tony Esposito; beginners@perl.org Subject: RE: Having problems getting data back to STDOUT once I assign it to a file This is how I got it to work. However any STDOUT completion messages will need to be done outside the brace. } local *STDOUT; Ok, that seems do it. I have for the most part never used or needed the *x notation, so though I have been using Perl for years, not sure of all that it implies. So here is what I did: if ( $GlblInfo{audit} ) { print All STDOUT/STDERR will be assigned to this scripts audittrail log!!\nx3; open(OLD_STDERR,STDERR) or die Failed to save STDERR; #pulled this from the internet } If I do not do this before the print, then I get print on a closed filehandle. local *STDOUT; Then I placed the code to capture the STDOUT/ERR to a file. This worked as expected and placed all that was being displayed to the screen to disk. I then had the following: if ( $GlblInfo{audit} ) { print \n\n*Should be last line in the audittrail file...*\n\n; open(STDERR,OLD_STDERR) or die Failed to restore STDERR; select(STDERR); open(STDOUT , '-') || die Unable to open STDOUT: $!; select(STDOUT); if ( $GlblInfo{continues} ) { print \n\n . *EndOfProg*x7 . \n\n; }else { print \n\n . **Error*x9 . \n\n; } } Now everything seems to be working as I would have expected. I added an error to the open on STDOUT and it threw up the error to STDERR. As to the printf verses print, sorry, but I am the only one doing the work here using Perl. There may be overhead and I will try to change the thought processes. I do appreciate the list and it's help.. Thanks again. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us if ( $GlblInfo{audit} ) { printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; open(STDOUT, q[] . $GlblInfo{audittrail}) || dies(0, $GlblInfo{audittrail}, $!); select(STDOUT); $| = 1; open(STDERR, q[] . $GlblInfo{audittrail}) || dies(1, $GlblInfo{audittrail}, $!); select(STDERR); $| = 1; } } The sub dies is my own little setup. It does take all the output destined for STDOUT and STDERR and places into a file. I have reviewed the output in the file and it is what I expect. I am running under Xp SP2 using AS 5.8.9 Build 825 ( Dec 2008 ). Running under a Korn shell, but have tried with the std command shell with all the same results. I do not go into a loop, but I would never have thought I would spend so much time for something so minor. At this point, I have tried everything but the tee (tee is not accomplishing what I wanted: off the screen and into a file) and always with the same results: no more output to STDOUT or STDERR. Everything that I read using perldoc and perliotut says to do this and this and you will have STDIN or STDOUT. Use '-' for STDIN and '-' for STDOUT, but for whatever reason or the way I am doing it, I never see anything printed out.. At this point, I will leave it alone for a while and see if anything else floats to the top. I appreciate all the responses, but never thought it would be this complicated to just get back to a STDOUT or STDERR. It is Perl.. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us use File::Tee qw(tee); # simple usage: tee(STDOUT, '', 'stdout.txt'); Tony From: John W. Krahn jwkr...@shaw.ca To: Sent: Tuesday, 21 July, 2009 8:41:25 Subject: Re: Having problems getting data back to STDOUT once I assign it to a file Shawn H. Corey wrote: John W. Krahn wrote: Shawn H. Corey wrote: Wagner, David --- Senior Programmer Analyst --- CFS wrote: I am done processing and I want to place the final output line also on the screen. Here is what I have: if ( $GlblInfo{audit} ) { printf \n\n*Should be last line in the audittrail file...*\n\n; close(STDOUT); close(STDERR); open(STDOUT , '') || die Unable to open STDOUT: $!; You're not opening STDOUT to anything
RE: Reading a list of numbers into an array
-Original Message- From: Emanuele Osimo [mailto:e.os...@gmail.com] Sent: Wednesday, July 22, 2009 15:47 To: beginners perl ml Subject: Reading a list of numbers into an array Hello there, I'd like to read a file thet is a list of numbers like: 3084 4855 2904 making each line (each number) one of the elements of the array. I've tried foreach my $line (FILEHANDLE){ push (@array, $line) } but then printing the array just gives me the last number, in this case 2904. What's wrong? Here is a simple script based on what you gave here and it works: #!/usr/bin/perl use strict; use warnings; my @array = (); foreach (DATA){ chomp; push (@array, $_); } foreach ( @array ) { print $_ . \n; } __DATA__ 3084 4855 2904 Output: 3084 4855 2904 Thanks Emanuele -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Having problems getting data back to STDOUT once I assign it to a file
I am done processing and I want to place the final output line also on the screen. Here is what I have: if ( $GlblInfo{audit} ) { printf \n\n*Should be last line in the audittrail file...*\n\n; close(STDOUT); close(STDERR); open(STDOUT , '') || die Unable to open STDOUT: $!; if ( $GlblInfo{continues} ) { printf \n\n*EndOfProg*x7 . \n\n; }else { printf \n\n**Error*x9 . \n\n; } } I have looked at perldoc -f open and tried a number of things. The line should be last line is appearing in my audittrail file, but I never see the EndOfProg or Error in the auditrrail or on the screen. I am running with AS 5.8.9 build 825 on XP SP2. I have tried a number of different things after reading different docs, but I must be missing some very simple thing. Any ideas would be greatly appreciated. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Having problems getting data back to STDOUT once I assign it to a file
-Original Message- From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Tuesday, July 21, 2009 08:08 To: beginners@perl.org Subject: Fw: Having problems getting data back to STDOUT once I assign it to a file Back to the question at hand - have you tried using 'tee' No. I just wanted to place back on the screen what the final processing would tell me(success or failure). At the beginning, I was creating an audittrail for the processing via the following: if ( $GlblInfo{audit} ) { printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; printf All STDOUT/STDERR will be assigned to this scripts audittrail log!!\n; open(STDOUT, q[] . $GlblInfo{audittrail}) || dies(0, $GlblInfo{audittrail}, $!); select(STDOUT); $| = 1; open(STDERR, q[] . $GlblInfo{audittrail}) || dies(1, $GlblInfo{audittrail}, $!); select(STDERR); $| = 1; } The sub dies is my own little setup. It does take all the output destined for STDOUT and STDERR and places into a file. I have reviewed the output in the file and it is what I expect. I am running under Xp SP2 using AS 5.8.9 Build 825 ( Dec 2008 ). Running under a Korn shell, but have tried with the std command shell with all the same results. I do not go into a loop, but I would never have thought I would spend so much time for something so minor. At this point, I have tried everything but the tee (tee is not accomplishing what I wanted: off the screen and into a file) and always with the same results: no more output to STDOUT or STDERR. Everything that I read using perldoc and perliotut says to do this and this and you will have STDIN or STDOUT. Use '-' for STDIN and '-' for STDOUT, but for whatever reason or the way I am doing it, I never see anything printed out.. At this point, I will leave it alone for a while and see if anything else floats to the top. I appreciate all the responses, but never thought it would be this complicated to just get back to a STDOUT or STDERR. It is Perl.. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us use File::Tee qw(tee); # simple usage: tee(STDOUT, '', 'stdout.txt'); Tony From: John W. Krahn jwkr...@shaw.ca To: Sent: Tuesday, 21 July, 2009 8:41:25 Subject: Re: Having problems getting data back to STDOUT once I assign it to a file Shawn H. Corey wrote: John W. Krahn wrote: Shawn H. Corey wrote: Wagner, David --- Senior Programmer Analyst --- CFS wrote: I am done processing and I want to place the final output line also on the screen. Here is what I have: if ( $GlblInfo{audit} ) { printf \n\n*Should be last line in the audittrail file...*\n\n; close(STDOUT); close(STDERR); open(STDOUT , '') || die Unable to open STDOUT: $!; You're not opening STDOUT to anything. And you closed STDERR so the die message can't go anywhere. In fact, it goes into an infinite loop. No it doesn't, there is no loop there. It goes into an infinite loop on my machine. I suggest you try it before you make such blanket statements. I did and it doesn't on my machine. Perhaps your OS or C library is doing something stupid? It makes no sense for IO on an unopened filehandle to loop. 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/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: While issues
-Original Message- From: Patrick K Christopher TANAGER [mailto:pchristop...@tanagerinc.com] Sent: Thursday, July 16, 2009 11:39 To: beginners@perl.org Subject: While issues I can't seem to find this oddness in this script. #! /usr/bin/perl You should use strict and warnings as part of the processing and you might have a better idea. Also you should really have the code that is failing and not just making the assumption that the code is the same as the first. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight Systems 1.719.484.2097 Tel 1.719.484.2419 Fax 1.408.623.5963 Cell http://fedex.com/us open(FH,$ARGV[0]) || die (File failed to open!\n); open(FO,$ARGV[1]) || die (Output failed to open!\n); while (FH){ s/,//g print (FO); } close (FH); close (FO); open(FH1,$ARGV[2]). The problem is the first while iterates properly but then the script just exits. Any ideas ? Thanks, Keith This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this email. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late, or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version. Tanager, INC 3140 West Ward Road Suite 205 Dunkirk, MD 20754 www.tanagerinc.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: word substitute with character count.
-Original Message- From: Nisse Tuta [mailto:nisset...@gmail.com] Sent: Thursday, June 18, 2009 15:12 To: beginners@perl.org Subject: word substitute with character count. Hi all, I'm having a problem solving this one. I need to replace/substitute a word in a text file. The problem is that i need to keep the same amount of characters as the replaced word. This is for replacing words in a template/postscript file that I use for printing labels. After upgrading the OS and CUPS printer driver, things don't work the same. i.e In the template text file there is a pattern #--# (20 characters). if I do s/#--#/not ok/ it will come out wrong. If I would substitute with a variable and add spaces for remaining character not used. i.e s/#--#/'not ok '/ it works. I'm hoping that someone could show me how to solve this one. If you are doing multiple pattern changes, then should be able to tie to a hash or array to have the pattern, length, etc for what you want to do. It can be done, I am sure other will have a btter process, but it does do what you want. #!/usr/bin/perl use strict; use warnings; $_ = q[#-#]; my $MyPat = q[#-#]; my $MyHoldData = $_; my $MyLen = length($MyPat); my $MyChg = q[abc]; my $MyChgLen = length($MyChg); s/$MyPat/${MyChg} .q[ ]x($MyLen-$MyChgLen)/ie; printf %sOrig\n%sChg\n, $MyHoldData, $_; Output: #-#Orig abcChg If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us Thanks for your time. Nisse -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Please, I need help!!!
-Original Message- From: Phillip [mailto:fibbe...@gmx.net] Sent: Thursday, June 11, 2009 12:00 To: beginners@perl.org Subject: Please, I need help!!! Hallo @ all, i am new in this domain(perlscript) and i have a question.i have a array,i sort it,i get the last element of the array but i want to get the next element after this one.how can i do this? for example: $arr1=(6,3,8,1) ---my last element is 1 and mark that is the last element now i sort them $arr1=(1,3,6,8) my last element is 1 and now i want to go to the next element in the list,how can i do this?mbered The reason is unless you change how arrays are numbered, they start at zero and go from there. You can also use -1 to get the last element of an array as in $arr1[-1] would be 1 in the first example. $arr1[0] = 6 from your first example. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us if i do something like this:$next=$last+1; ---in this case $next will be 2 and this is not my third element in my list,i want the 3. BR, Phil here is my code: @arr[1]=(3,7,13,1,19,5,9); @array=split(/,/,@arr[1]); $i=0; while(@array[$i]) { $i=$i+1; } printAnzahl:$i\n; @sorty=sort(Nummernsort @array); sub Nummernsort{ if($a$b){ return -1; }elsif($a==$b){ return 0; }else{ return 1; } } print sort:@sorty\n; $last=$array[$i-1]; print last:$last\n; $next=? printnextt=$next\n; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: split() does not work with all characters
-Original Message- From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Tuesday, June 02, 2009 15:29 To: Beginners Perl Subject: split() does not work with all characters When trying to use split() where the delimiter is passed from the command-line ( as seen in stub code that follows ), the code fails to parse/split input file via some characters (e.g. | ) but it runs ok for others (e.g. , ). The | has special significance when used in regex, so if you are just after whatever characters are inputted, then you will need to set the regex so it won't interpret as a regex value, so you could do: @cfgData = split(/\Q$opt{d}\E/); where \Q Backslash all following nonalphanumeric characters and \E ends the \Q Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us Any idea what could be causing this? Code: use vars qw/ %opt /; use Getopt::Std; my $optString = 'd:'; getopts( $optString, \%opt ); while(FILE) { @cfgData = split(/$opt{d}/); ... } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: skipping a repeated header
-Original Message- From: Kirk Wythers [mailto:kwyth...@umn.edu] Sent: Wednesday, May 27, 2009 09:31 To: beginners@perl.org Subject: skipping a repeated header I have a large datafile that I am trying to read into a postgresql database. I think I have the db_connect stuff down, but I'm fighting with the part that reads the file to be processed. The file contains a repeating structure of header lines like this: TOA5 B4WARM_CCR1000 16474 CR1000.Std.15 TIMESTAMP RECORD Flag(1) Flag(2) Flag(3) TSRN Smp Smp Smp 4/29/09 15:10 0 0 0 0 4/29/09 15:11 1 0 0 0 4/29/09 15:12 2 0 0 0 4/29/09 15:13 3 0 0 0 4/29/09 15:14 4 0 0 0 4/29/09 15:15 5 0 0 0 4/29/09 15:16 6 0 0 0 4/29/09 15:17 7 0 0 0 4/29/09 15:18 8 -1 -1 -1 4/29/09 15:19 9 -1 -1 -1 4/29/09 15:20 10 -1 -1 -1 TOA5 B4WARM_CCR1000 16474 CR1000.Std.15 TIMESTAMP RECORD Flag(1) Flag(2) Flag(3) TSRN Smp Smp Smp 4/29/09 15:10 0 0 0 0 4/29/09 15:11 1 0 0 0 4/29/09 15:12 2 0 0 0 4/29/09 15:13 3 0 0 0 4/29/09 15:14 4 0 0 0 4/29/09 15:15 5 0 0 0 4/29/09 15:16 6 0 0 0 4/29/09 15:17 7 0 0 0 4/29/09 15:18 8 -1 -1 -1 4/29/09 15:19 9 -1 -1 -1 4/29/09 15:20 10 -1 -1 -1 I want to read in the lines that begin with the date format, but skip all the header stuff. Can anyone suggest a strategy for a, if the next if ( ! /^\d/ ); If you only care about the date, then unless your lines have a number in the front, then the above will bypass those headers. If the head can have a number then something like: next if ( ! m!^\d+/\! ); Also the group is more willing if you can show code you have attempted. This is a very simplestic regex test which you should have gotten from any doc on Perl regex processing. Just a fyi for the future. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us line begins with , go ahead and read. Thanks in advance. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: skipping a repeated header
-Original Message- From: Kirk Wythers [mailto:kwyth...@umn.edu] Sent: Wednesday, May 27, 2009 10:16 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: beginners@perl.org Subject: Re: skipping a repeated header Thanks David. I didn't include my attempts because the postgresql stuff took up so many lines. I have snippet out the data read part (including your suggestion) and pated below. As you can see I also, sent a number of variables in the file. Again I was trying to not fill the list with too much text. The error I am getting is: Search pattern not terminated at ./untitled.pl line 7. #!/usr/bin/perl -w use strict; while ( ) { #Part 1. Skip header lines next if ( ! m!^\d+/\! ); I missed the last portion and should be: next if ( ! m!^\d+/\d! ); Whne you have \ within a regex then that implies take the next character as is unless it has special meaning like \d implies a number or \D is not a number. I apologize as I wrote a quick script, but when I copied or type over I left out the d in what I sent to you If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us #Part 2. Loop through the records and prepare SQL statement. my ( $TIMESTAMP, $RECORD, $Flag1, $Flag2, $Flag3, $Flag4, $Flag5, $Flag6, $Flag7, $year, $doy, $hour, $minute, $Batt_volt, $PTemp, $AM25TREF1, $AIRTEMP_Avg, $SCTemp_Avg1, $SCTemp_Avg2, $SCTemp_Avg3, $SCTemp_Avg4, $SCTemp_Avg5, $SCTemp_Avg6, $SCTemp_Avg7, $SCTemp_Avg8, $SCTemp_Avg9, $SCTemp_Avg10, $SCTemp_Avg11, $SCTemp_Avg12, $SCTemp_Avg13, $SCTemp_Avg14, $SCTemp_Avg15, $SCTemp_Avg16, $SCTemp_Avg17, $STemp_Avg1, $STemp_Avg2, $STemp_Avg3, $STemp_Avg4, $STemp_Avg5, $STemp_Avg6, $STemp_Avg7, $STemp_Avg8, $STemp_Avg9, $STemp_Avg10, $STemp_Avg11, $STemp_Avg12, $STemp_Avg13, $STemp_Avg14, $STemp_Avg15, $STemp_Avg16, $TsoilH1_Avg1, $TsoilH1_Avg2, $TsoilH2_Avg1, $TsoilH2_Avg2, $TsoilAc_Avg1, $TsoilAc_Avg2, $TsoilDs_Avg1, $TsoilDs_Avg2, $S_All_AvgT_Avg, $S_dif_Avg1, $S_dif_Avg2, $S_dif_Avg3, $S_dif_Avg4, $S_dif_Avg5, $S_dif_Avg6, $SAVG_dif_Avg1, $SAVG_dif_Avg2, $SBtemp_Avg1, $SBtemp_Avg2, $SBtemp_Avg3, $SBtemp_Avg4, $SBtemp_Avg5, $SBtemp_Avg6, $SBtemp_Avg7, $SBtemp_Avg8, $TmV_Avg1, $TmV_Avg2, $TmV_Avg3, $TmV_Avg4, $TmV_Avg5, $TmV_Avg6, $TmV_Avg7, $TmV_Avg8, $TargetTemp_Avg1, $TargetTemp_Avg2, $TargetTemp_Avg3, $TargetTemp_Avg4, $TargetTemp_Avg5, $TargetTemp_Avg6, $TargetTemp_Avg7, $TargetTemp_Avg8, $A_TargetTemp_Avg1, $A_TargetTemp_Avg2, $A_TargetTemp_Avg3, $A_TargetTemp_Avg4, $A_TargetTemp_Avg5, $A_TargetTemp_Avg6, $A_TargetTemp_Avg7, $A_TargetTemp_Avg8, $TargetTemp_ADJ_Avg1, $TargetTemp_ADJ_Avg2, $TargetTemp_ADJ_Avg3, $TargetTemp_ADJ_Avg4, $Temp_H1_Avg1, $Temp_H1_Avg2, $Temp_H2_Avg1, $Temp_H2_Avg2, $Temp_Ac_Avg1, $Temp_Ac_Avg2, $Temp_Ds_Avg1, $Temp_Ds_Avg2, $A_Dif_H1_Avg1, $A_Dif_H1_Avg2, $A_Dif_H2_Avg1, $A_Dif_H2_Avg2, $AAVG_Dif_Avg1, $AAVG_Dif_Avg2, $All_AvgT_Avg, $PID_out_Avg1, $PID_out_Avg2, $PID_out_Avg3, $PID_out_Avg4, $PID_lmt_Avg1, $PID_lmt_Avg2, $PID_lmt_Avg3, $PID_lmt_Avg4, $ScldOut_Avg1, $ScldOut_Avg2, $ScldOut_Avg3, $ScldOut_Avg4, $SDM_Out_Avg1, $SDM_Out_Avg2, $SDM_Out_Avg3, $SDM_Out_Avg4, $E_ScldOut_Avg1, $E_ScldOut_Avg2, $RXResponse, $ES_ScldOut_Avg1, $ES_ScldOut_Avg2, $S_RXResponse, $Wind_RXResponse, $I_WS_MS ) = split; print join( \t, $TIMESTAMP, $RECORD, $Flag1, $Flag2, $Flag3, $Flag4, $Flag5, $Flag6, $Flag7, $year, $doy, $hour, $minute, $Batt_volt, $PTemp, $AM25TREF1, $AIRTEMP_Avg, $SCTemp_Avg1, $SCTemp_Avg2, $SCTemp_Avg3, $SCTemp_Avg4, $SCTemp_Avg5, $SCTemp_Avg6, $SCTemp_Avg7, $SCTemp_Avg8, $SCTemp_Avg9, $SCTemp_Avg10, $SCTemp_Avg11, $SCTemp_Avg12, $SCTemp_Avg13, $SCTemp_Avg14, $SCTemp_Avg15, $SCTemp_Avg16, $SCTemp_Avg17, $STemp_Avg1, $STemp_Avg2, $STemp_Avg3, $STemp_Avg4, $STemp_Avg5, $STemp_Avg6, $STemp_Avg7, $STemp_Avg8, $STemp_Avg9, $STemp_Avg10, $STemp_Avg11, $STemp_Avg12, $STemp_Avg13, $STemp_Avg14, $STemp_Avg15, $STemp_Avg16, $TsoilH1_Avg1, $TsoilH1_Avg2, $TsoilH2_Avg1, $TsoilH2_Avg2, $TsoilAc_Avg1, $TsoilAc_Avg2, $TsoilDs_Avg1, $TsoilDs_Avg2, $S_All_AvgT_Avg, $S_dif_Avg1, $S_dif_Avg2, $S_dif_Avg3, $S_dif_Avg4, $S_dif_Avg5, $S_dif_Avg6, $SAVG_dif_Avg1, $SAVG_dif_Avg2, $SBtemp_Avg1, $SBtemp_Avg2, $SBtemp_Avg3, $SBtemp_Avg4, $SBtemp_Avg5, $SBtemp_Avg6, $SBtemp_Avg7, $SBtemp_Avg8, $TmV_Avg1, $TmV_Avg2, $TmV_Avg3, $TmV_Avg4, $TmV_Avg5
RE: deleting subdirectories only in Win32
-Original Message- From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] Sent: Thursday, May 14, 2009 12:02 To: beginners@perl.org Subject: Fw: deleting subdirectories only in Win32 It appears that, after doing more research, the keep_root variable does not keep the \data folder intact but removes it. Unless I am mistaken, is there another method to cleaning a directory of files and subdirectories without removing the directory itself? (I know I can do it programmatically but I was wondering if there was a '1-liner' like the one previously listed). but that is not what the doc states: keep_root = $bool When set to a true value, will cause all files and subdirectories to be removed, except the initially specified directories. This comes in handy when cleaning out an application's scratch directory. So I would at least get ahold of the maintainer: AUTHORS Tim Bunce and Charles Bailey. Currently maintained by David Landgren da...@landgren.net. What it is advertising and doing are not right. My 2 cents... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us - Forwarded Message From: Tony Esposito tony1234567...@yahoo.co.uk To: Beginners Perl beginners@perl.org Sent: Wednesday, 13 May, 2009 12:56:45 Subject: 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}); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Re: Perl code for comparing two files
-Original Message- From: news [mailto:n...@ger.gmane.org] On Behalf Of Richard Loveland Sent: Friday, May 08, 2009 11:59 To: beginners@perl.org Subject: Re: Perl code for comparing two files -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mr. Adhikary, The following will take any number of files as arguments, in the format you described (I even tested it! :-)). It goes through each line of those files, stuffing (the relevant part of) each line in a 'seen' hash (more on that, and other, hash techniques here if you're interested: http://www.perl.com/pub/a/2006/11/02/all-about-hashes.html). The code below does not keep track of line numbers as you requested, but I think the hash technique used here could help you as you approach a solution to your particular problem. #!/usr/bin/perl use strict; use warnings; use File::Slurp; # This is where 'read_file' lives my %seen; for my $arg ( @ARGV ) { my @lines = read_file( $arg ); for my $line ( @lines ) { chomp $line; my @elems = split / /, $line; my $value = $elems[1]; $seen{$value}++; } } for my $k ( keys %seen ) { print $k, \n if $seen{$k} 1; } This is similar to above, but no File::Slurp and uses an hash combined with an array with [0] being the count of seen items, [ zero] is line number and index is the file it was from. I have given you a Data::Dumper. I ran with the fieles you provided. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %seen; my $MyLineNbr = 1; my %MFN = (); my $MyFilenames = \%MFN; my $MyFileCnt = 1; my $MyCurrFile = q[]; while ( ) { if ( $ARGV ne $MyCurrFile ) { printf Filename: %s (%d)\n, $ARGV, $MyFileCnt; $MyCurrFile = $ARGV; $MyFilenames-{$MyCurrFile} = $MyFileCnt++; $MyLineNbr = 0; } chomp; $MyLineNbr++; next if ( /^\s*$/ ); my @elems = split (/ /, $_); my $value = $elems[1]; $seen{$value}[0]++; $seen{$value}[$MyFilenames-{$MyCurrFile}] = $MyLineNbr; } print Dumper(\%seen); Regards, Rich Loveland Anirban Adhikary wrote: Hi List I am writing a perl code which will takes 2 more files as argument. Then It will check the the values of each line of a file with respect with another file. If some value matches then it will write the value along with line number to another ( say outputfile) file. The source files are as follow Contents of abc.txt 1 2325278241,P0 2 2296250723,MH 3 2296250724,MH 4 2325277178,P0 5 7067023316,WL 6 7067023329,WL 7 2296250759,MH 8 7067023453,WL 9 7067023455,WL 10 555413,EA05 ### Contents of xyz.txt 1 7067023453,WL 2 31-DEC-27,2O,7038590671 3 31-DEC-27,2O,7038596464 4 31-DEC-27,2O,7038596482 5 2296250724,MH 6 31-DEC-27,2O,7038597632 7 31-DEC-27,2O,7038589511 8 31-DEC-11,2O,7038590671 9 7067023455,WL 10 31-DEC-27,2O,7038555744 ### Contents of pqr.txt 1 2325278241,P0 2 7067023316,WL 3 7067023455,WL 4 2296250724,MH For this requirement I have written the following code which works fine for 2 input files use strict; use warnings; use Benchmark; if(@ARGV 2) { print Please enter atleast two or more .orig file names \n; exit 0; } my @file_names = @ARGV; chomp(@file_names); my @files_to_process; for(@file_names) { if( -s $_){ print File $_ exists\n; push(@files_to_process,$_); } elsif( -e $_) { print File $_ exists but it has zero byte size\n; } else { print File $_ does not exists \n; } } my $count = @files_to_process; if( $count 2 ) { print Atleast 2 .orig files are required to continue this program\n; exit 0; } my $output_file = outputfile; my $value = 0; my $start_time = new Benchmark; if( $count = 2 ) { while ($count) { my ($files_after_processing_pointer,$return_val) = create_itermediate_file (\...@files_to_process,$value); my @files_after_processing = @$files_after_processing_pointer; $count = @files_after_processing; $value = $return_val; @files_to_process = @files_after_processing; } my $end_time = new Benchmark; my $difference = timediff($end_time, $start_time); print It took , timestr($difference), to execute the program\n; } sub create_itermediate_file { my $file_pointer = $_[0]; my $counter = $_[1]; my @file_content = @$file_pointer;
RE: Perl code for comparing two files
-Original Message- From: Anirban Adhikary [mailto:anirban.adhik...@gmail.com] Sent: Monday, May 04, 2009 06:40 To: beginners@perl.org Subject: Perl code for comparing two files Hi List I am writing a perl code which will takes 2 more files as argument. Then It will check the the values of each line of a file with respect with another file. If some value matches then it will write the value along with line number to another ( say outputfile) file. The source files are as follow Contents of abc.txt 1 2325278241,P0 2 2296250723,MH 3 2296250724,MH 4 2325277178,P0 5 7067023316,WL 6 7067023329,WL 7 2296250759,MH 8 7067023453,WL 9 7067023455,WL 10 555413,EA05 ### Contents of xyz.txt 1 7067023453,WL 2 31-DEC-27,2O,7038590671 3 31-DEC-27,2O,7038596464 4 31-DEC-27,2O,7038596482 5 2296250724,MH 6 31-DEC-27,2O,7038597632 7 31-DEC-27,2O,7038589511 8 31-DEC-11,2O,7038590671 9 7067023455,WL 10 31-DEC-27,2O,7038555744 ### Contents of pqr.txt 1 2325278241,P0 2 7067023316,WL 3 7067023455,WL 4 2296250724,MH Here is a way where a 'seen' hash has two array elements: [0] - count, [1]: file number and line number for each seen item. Code starts on next line: use strict; use warnings; use Data::Dumper; my %seen; my $MyLineNbr = 1; my %MFN = (); my $MyFilenames = \%MFN; my $MyFileCnt = 1; my $MyCurrFile = q[]; my $MyActIdx = 1; while ( ) { if ( $ARGV ne $MyCurrFile ) { printf Filename: %s\n, $ARGV; $MyCurrFile = $ARGV; $MyFilenames-{$MyCurrFile} = $MyFileCnt++; $MyLineNbr = 0; } chomp; $MyLineNbr++; next if ( /^\s*$/ ); my @elems = split (/ /, $_); my $value = $elems[1]; $seen{$value}[0]++; $seen{$value}[$MyActIdx] .= $MyFilenames-{$MyCurrFile} . q[;] . $MyLineNbr. q[^]; } print Dumper(\%seen); ^--- code ends here I leave to you to get the output, but this should give you what need to work with. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us For this requirement I have written the following code which works fine for 2 input files use strict; use warnings; use Benchmark; if(@ARGV 2) { print Please enter atleast two or more .orig file names \n; exit 0; } my @file_names = @ARGV; chomp(@file_names); my @files_to_process; for(@file_names) { if( -s $_){ print File $_ exists\n; push(@files_to_process,$_); } elsif( -e $_) { print File $_ exists but it has zero byte size\n; } else { print File $_ does not exists \n; } } my $count = @files_to_process; if( $count 2 ) { print Atleast 2 .orig files are required to continue this program\n; exit 0; } my $output_file = outputfile; my $value = 0; my $start_time = new Benchmark; if( $count = 2 ) { while ($count) { my ($files_after_processing_pointer,$return_val) = create_itermediate_file (\...@files_to_process,$value); my @files_after_processing = @$files_after_processing_pointer; $count = @files_after_processing; $value = $return_val; @files_to_process = @files_after_processing; } my $end_time = new Benchmark; my $difference = timediff($end_time, $start_time); print It took , timestr($difference), to execute the program\n; } sub create_itermediate_file { my $file_pointer = $_[0]; my $counter = $_[1]; my @file_content = @$file_pointer; if($counter == 0) { my($first_file,$second_file) = splice (@file_content, 0, 2); open my $orig_first, , $first_file or die could not open $first_file: $!; open my $orig_second, , $second_file or die could not open $second_file: $!; open my $output_fh, , $output_file or die could not open $output_file: $!; my %content_first; while (my $line = $orig_first) { chomp $line; if ($line) { my($line_num,$value) = split( ,$line); $content_first{$value} = $line_num;
How to Extract to a flat file thru Excel an Access DB file
I have an Excel file that I am copying from a Windows server to Linux box(initially). I then extract each worksheet to their own csv. Within the Excel is detail that is contained within a Access DB. I am getting the necessary worksheets out ok, but am unsure how or if one can extract to a csv, the detail data from Access DB. Any thoughts or how one would research to do this? I am on 5.8.8 ActiveState Build 824. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: String manipulation question
-Original Message- From: Grant [mailto:emailgr...@gmail.com] Sent: Tuesday, April 21, 2009 09:58 To: Perl Beginners List Subject: String manipulation question I'd like to take a string and manipulate it in a few ways. If the string is 34 characters or less, I'd like to append a colon character and save it to $var1. If the string is longer than 34 characters, I'd like to save up to 35 characters to $var1, but cut off at the last possible space character and not including that space character in the variable. I'd then like to save up to 26 characters of the cut off portion (not including the previously mentioned space character) to $var2, cut off at the last possible space character and not including that space character in the variable. $var2 should have an appended colon character. Is that a tall order? I'm hoping it's trivial for someone here. Thanks, Grant Here is a simple script that attempts to do what you ask. If you are new at Perl, then can seem overwhelming to say the least. But once you get into it, you start thinking differently. Jim G looks at indexing, etc while that never ended my sphere of things. I thought of spliting on white space and rebuilding the line along the way you wanted it back out. It is only a start and does not take into account if you have a very large word that could be say greater than 34 or 26 characters. Code follows: #!/usr/bin/perl use strict; use warnings; =head1 I'd like to take a string and manipulate it in a few ways. If the string is 34 characters or less, I'd like to append a colon character and save it to $var1. If the string is longer than 34 characters, I'd like to save up to 35 characters to $var1, but cut off at the last possible space character and not including that space character in the variable. I'd then like to save up to 26 characters of the cut off portion (not including the previously mentioned space character) to $var2, cut off at the last possible space character and not including that space character in the variable. $var2 should have an appended colon character. Is that a tall order? I'm hoping it's trivial for someone here. =cut my $var1 = q[]; my $var2 = q[]; my @MyWorkw = (); while ( 1 ) { print 1234567891123456789212345678931234^2345678911234567892123456\n; chomp($_ = STDIN); last if ( /^(ex|qu)/i ); ($var1, $var2) = ( q[], q[] ); if ( length($_) 35 ) { $var1 = $_ . q[:]; } else { @MyWorkw = split(/\s+/, $_); while ( 1 ) { if ( length($var1)+length($MyWorkw[0]) 35 ) { $var1 .= shift(@MyWorkw) . q[ ]; } else { $var1 =~ s/ $/:/; last } } while ( 1 ) { if ( length($var2)+length($MyWorkw[0]) 26 ) { $var2 .= shift(@MyWorkw) . q[ ]; } else { $var2 =~ s/ $/:/; last } } } printf Original Data:\n%s\n, $-; printf var1: %s\n 12345678911234567892123456789312345\nvar2: %s\n 12345678911234567892123456\n, $var1, $var2; } ^--- Code ends here If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: String manipulation question
-Original Message- From: Grant [mailto:emailgr...@gmail.com] Sent: Tuesday, April 21, 2009 11:47 To: Perl Beginners List Subject: Re: String manipulation question I'd like to take a string and manipulate it in a few ways. If the string is 34 characters or less, I'd like to append a colon character and save it to $var1. The length function will tell you how many characters are in a string. If the string is longer than 34 characters, I'd like to save up to 35 characters to $var1, but cut off at the last possible space character and not including that space character in the variable. I'd then like to save up to 26 characters of the cut off portion (not including the previously mentioned space character) to $var2, cut off at the last possible space character and not including that space character in the variable. $var2 should have an appended colon character. The substr function will return parts of a string, and may also be used to replace parts of a string. The concatenation operator (.) may be used to add characters to the end of the string. The index function will return the first position of a substring within a specified string, and -1 if the substring cannot be found. The rindex function returns the last position, so you can use it to find the last space in a string. Is that a tall order? I'm hoping it's trivial for someone here. It should be straight-forward to put these functions together to do what you want. Give it a try and come back here if you can't get it to work. See the following: perldoc -f length perldoc -f substr perldoc -f index perldoc -f rindex perldoc perlop (Search for 'Additive Operators') Thanks guys. With some help I've come up with this: $string = 'abc def ghi jkl mno pqr stu vwx yz'; if(length($string) = 34) {$var1 = $string.:;} change = to == ( this is the test for equality). Also add use strict and warnings to your Perl and you would have had a heads up to what is happening. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us if(length($string) 34) { $string =~ s/\s//g; ($var1, $var2) = $string =~ /(.){35}(.){26}/; $var2 .= :; } but I get: Safe: Can't modify length in scalar assignment I've got to leave Safe on. Can I modify this to work within it? - Grant -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: String manipulation question
-Original Message- From: Grant [mailto:emailgr...@gmail.com] Sent: Tuesday, April 21, 2009 12:16 To: Perl Beginners List Subject: Re: String manipulation question Thanks guys. With some help I've come up with this: $string = 'abc def ghi jkl mno pqr stu vwx yz'; if(length($string) = 34) {$var1 = $string.:;} '=' is assignment, '==' is test for numerical equality. Change the above line to: if( length($string) == 34 ) { $var1 = $string . ':' } if(length($string) 34) { $string =~ s/\s//g; The above line deletes all of the spaces in $string. Is that what you want to do? All fixed up except for this. How can I remove only the spaces at the end of $var1 and $var2 if they exist? - Grant ($var1, $var2) = $string =~ /(.){35}(.){26}/; This pulls 35 characters and splits words, yet what you asked for was the last word separated. Correct? Wags ;) You should put your repeat specifiers inside the capture parentheses: ($var1, $var2) = ($string =~ /(.{35})(.{26})/); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: String manipulation question
-Original Message- From: Grant [mailto:emailgr...@gmail.com] Sent: Tuesday, April 21, 2009 12:43 To: Perl Beginners List Subject: Re: String manipulation question Thanks guys. With some help I've come up with this: $string = 'abc def ghi jkl mno pqr stu vwx yz'; if(length($string) = 34) {$var1 = $string.:;} '=' is assignment, '==' is test for numerical equality. Change the above line to: if( length($string) == 34 ) { $var1 = $string . ':' } if(length($string) 34) { $string =~ s/\s//g; The above line deletes all of the spaces in $string. Is that what you want to do? All fixed up except for this. How can I remove only the spaces at the end of $var1 and $var2 if they exist? - Grant ($var1, $var2) = $string =~ /(.){35}(.){26}/; This pulls 35 characters and splits words, yet what you asked for was the last word separated. Correct? I'm trying to pull 35 or fewer characters to the nearest space basically. This is what I have now: if(length($string) = 34) {$var1 = $string.:;} if(length($string) 34) { ($var1, $var2) = ($string =~ /(.{35})(.{26})/); 1234567891124567892123456789312345 if you have in $string = q[1234 12345 12 5346 12367 123 123678123]; Then $var1 will be '1234 12345 12 5346 12367 123 12367', but I thought you wanted '1234 12345 12 5346 12367 123'? Which one is the right one for what you are doing? Wags ;) $var1 =~ s/\s+$//; $var2 =~ s/\s+$//; $var2 .= :; } Does that look OK? Is the 3rd line off? - Grant -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: String manipulation question
-Original Message- From: Grant [mailto:emailgr...@gmail.com] Sent: Tuesday, April 21, 2009 12:55 To: Perl Beginners List Subject: Re: String manipulation question Thanks guys. With some help I've come up with this: $string = 'abc def ghi jkl mno pqr stu vwx yz'; if(length($string) = 34) {$var1 = $string.:;} '=' is assignment, '==' is test for numerical equality. Change the above line to: if( length($string) == 34 ) { $var1 = $string . ':' } if(length($string) 34) { $string =~ s/\s//g; The above line deletes all of the spaces in $string. Is that what you want to do? All fixed up except for this. How can I remove only the spaces at the end of $var1 and $var2 if they exist? - Grant ($var1, $var2) = $string =~ /(.){35}(.){26}/; This pulls 35 characters and splits words, yet what you asked for was the last word separated. Correct? I'm trying to pull 35 or fewer characters to the nearest space basically. This is what I have now: if(length($string) = 34) {$var1 = $string.:;} if(length($string) 34) { ($var1, $var2) = ($string =~ /(.{35})(.{26})/); 1234567891124567892123456789312345 if you have in $string = q[1234 12345 12 5346 12367 123 123678123]; Then $var1 will be '1234 12345 12 5346 12367 123 12367', but I thought you wanted '1234 12345 12 5346 12367 123'? Which one is the right one for what you are doing? You're right, I would want: 1234 12345 12 5346 12367 123 Can you show me how to do that properly? I sent a reply which had a whole different tack to how you are doing the processing. With Perl, there is always a number of ways to accomplish the task. If and when you get the original email, it was a little program to test out what you were entering. Here is snippet of breaking that apart and re-joining # # if less than 35 characters, just add the colon # if ( length($string) 35 ) { $var1 = $string . q[:]; } else { @MyWorkw = split(/\s+/, $string); # # split the line by white space into an array # while ( 1 ) { if ( length($var1)+length($MyWorkw[0]) 35 ) { $var1 .= shift(@MyWorkw) . q[ ]; } else { $var1 =~ s/ $/:/; last } } while ( 1 ) { if ( length($var2)+length($MyWorkw[0]) 26 ) { $var2 .= shift(@MyWorkw) . q[ ]; } else { $var2 =~ s/ $/:/; last } } } If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us - Grant $var1 =~ s/\s+$//; $var2 =~ s/\s+$//; $var2 .= :; } Does that look OK? Is the 3rd line off? - Grant -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Generating emails for BlackBerry
I have a number of emails I do for upper management, but the majority of them travel and live off their BlackBerry. I am attempting to think out how to present the data to them so that it lines up ( or at least attempts to line up) for easier reading. I would still send the original email so readable from their Desktop or notebook, but for the upper management team, I would provide a BB version also. I do not want to re-invent the wheel unless I need to. Has anyone had to do something like this( module used, thought process in re-formatting, etc )? Any insight would be greatly appreciated.. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: help needed to get over endless loop
-Original Message- From: Brian [mailto:brian5432...@yahoo.co.uk] Sent: Friday, April 17, 2009 11:03 To: Perl Beginners Subject: help needed to get over endless loop Hi I had this semi-working, changed something and can't remember where I went right, so would appreciate some help getting back on top. I know 1..10 and 2..10 probably won't work in the following example, I have just changed lines to show what I am trying to get. You are not running with strict, warnings which would give you a heads up $mystart = -2; $i = 1; for ($i = 1..10 ) { while ($i = 1 ) { You would get warning if warnings were on. You are assigning 1 to $i and not $i == 1. Better to give your code for the list to review. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us if ($mystart 1 ) {print line 1 no data} if ($mystart 0 ) {print line 1 data} $mystart++ ; $i++; } } while ($i = 2..10 ) { if ($mystart 1 ) {print line 2..10 no data} if ($mystart 0 ) {print line 2..10 with data} $mystart++ ; $i++; } } thanks Brian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Looking for a quick, easy way to time system process to the sub-second
-Original Message- From: Dan Huston [mailto:dan.hus...@domail.maricopa.edu] Sent: Friday, April 10, 2009 11:24 To: beginners@perl.org Subject: Looking for a quick, easy way to time system process to the sub-second Greetings All: I have a script that I am using to run a series of sql statements against two different Oracle databases to compare performance based on a request from our DBAs. I am currently using code like this: $time1 = time(); $result = `$this_comm`; $time2 = time(); $time_tot = $time2 - $time1; but the problem that I have is that most of the queries complete in less than one second so I either need to rewrite the queries to make them run longer or I need a more fine grained timing sstem that would do sub second timing, preferably something in the stand perl distro. Any suggestions? You could tie to Perl Benchmark and run x iterations. Add in Time-HiRes and you should be able to get down to what you need. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us Thanks Dan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Replace string with list of strings via character changes
-Original Message- From: Kelly Jones [mailto:kelly.terry.jo...@gmail.com] Sent: Friday, April 10, 2009 13:33 To: beginners@perl.org Subject: Replace string with list of strings via character changes I want to replace all the o's in a string with x's or y's and all the a's in a string with u's or v's. Example: given string foobar, the output would be this list of strings fxxbur (change both o's to x, and the a to u) fxxbvr (both o's to x, a to y) fxybur (first o to x, second to y, and the a to u) fxybvr (and so on...) fyxbur fyxbvr fyybur fyybvr I am not following at all given what you state you want to do, then in your example you have something else and then add in ( and so on... ). Do you want to change o's to x one time and y the next and a to u then y the next time? Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us What's the best subroutine to do this? I've got some ideas, but they're all fairly complex. Reason I'm doing this (if anyone cares): I want to ASCII-ify the geonames alternatenames table using iso-8859-1. Most of the translations are obvious: s/[\xc0-\xc5]/A/sg; s/\xc6/AE/sg; s/\xc7/C/sg; s/[\xc8-\xcb]/E/sg; s/[\xcc-\xcf]/I/sg; s/\xd1/N/sg; s/[\xd2-\xd6\xd8]/O/sg; s/[\xd9-\xdc]/U/sg; s/\xdd/Y/sg; s/[\xe0-\xe5]/a/sg; s/\xe6/ae/sg; s/\xe7/c/sg; s/[\xe8-\xeb]/e/sg; s/[\xec-\xef]/i/sg; s/\xf1/n/sg; s/[\xf2-\xf6\xf8]/o/sg; s/[\xf9-\xfc]/u/sg; s/[\xfd\xff]/y/sg; but eth can be translated as d or dh, thorn can be translated as th or y, and sharp s can be translated as ss or sz. In all cases, I want to use *both* translations to have the largest possible ASCII-ification. -- We're just a Bunch Of Regular Guys, a collective group that's trying to understand and assimilate technology. We feel that resistance to new ideas and technology is unwise and ultimately futile. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Converting an XML doc ( xls format ) to CSV
I have two files which are xml based and double clickable into Excel. I would like to get the data into a CSV, but when I try to read using use Spreadsheet::ParseExcel; I get no ouput and no errors. I looked at XML::Simple and followed the example they had but it generates several thousand lines. The processing occurs in the early AM and I am trying to tie together. I know if I open in Excel and can do save as, but this is not automation of the process. I have data from another stream and am trying to pull in these two files to merge the data into one email verses three as they are being handled now. Any thoughts or ideas on how one could approach this?? If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Network Printing using a Perl Script
-Original Message- From: Aglipay, Recelyn [mailto:recelyn.agli...@ehmc.com] Sent: Thursday, March 12, 2009 07:19 To: Wagner, David --- Senior Programmer Analyst --- CFS; beginners@perl.org Subject: RE: Network Printing using a Perl Script Hi Dave, I'm using a third party application to call the perl script. This application only allows for subroutines to be written since the app also uses some perl. So the code below is all I have. My goal was to open the directory which contains .dat files. Print all of them to the printer. I've tried using different syntax for the open command but all I get is the message I've created within the code Unable to open the printer. I had thought that my line of code for the open would do the printing? Is there another command I would need to use? I know there is a print command but I thought that would only be used if you want to print text that you define? Can you use it to print a file? Thanks for your help. -Recelyn -Original Message- From: Wagner, David --- Senior Programmer Analyst --- CFS [mailto:david.wag...@fedex.com] Sent: Wednesday, March 11, 2009 5:48 PM To: Aglipay, Recelyn; beginners@perl.org Subject: RE: Network Printing using a Perl Script -Original Message- From: Aglipay, Recelyn [mailto:recelyn.agli...@ehmc.com] Sent: Wednesday, March 11, 2009 15:35 To: beginners@perl.org Subject: Network Printing using a Perl Script Hello everyone, I'm a beginner and having some issues with a Perl Script I had written for work. I am trying to print to a network label printer. I've verified that the printer is working on its own. But when I try to print to it using Perl nothing happens. Here is an untested portion of code to read the directory, read a file, print what is in the file and loop through the directory until end of directory. my $port = 9100; my $printer1 = q[\\10.10.10.10\Zebra LP2824]; my $directory = q[D:/TEST/TDS/EdPtLabels]; my $FileToRead; opendir(DIRECTORY, $directory) || die Couldn't Open the Directory!: $!; # # you have opened directory, but you need to read the directory until done while ( 1 ) { $FileToRead = readdir(DIRECTORY); last if ( ! defined $FileToRead); open(FILETOREAD, q[] . $FileToRead) || die Unable to open input $FileToRead; $!; open(OUTPUT_PRINTER, q[] . $printer1 . q[\] . $port) || die Unable to open the printer!: $!; # # Here you need to write to the OUTPUT_PRINTER # depending on what is in the file. If it is set to print, then something as easy as # while ( FILETOREAD ) { print OUTPUT_PRINTER $_; } close(FILETOREAD); close(OUTPUT_PRINTER); # # unsure if you want to print success after each file printed or what # here is going to be printed after each file print LOG_FILE \n--\n print LOG_FILE The label was printed successfully\n; print LOG_FILE \n--\n; } # end of loop ro read thru directory close(DIRECTORY); Here is a copy of my code. I get the message The label was printed successfully in my log but nothing ever printed. return 1; sub PRINT_LABEL { my $port = 9100; my $printer1 = \\10.10.10.10\Zebra LP2824; With double quotes, you are not getting waht you think. When slashes(\) and double quotes are involved, then need to double the slashes or use single quotes. my $directory = D:/TEST/TDS/EdPtLabels; opendir(DIRECTORY, $directory) || die Couldn't Open the Directory!; open(OUTPUT_PRINTER, $printer1\$port) || Again the double quotes and the \ are not doing what yiou think. die Unable to open the printer!; Either you have code missing or you think something is happening by the opendi. At this point, you have an open directory and attempted open output, but no where do I see you doing the printing of the file(s). Is there code missing or is this it? If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us
RE: Network Printing using a Perl Script
-Original Message- From: Aglipay, Recelyn [mailto:recelyn.agli...@ehmc.com] Sent: Wednesday, March 11, 2009 15:35 To: beginners@perl.org Subject: Network Printing using a Perl Script Hello everyone, I'm a beginner and having some issues with a Perl Script I had written for work. I am trying to print to a network label printer. I've verified that the printer is working on its own. But when I try to print to it using Perl nothing happens. Here is a copy of my code. I get the message The label was printed successfully in my log but nothing ever printed. return 1; sub PRINT_LABEL { my $port = 9100; my $printer1 = \\10.10.10.10\Zebra LP2824; With double quotes, you are not getting waht you think. When slashes(\) and double quotes are involved, then need to double the slashes or use single quotes. my $directory = D:/TEST/TDS/EdPtLabels; opendir(DIRECTORY, $directory) || die Couldn't Open the Directory!; open(OUTPUT_PRINTER, $printer1\$port) || Again the double quotes and the \ are not doing what yiou think. die Unable to open the printer!; Either you have code missing or you think something is happening by the opendi. At this point, you have an open directory and attempted open output, but no where do I see you doing the printing of the file(s). Is there code missing or is this it? If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us print LOG_FILE \n--\n; print LOG_FILE The label was printed successfully\n; print LOG_FILE \n--\n; closedir (DIRECTORY); close (OUTPUT_PRINTER); } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Printing directory sizes
-Original Message- From: lauri.nikki...@gmail.com [mailto:lauri.nikki...@gmail.com] On Behalf Of Lauri Nikkinen Sent: Tuesday, March 03, 2009 12:10 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: Perl Beginners Subject: Re: Printing directory sizes Thanks, how can I check if the module File::find is installed on my system? I can't locate it from the ppm interface. -L File::Find is part of the Std Perl Install and shoule be there. You should not have to do anything for installing. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us 2009/3/3 Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@freight.fedex.com -Original Message- From: lauri.nikki...@gmail.com [mailto:lauri.nikki...@gmail.com] On Behalf Of Lauri Nikkinen Sent: Tuesday, March 03, 2009 11:38 To: Perl Beginners Subject: Printing directory sizes Hi, I'm trying to print directory sizes using script from http://coding.derkeiler.com/Archive/Perl/perl.beginners/2005-0 8/msg00693.html and when I try it from the cmd.exe C:\Perlperl Print_directory_sizes.pl C:/Temp but I get an error message saying use of uninitialized value etc. Where is the problem? I'm using Win XP. ---code--- #!/bin/perl use warnings; use strict; use File::Find::Rule; my $dir = $ARGV[0]; my $size; find( sub { -f and ( $size += -s _ ) }, $dir ); ---code--- I took the code and removed the ::Rule and left the other and it ran fine, but did not print anything. So I add a print statement for the $size and it worked without any error msgs,etc and it gve the right values. What actually happens when you run? Not just the use of uni.. but all the output. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Printing directory sizes
From: lauri.nikki...@gmail.com [mailto:lauri.nikki...@gmail.com] On Behalf Of Lauri Nikkinen Sent: Tuesday, March 03, 2009 13:00 To: Chas. Owens Cc: Wagner, David --- Senior Programmer Analyst --- CFS; Perl Beginners Subject: Re: Printing directory sizes Thanks Chas! On windows side this seems to work C:\perl -MFile::Find -le print 'ok' ok and it seems that File::Find module is installed though ppm won't locate it (ppm query File::Find). And I don't know why. On mac's side I followed Chas's orders, but I can't get any output ~ perl -MFile::Find -le 'print ok' ok ~ cat Print_directory_sizes.pl #!/usr/bin/perl use warnings; use strict; use File::Find; my $dir = defined $ARGV[0] ? $ARGV[0] : '.'; my $size; find( sub { -f and ( $size += -s _ ) }, $dir ); ~ perl Print_directory_sizes.pl ~ or ~ perl Print_directory_sizes.pl Documents/ ~ Do you know why? You are not printing anything in your script. You add to $size, but you must either do a print or printf depending on what you want to display the results... If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -L 2009/3/3 Chas. Owens chas.ow...@gmail.com On Tue, Mar 3, 2009 at 14:47, Lauri Nikkinen lauri.nikki...@iki.fi wrote: I uninstalled ActiveState Perl via Add/Remove Programs and installed it (ActivePerl 5.10.0 Build 1004) again from here http://www.activestate.com/activeperl/ and I got the same answer from ppm query File::Find. I don't know if it has something to do with the Windows 'cause I'm running Windows XP via Parallels Desktop (as a virtual computer) on my Macbook Pro. I haven't had any difficulties with other programs. snip File::Find is part of Core Perl. If it weren't installed by Activestate's Perl installer many people would be up in arms. Try writing a simple script using it or saying perl -MFile::Find -le print 'ok' in cmd.exe. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read.
RE: Printing directory sizes
-Original Message- From: lauri.nikki...@gmail.com [mailto:lauri.nikki...@gmail.com] On Behalf Of Lauri Nikkinen Sent: Tuesday, March 03, 2009 11:38 To: Perl Beginners Subject: Printing directory sizes Hi, I'm trying to print directory sizes using script from http://coding.derkeiler.com/Archive/Perl/perl.beginners/2005-0 8/msg00693.html and when I try it from the cmd.exe C:\Perlperl Print_directory_sizes.pl C:/Temp but I get an error message saying use of uninitialized value etc. Where is the problem? I'm using Win XP. ---code--- #!/bin/perl use warnings; use strict; use File::Find::Rule; my $dir = $ARGV[0]; my $size; find( sub { -f and ( $size += -s _ ) }, $dir ); ---code--- I took the code and removed the ::Rule and left the other and it ran fine, but did not print anything. So I add a print statement for the $size and it worked without any error msgs,etc and it gve the right values. What actually happens when you run? Not just the use of uni.. but all the output. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: calling a program from a perl script and redirecting to output to a file
-Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 09:12 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: beginners@perl.org Subject: Re: calling a program from a perl script and redirecting to output to a file Thank you David. A typical output file comprises ~200 lines. Most of those files are useless and thus the arrays that contain theirs lines will occupy extra memory. I am running many such scripts concurrently which invoke similar processes several times so I'm wondering if there is a way to erase those arrays from memory upon completion of the execution. You can do undef @myout; but it really depends upon what system you are running under and how they handle the release of memory. This should cutdown, but you could also use brackets like: { my @myout = `program file`; # now process what is in @myout and either save to another arry which you want to write eventually or # write to a file with the necessary data that meets your criteria } after the }, the my @myout would be released thanks in advance, Thomas 2009/2/19 Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com -Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: calling a program from a perl script and redirecting to output to a file
-Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Delay in sending email via Perl
Within Outlook, one can create an email and then not send it until a date and time has been met. Can this also be done via Perl and either Sendmail or Sender? I looked at the doc and did not see anything about delay of sending. Found delay on retires, etc., but nothing on delay in actually sending the email. I am trying to verify if can be done or is this something that Outlook is handling itself in some procedure itself??? Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Loading results of pattern match into an array - help please
-Original Message- From: jeffqt...@gmail.com [mailto:jeffqt...@gmail.com] Sent: Friday, January 23, 2009 12:58 To: beginners@perl.org Subject: Loading results of pattern match into an array - help please I am trying to split a very long fixed lenght record into its constituents, and then load them into an array. I have patterns like '^ (.{3})(.{24})(.{6})...' which gets teh fields into $1, $2, $3 etc. I am stumped however as to how to get them into an array in a general way. With 'use strict' turned off I can force it with the ugly ${$i} construct in a loop, but I would prefer something that was 'strict' compatible. I havebasic. read the perodlc on @-, %-, %+, and none seem to do what I want - but that probably because I am missing something it does a double regex and one of the gurus can probably do it without the double, but this does work: #!/usr/bin/perl use strict; use warnings; my @MyWorka = (); while ( DATA ) { chomp; next if ( /^\s*$/ ); if ( /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ ) { @MyWorka = (/(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/); printf %s\n, join(q[|], @MyWorka ); } else { printf not correct number of fields on line to load into array:\n; printf (%6d)%s\n, $., $_; } } __DATA__ 1234 1234 1235 1236 1237 1234 1234 1235 1236 Output: 1234|1234|1235|1236|1237 not correct number of fields on line to load into array: ( 3)1234 1234 1235 1236 So, any help gratefully accepted Jeff -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/