From mengel at allegheny.edu Tue Sep 4 11:04:53 2007 From: mengel at allegheny.edu (Matthew T. Engel) Date: Tue, 4 Sep 2007 14:04:53 -0400 Subject: [pgh-pm] system() not displaying scalar text Message-ID: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> I think the problem is that I am trying to use the system function to echo text to the terminal. Something like: #!/usr/bin/perl while(<>) { chomp; system("echo $_"); } If I run the script via $ cat ascii_text_file | ./above_script.pl Everything works fine where it essentially cats the input file. However, if I do a $ cat unicode_text_file | ./above_script.pl. I get blank lines where the echo'd data should be. I think the second file is Unicode because doing a $od -c Unicode_text file, shows /0 in front of all the characters, and if I vi the same file it shows ^@ before every character. I would like to be able to use Unicode and ascii text files interchangeabley. please advice. Thank you very much in advance. Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/pgh-pm/attachments/20070904/e39a84a8/attachment.html From Dan at DWright.Org Tue Sep 4 13:23:55 2007 From: Dan at DWright.Org (Daniel J. Wright) Date: Tue, 4 Sep 2007 16:23:55 -0400 (EDT) Subject: [pgh-pm] system() not displaying scalar text In-Reply-To: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> References: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> Message-ID: <4412.10.8.0.6.1188937435.squirrel@webmail8.pair.com> I wonder if the issue is that you are trying to interpolate unicode into a normal string. What happens if you do this instead? system( 'echo', $_ ); Also, I presume that "echo $_" isn't really what you are trying to do with the system call and that you're just using that for demo purposes? -Dan From pm at benizi.com Tue Sep 4 13:29:09 2007 From: pm at benizi.com (Benjamin R. Haskell) Date: Tue, 4 Sep 2007 16:29:09 -0400 (EDT) Subject: [pgh-pm] system() not displaying scalar text In-Reply-To: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> References: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> Message-ID: On Tue, 4 Sep 2007, Matthew T. Engel wrote: > I think the problem is that I am trying to use the system function to echo > text to the terminal. Something like: First off, in your example, there's no need to 'cat' the files into your script. You can just pass them as extra parameters, since you're using '<>', which uses '@ARGV' as its source for filenames to open. Secondly, why are you using: system("echo $_"); instead of: print "$_\n"; # or print $_, $/; # or print; # with the '-l' switch ;) If all you really want to do is echo data to the terminal, that's what you should do. > #!/usr/bin/perl > > while(<>) > > { > > chomp; > > system("echo $_"); > > } > > > > If I run the script via > > > > $ cat ascii_text_file | ./above_script.pl Everything works fine where it > essentially cats the input file. However, if I do a $ cat unicode_text_file > | ./above_script.pl. I get blank lines where the echo'd data should be. > > > > I think the second file is Unicode because doing a $od -c Unicode_text file, > shows /0 in front of all the characters, and if I vi the same file it shows > ^@ before every character. > > > > I would like to be able to use Unicode and ascii text files > interchangeabley. please advice. Thank you very much in advance. If you're worried about being able to use both "ASCII" (as in "7-bit ASCII") files and Unicode (as in "UTF-8" [or "UTF-16" == UCS-2]), you shouldn't have any problems whatsoever, if you just 'print' it to the terminal. If you're worried about interoperability between ASCII (as in "ISO-8859-*" [*=1,2,etc.]), then you'll *have* to do something more complicated. In order for perl to deal with ISO-8859-*, if it uses anything outside of 7-bit ASCII, you must let it know how to interpret the byte stream. (or, my recommendation: *convert it*.) >From your description, it sounds like your unicode_text_file is in UTF-16 (== UCS-2?), where each character is two bytes. Usually, to distinguish UTF-16-LE from -BE (little-/big-endian), there's a BOM (byte-order mark) of 0xfeff at the start of the file. I think 'iconv', a very useful program for converting character sets will handle that. Other useful resources might be to 'Super Search' on Perlmonks for 'Unicode' and UTF-8 or UTF-16. Best, Ben From mengel at allegheny.edu Tue Sep 4 13:32:47 2007 From: mengel at allegheny.edu (Matthew T. Engel) Date: Tue, 4 Sep 2007 16:32:47 -0400 Subject: [pgh-pm] system() not displaying scalar text In-Reply-To: <4412.10.8.0.6.1188937435.squirrel@webmail8.pair.com> References: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> <4412.10.8.0.6.1188937435.squirrel@webmail8.pair.com> Message-ID: <004101c7ef32$c18439e0$18e2c38d@allegheny.edu> Dan, Thanks for the reply. Using system( 'echo', $_ ); has the same results. Nothing but blank lines. From tom at moertel.com Tue Sep 4 14:37:17 2007 From: tom at moertel.com (Tom Moertel) Date: Tue, 04 Sep 2007 17:37:17 -0400 Subject: [pgh-pm] system() not displaying scalar text In-Reply-To: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> References: <003001c7ef1e$23190c90$18e2c38d@allegheny.edu> Message-ID: <46DDD00D.8060709@moertel.com> Matthew T. Engel wrote: > [...] However, if I do a $ cat > unicode_text_file | ./above_script.pl. I get blank lines where the > echo?d data should be. > > I think the second file is Unicode because doing a $od ?c Unicode_text > file, shows /0 in front of all the characters, and if I vi the same file > it shows ^@ before every character. That's your problem. Under the hood, arguments are passed to programs as traditional C-style, null-terminated strings. (For more, read man page for the exec(3) system call: "const char *arg: a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program.") Therefore, when you pass an argument that contains a 0 byte to Perl's "system" function, the program that Perl invokes will see only the portion of the argument up to the 0, but nothing more. For example: $ perl -e 'system "echo hi"' hi $ perl -e 'system "echo \0hi"' $ Cheers, Tom From schwern at pobox.com Fri Sep 21 17:35:55 2007 From: schwern at pobox.com (Michael G Schwern) Date: Fri, 21 Sep 2007 17:35:55 -0700 Subject: [pgh-pm] Flight for PPW fell through Message-ID: <46F4636B.3000800@pobox.com> Hi, all. Apologies for the cross-PM post but I'm in a bit of a bind. I'm scheduled to give two talks and a keynote at the Pittsburgh Perl Workshop next month. [1] I was hoping on contract work in Pittsburgh to pay for my flight to PPW and also the bills, but that work has been postponed until November. :( Now I have no flight for PPW and no work to pay for it. I'd rather work my way there then have PPW sponsors pay for me. So I'm asking nearby PM groups if they or their work would like to hire me in October for local work. I would charge travel but my normal fees would be substantially reduced and your company/group will get thanked in my PPW talks. Suggested work and training includes... * Improving your company's test suite * Improving how your company uses CPAN * Improved developer coordination through better version control (SVK) * Performance optimization * Simple Ways To Be A Better Programmer (very popular OSCON tutorial) http://www.slideshare.net/schwern/simple-ways-to-be-a-better-programmer-oscon-2007 * Geeks Communicating Better * Beginning Refactoring * Learning Interface Design To Improve Your Programming http://pghpw.org/ppw2007/talk/748 * Easing The Pain Of Transitioning From Class::DBI to DBIx::Class Or suggest something from the pile: http://schwern.org/~schwern/talks/ Thank you, Schwern [1] "Improving geek2geek Communications" http://pghpw.org/ppw2007/talk/746 "The Many Faces of SVK" http://pghpw.org/ppw2007/talk/747 The keynote is about the results of the Perl Survey (perlsurvey.org) -- There will be snacks. From faisal at faisal.com Mon Sep 24 11:11:03 2007 From: faisal at faisal.com (Faisal N Jawdat) Date: Mon, 24 Sep 2007 14:11:03 -0400 Subject: [pgh-pm] Fwd: ANN: Pittsburgh Coding Dojo - Sept 27 6:00 PM References: <7F1E518F-4D34-4951-A0A8-6428C867896E@insomnia-consulting.org> Message-ID: <14DE6DBF-2976-4066-9E21-55F5F1FE6A68@faisal.com> [Forwarding Greg's note as we're running into SMTP related incidents] The Pittsburgh Coding Dojo will be meeting Thursday September 27th, 6:00PM at the Pittsburgh Technology Council. The Dojo meetings are organized with a Challenge in mind. You can see the links to past meetings topics on http://pghcodingdojo.org/ index.php/DojoWiki:Community_Portal The Challenges are meant to be small programming problems that can be explored reasonably well in 2 hours. They are pure programming challenges that don't involve any system setup beyond a simple compiler and editor, and are language agnostic. More information can be found here http://pghcodingdojo.org/index.php/ Current_events We'll be working on various types of Sorting algorithms this month. Pizza and Refreshments will be provided. Please visit http://groups.yahoo.com/group/pghcodingdojo for updates and more information. Greg Akins http://insomnia-consulting.org http://pghcodingdojo.org --------------------------------------------------------------------- To unsubscribe, e-mail: pittjug-unsubscribe at pittjug.dev.java.net For additional commands, e-mail: pittjug-help at pittjug.dev.java.net