Re: Problem with Encoding
John Delacour wrote: At 7:32 pm +0100 17/2/05, Philippe de Rochambeau wrote: I am trying to convert MacRoman encoded text to iso-8859-1... The input file, data.txt contains the following string: Les éléphants sont arrivés. EURO First of all iso-8859-1 does not contain the Euro sign. The character set you probably intend is Windows-1252 No he doesn't, he wants iso-8859-15 -- David Cantrell | Reality Engineer, Ministry of Information WARNING! People in front of screen are stupider than they appear -- Tanuki the Raccoon-dog, in the Monastery
Re: Problem with Encoding
At 12:33 pm + 18/2/05, David Cantrell wrote: First of all iso-8859-1 does not contain the Euro sign. The character set you probably intend is Windows-1252 No he doesn't, he wants iso-8859-15 I doubt it very much, but you seem to have inside information. #!/usr/bin/perl -w use Encode; $euro = \x{20ac}; $mac = encode(MacRoman, $euro); $cp1252 = encode(cp1252, $euro); $latin9 = encode(iso-8859-15, $euro); print $mac $cp1252 $latin9;
Re: Suggestions to better ship Perl on OS X.
Yes, you're right ... I suppose that Find in the Finder doesn't find it because /System is excluded from Find, unless you specifically choose it? sudo find / -name perlfunc*
Re: Problem with Encoding
John Delacour wrote: At 12:33 pm + 18/2/05, David Cantrell wrote: First of all iso-8859-1 does not contain the Euro sign. The character set you probably intend is Windows-1252 No he doesn't, he wants iso-8859-15 I doubt it very much If he says he wants ISO 8859 1 and he says he wants the Euro sign, then he wants ISO 8859 15 which is identical to 8859 1 but with the generic currency symbol replaced with the Euro symbol, and a few rarely used characters replaced with slightly less rarely used letters. but you seem to have inside information. That's funny, so do you when you claim he probably intends some odd proprietary Microsoft thing from their legacy Windows operating system. Using that is dangerous both because whether the euro character is present in the character set depends on which version of windows-1252 you use, and also because software support for it is poor. #!/usr/bin/perl -w use Encode; $euro = \x{20ac}; $mac = encode(MacRoman, $euro); $cp1252 = encode(cp1252, $euro); $latin9 = encode(iso-8859-15, $euro); print $mac $cp1252 $latin9; That prints a capital-U with circumflex (I think, it's hard to see), followed by two spaces, followed by a Euro symbol, proving my point rather elegantly. Thankyou! -- David Cantrell | Reality Engineer, Ministry of Information If I was made in God's image, does that make God a grouchy unshaven pervert?
Re: Variables in external file
On 2005.2.19, at 01:39 AM, Mark Wheeler wrote: Hi, Just a quick question. Is it possible to have a bunch of variables in a separate file and then require that file in the script file? Let me give you and example. -- Script file -- #!/usr/local/bin/perl -w use strict; require variables.conf print Content-type: text/html\n\n; foreach (@list) { print; } exit; - variables.conf - my @list; I remember how my works in blocks, but I'm having trouble remembering how my works in files. And I'm having trouble remembering what to do when you actually _want_ a declaration to have global effect. Where're my books? $list[0] = '1'; $list[1] = '2'; $list[2] = '3'; $list[3] = '4'; $list[4] = '5'; 1; - When I try the above script, I get an error - Global variable @list needs to be defined. What am I doing wrong, or is this even possible? Thanks, Mark
Re: Variables in external file
At 4:54 pm + 18/2/05, Neil Bowers wrote: You'll need to declare the variable in the script ('our', not 'my'), before you require variables.conf I don't think it needs to be before; for (our @list) { print } will do the trick. JD
Re: Variables in external file
On 2005-02-18 Mark Wheeler wrote: Ok... I made the changes, but still no luck. Here is the script as it is, now. -- test.cgi -- #!/usr/bin/perl -w use strict; our @list; require 'variables.conf'; foreach (@list) { print; } exit; --- variables.conf --- $list[0] = '0'; $list[1] = '1'; $list[2] = '2'; $list[3] = '3'; $list[4] = '4'; 1; --- What am I missing here? Thanks for your help. That works here. What errors or warnings are you getting? Did you get rid of the my @list; declaration in the require()ed file (variables.conf)? Permissions OK? If you're running an earlier version of Perl, instead of our @list; write this: use vars qw/@list/; before the require() statement. In the bigger picture, yes, storing Perl code and data structures in separate files is a widespread practice, rightly so as part of Perl's easy extensibility. For a learning path that gives the most solid foundation to this practice, consider starting now with always running your scripts in taint mode. What you read in from external files is not secure in many situations, especially networks -- e.g., the Internet. Some common script operations, such as open()ing a file with a path stored in an external config file, could cause severe security issues. If you incorporate the simple steps required to untaint external data from the beginning, your programs will more strongly handle increased complexity and public exposure. And you will avoid the stress of combing back through a program you need to make secure, trying to find the elusive points where the -T switch tenaciously challenges you, an enterprise in which you may risk losing your appreciation of logically organized electron flows. HTH - Bruce __bruce__van_allen__santa_cruz__ca__
Re: Variables in external file
On Feb 18, 2005, at 10:39 AM, Mark Wheeler wrote: Hi, Just a quick question. Is it possible to have a bunch of variables in a separate file and then require that file in the script file? It's generally not a wise choice. Better to use something like Data::Dumper to write the data to a file, then load it back in the way the Data::Dumper manpage describes. Or YAML (as Rich pointed out), or Storable, etc. If you don't like that approach, consider at *least* wrapping it in a subroutine: -- Script file -- #!/usr/local/bin/perl -w use strict; require variables.conf print Content-type: text/html\n\n; foreach (list) { print; } exit; - variables.conf - my @list; $list[0] = '1'; $list[1] = '2'; $list[2] = '3'; $list[3] = '4'; $list[4] = '5'; sub list { @list } 1; -
Re: Looking for easy sessions using mod_perl
On Fri, 2005-02-18 at 12:43 -0600, Boysenberry Payne wrote: Normally in php it's as simple as: session_start(); It's that easy with mod_perl too if you use Apache::SessionManager. Save yourself some trouble and just use that. http://search.cpan.org/search?query=Apache-SessionManagermode=dist - Perrin
Heredoc
I'm looking for the perl equivalent of a heredoc declaration. For some reason I can't recall how. In php it would work like this: $foo = EOD Stuff stuff stuff EOD; I need to declare a several line string in a quick and easy fashion. Any ideas? Christopher
Re: Heredoc
* Christopher L. Filkins [EMAIL PROTECTED] I'm looking for the perl equivalent of a heredoc declaration. For some reason I can't recall how. In php it would work like this: my $foo = EOD; Stuff stuff stuff EOD
Re: Heredoc
In perl it's a heredoc. You use instead of , and you need to specify EXACTLY what you put AFTER the as the terminator. So, in the example you posted, you would put $foo=EOD ... EOD; You can't have spaces before the EOD; terminator unless the same number of spaces also follows the . -Jeff Lowrey At 05:15 PM 2/18/2005, Christopher L. Filkins wrote: I'm looking for the perl equivalent of a heredoc declaration. For some reason I can't recall how. In php it would work like this: $foo = EOD Stuff stuff stuff EOD; I need to declare a several line string in a quick and easy fashion. Any ideas? Christopher
Building external modules
Where can I find printed docs on how to build external modules on MacOS X? For some reasons perldoc don't work correctly when piping output into the lpr command. All titles/subtitles get duplicated cchhaarraacctteerrss (like the previous word), making the output nearly unreadable. Are there any suitable books on this topic? Home is not where you are born, but where your heart finds peace - Tommy Nordgren, The dying old crone
Re: Heredoc
* Chris Devers [EMAIL PROTECTED] Doesn't that look so much easier than heredoc syntax? You can pick whatever quot delimiters work best for the output of the moment, you don't have to keep track of the fiddly TOKEN; syntax, you don't get tripped up if the closing quote has *gasp* proper indentation, etc. Warning! The qq[] syntax produces different output than the heredoc: my $foo = EOD; asdf EOD my $bar = qq[ asdf ]; print uh oh unless $foo eq $bar; Another alternative would be to template the output via HTML::Template or similar.
Re: Heredoc
On Fri, 18 Feb 2005, Jeremy Mates wrote: Warning! The qq[] syntax produces different output than the heredoc: my $foo = EOD; asdf EOD my $bar = qq[ asdf ]; print uh oh unless $foo eq $bar; Right. The qq[] syntax above as I offered earlier, tacks on newlines. These are identical: $ cat ptest #!/usr/bin/perl my $foo = EOD; asdf EOD my $bar = qq[asdf ]; print uh oh unless $foo eq $bar; print qq{ \$foo: [$foo] \$bar: [$bar] }; $ perl ptest $foo: [asdf ] $bar: [asdf ] $ That's just wacky that I had to force a newline on the qq form to get a match; I don't see this as validating the heredoc approach at all. I find the qq[] form so much more readable forgiving than heredocs that I generally never even consider using them unless I'm maintaing something that uses them heavily or are otherwise forced to use them. They have so little to offer though that I avoid them otherwise... But as I say, YMMV... -- Chris Devers
Taint mode (was Re: Variables in external file)
--- Bruce Van Allen [EMAIL PROTECTED] wrote: And you will avoid the stress of combing back through a program you need to make secure, trying to find the elusive points where the -T switch tenaciously challenges you, an enterprise in which you may risk losing your appreciation of logically organized electron flows. Which reminds me... I've been using the #!/usr/bin/env perl shebang for easier distribution, but env doesn't like switches. Is there a way to set taint mode via `use` or the like (ala use warnings; for -w). I can't seem to locate anything in the manuals other than the -T flag. Live well, ~wren __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail