[30073] in Perl-Users-Digest
Perl-Users Digest, Issue: 1316 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 28 11:09:43 2008
Date: Thu, 28 Feb 2008 08:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 28 Feb 2008 Volume: 11 Number: 1316
Today's topics:
Re: a very simplistic example of a perl module <cartercc@gmail.com>
Re: Converting "’" to an Apostrophe? <RedGrittyBrick@SpamWeary.foo>
Re: Converting "’" to an Apostrophe? <stoupa@practisoft.cz>
executing source command from perl <michaelgang@gmail.com>
Re: executing source command from perl <peter@makholm.net>
Re: executing source command from perl <michaelgang@gmail.com>
Re: executing source command from perl <jurgenex@hotmail.com>
Generate an associative array from a file <gniagnia@gmail.com>
Re: Generate an associative array from a file <peter@makholm.net>
Re: Generate an associative array from a file <cartercc@gmail.com>
Re: Magic $a $b <joost@zeekat.nl>
monitor unix file for string jamesjesse68@yahoo.com
Re: monitor unix file for string <josef.moellers@fujitsu-siemens.com>
Re: monitor unix file for string <peter@makholm.net>
Permutations - Perl or just Javascript embedded ? <telemach@go2.pl>
Re: Permutations - Perl or just Javascript embedded ? <darthludi@gmail.com>
Re: Permutations - Perl or just Javascript embedded ? <joost@zeekat.nl>
unicode via DBI on linux to sql server 2005? <bugbear@trim_papermule.co.uk_trim>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Feb 2008 06:00:00 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: a very simplistic example of a perl module
Message-Id: <85511470-291e-4ac8-b6fe-a8875367ba5c@o77g2000hsf.googlegroups.com>
On Feb 27, 3:54 pm, BH <Benson....@googlemail.com> wrote:
> Interesting! It's interesting someone actually thinks that any typical
> school/university will teach Perl as a subject? ;)
I've had five years of post-bat CS and SE, and have never been exposed
to Perl in a University environment, but I ~have~ been exposed to
COBOL, Scheme, Python, C, Java (lots), Microsoft languages (lots),
shell scripts, assembly, X languages (XPath, XSLT, etc.), Mate,
Erlang, and others I can't remember. No Perl, none at all.
OTOH, I've taught at a college and taught the Perl course, which was
taught as part of a state required curriculum. Yes, my state mandated
that students learn Perl, but the curriculum was 20 years old when I
taught, and that was five years ago, and it still IS the curriculum.
I find it ironic that self-respecting academics won't touch Perl with
a ten foot pole, yet teach it because of 20 year old state mandates.
Don't get me wrong ... Perl is perhaps the most useful technology
invented, but maybe that's why academics don't like it.
CC
------------------------------
Date: Thu, 28 Feb 2008 14:37:39 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Converting "’" to an Apostrophe?
Message-Id: <47c6c737$0$2450$fa0fcedb@news.zen.co.uk>
RedGrittyBrick wrote:
>>> maria wrote:
>>>> I am using a CGI program to read XML files and extract their various
>>>> items. Somehow, my program converts the apostrophe "’" to ...
>>>> "\â\€\™".
It's more likely your browser is doing this than your CGI program.
Probably because your program lied about the character-set/encoding.
>>>> How do I program my CGI program to convert "’" to
>>>> an apostrophe, "'"?
You shouldn't.
>>>> Is there a little CGI code that will convert
>>>> all these different strings (including dagger, ellipsis, euro
>>>> symbol, double quote, etc.) to their ASCII equivalents?
No, because dagger, ellipsis and euro don't have ASCII equivalents!
> Unicode code-point u2019 is represented in UTF8 as the byte sequence e2
> 80 99 (shown here in hexadecimal), that same byte sequence, when
> interpreted as Latin-1 is the three characters ’ (a acute, euro,
> trademark).
>
> You can learn more about Perl's handling of unicode by typing the
> command `perldoc perlunicode`
>
Here's another example, but using XML instead of plain text. Perl has so
many different modules for handling XML and CGI that it is unlikely my
example matches your situation.
The following perl file can be dropped into a CGI directory. The first
line may need changing, depending on OS, webserver etc.
--------------------------------- 8< ----------------------------------
#!perl
#
# Demonstrate handling of Unicode characters in a UTF8 encoded XML file
#
# RGB 2008-02-28
#
use strict;
use warnings;
use XML::Simple;
use CGI qw/:standard/;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#
# First we write some Unicode to an XML file using UTF-8 encoding.
#
my $tempfile = "unicode.xml";
open (my $out, '>:utf8', $tempfile) or die "can't open $tempfile because
$!\n";
print $out <<ENDXML;
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar>
<baz>Here is a Unicode RIGHT SINGLE QUOTE MARK \x{2019}</baz>
</bar>
</foo>
ENDXML
close $out;
#
# Now we read our XML file and use it in a web-page
#
my $foo = XMLin($tempfile);
my $line = $foo->{bar}->{baz};
print header(-charset=>'utf-8'), # NOTE - Default is NOT utf-8
start_html(), h1("Unicode example"), pre($line), hr(), end_html();
--------------------------------- 8< ----------------------------------
In case it's not obvious, the only reason the example first writes a
file is so that I don't have to include a separate example data file.
The example is completely self contained. I could have used a DATA
section but felt that mishandling text file encodings might be part of
your problem.
------------------------------
Date: Thu, 28 Feb 2008 16:05:29 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Converting "’" to an Apostrophe?
Message-Id: <fq6j10$r0s$1@ns.felk.cvut.cz>
maria wrote:
> I am using a CGI program to read XML files and extract their various
> items. Somehow, my program converts the apostrophe "’" to ...
> "\â\?\T". How do I program my CGI program to convert "’" to
> an apostrophe, "'"? Is there a little CGI code that will convert
> all these different strings (including dagger, ellipsis,
> euro symbol, double quote, etc.) to their ASCII equivalents?
> Thank you very much.
>
You can use s/// for this.
my $xml = 'some maria’s text';
$xml =~ s/’/'/sg;
print $xml;
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Thu, 28 Feb 2008 05:23:54 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: executing source command from perl
Message-Id: <ff284034-fd34-4c95-83c6-d1baa89fb462@s37g2000prg.googlegroups.com>
Dear All,
I want to automize a process in perl.
In this process I have the following code
sub run_command {
my ($command) = @_;
print "$command\n";
system($command) == 0
or die "system $command failed: $? -- $!"
}
run_command('source init_file');
run_command('mycommand.pl -configfile config -exec ');
I get the following error
source init
Can't exec "source": No such file or directory at ..
system source init failed: -1 -- No such file or directory at ...
Can please someone help me to understand what i did wrong.
Best regards,
David
------------------------------
Date: Thu, 28 Feb 2008 13:28:39 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: executing source command from perl
Message-Id: <87ir0943co.fsf@hacking.dk>
david <michaelgang@gmail.com> writes:
> run_command('source init_file');
> run_command('mycommand.pl -configfile config -exec ');
I'm guessing that you are trying to read some environment variables
from init_file before running mycommand.pl?
That won't work. First problem is that source is a shell builtin and
not an independent program, this is why you are getting an
error. Another problem is that child processes can't set environment
variables if the parrent process and even if source was a real
program, it couldn't set the environment for mycommand.pl
//Makholm
------------------------------
Date: Thu, 28 Feb 2008 05:32:34 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: Re: executing source command from perl
Message-Id: <5d735027-6b9e-4b2f-80d5-f77d1ffcbee4@i12g2000prf.googlegroups.com>
On Feb 28, 3:28 pm, Peter Makholm <pe...@makholm.net> wrote:
> david <michaelg...@gmail.com> writes:
> > run_command('source init_file');
> > run_command('mycommand.pl -configfile config -exec ');
>
> I'm guessing that you are trying to read some environment variables
> from init_file before running mycommand.pl?
>
> That won't work. First problem is that source is a shell builtin and
> not an independent program, this is why you are getting an
> error. Another problem is that child processes can't set environment
> variables if the parrent process and even if source was a real
> program, it couldn't set the environment for mycommand.pl
>
> //Makholm
I understand, so it is better for this purpose to write a shell
script .
Thank you very much for your quick answer,
David
------------------------------
Date: Thu, 28 Feb 2008 13:38:30 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: executing source command from perl
Message-Id: <83eds3db04h6nn1kshmbfilnktp5slqmna@4ax.com>
david <michaelgang@gmail.com> wrote:
[...]
> system($command) == 0
> or die "system $command failed: $? -- $!"
[...]
>I get the following error
>source init
>Can't exec "source": No such file or directory at ..
>system source init failed: -1 -- No such file or directory at ...
>
>Can please someone help me to understand what i did wrong.
See third paragraph in the documentation for system():
perldoc -f system
jue
------------------------------
Date: Thu, 28 Feb 2008 05:59:00 -0800 (PST)
From: Mr_Noob <gniagnia@gmail.com>
Subject: Generate an associative array from a file
Message-Id: <a800a83f-1f15-4133-bc44-d72a0dae22c5@s37g2000prg.googlegroups.com>
Hi all,
here is a sample of my file :
## blah blah
[client1]
remote=192.168.1.2
### some comments here
### blah blah
[client2]
remote=192.168.1.5
passive=true
###blablah
[client3]
remote=192.168.1.8
[client4]
remote=192.168.1.15
passive=true
###
####
####
I am trying to write a perl script that would exclude all comments
from the above file and then generate an associative array, and output
the following result :
client1;192.168.1.1
client2;192.168.1.5;true
client3;192.168.1.8
client4;192.168.1.15;true
...
thanks in advance for ur help...
br
------------------------------
Date: Thu, 28 Feb 2008 14:06:35 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Generate an associative array from a file
Message-Id: <87ejax41lg.fsf@hacking.dk>
Mr_Noob <gniagnia@gmail.com> writes:
> I am trying to write a perl script that would exclude all comments
> from the above file and then generate an associative array, and output
> the following result :
Looks like something that is parsable by Config::INI, Config::Simple,
Config::Tiny or probaly a couple of other existing modules.
//Makholm
------------------------------
Date: Thu, 28 Feb 2008 06:56:56 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Generate an associative array from a file
Message-Id: <d04d20b4-a47a-4513-8eed-92a0ba3620d4@k2g2000hse.googlegroups.com>
On Feb 28, 8:59 am, Mr_Noob <gniag...@gmail.com> wrote:
> Hi all,
>
> here is a sample of my file :
>
> ## blah blah
> [client1]
> remote=192.168.1.2
> ### some comments here
> ### blah blah
> [client2]
> remote=192.168.1.5
> passive=true
> ###blablah
> [client3]
> remote=192.168.1.8
> [client4]
> remote=192.168.1.15
> passive=true
> ###
> ####
> ####
>
> I am trying to write a perl script that would exclude all comments
> from the above file and then generate an associative array, and output
> the following result :
>
> client1;192.168.1.1
> client2;192.168.1.5;true
> client3;192.168.1.8
> client4;192.168.1.15;true
> ...
>
> thanks in advance for ur help...
>
> br
Here is some pseudocode:
my %hash
open INFILE, <file.csv
while <INFILE>
next if $_ =~ /#/ #skip comments
if $_ =~ /[/ #create hash element
create hash element like $hash{client1}
if $hash{client1}
($key, $value) = split on /=/ #create vars
create hashref like $hash{client}{$key} = $value
close INFILE
foreach my $client (sort keys %hash)
foreach my $key (sort keys %{$hash{$client}})
print $hash{$client} - $hash{$client}{$key}
exit
------------------------------
Date: Thu, 28 Feb 2008 12:08:26 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Magic $a $b
Message-Id: <87pruh8hjp.fsf@zeekat.nl>
Achim Peters <achimpeters@gmx.de> writes:
> which in fact does print the 4711 (a German "magic" number) with Perl
> 5.8.2, thus no side effects of the sorting (except of course that the
> missing "my" in front of $a does not cause an compile error.
>
> Is there any example to prove his impertinence of questioning the gurus'
> wisdom?
I would think:
sub srt {
my @arr = qw /x a u q r/;
@arr = sort { $a cmp $b } @arr;
}
srt();
my $a = 4711;
print "$a\n";
versus:
srt();
my $a = 4711;
print "$a\n";
sub srt {
my @arr = qw /x a u q r/;
@arr = sort { $a cmp $b } @arr;
}
would be enough reason not to use $a and $b.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Thu, 28 Feb 2008 05:20:00 -0800 (PST)
From: jamesjesse68@yahoo.com
Subject: monitor unix file for string
Message-Id: <76ba7b6b-9998-4af5-b035-ed996ce8bfaf@p43g2000hsc.googlegroups.com>
Hello,
I have a requirement to monitor a log file in unix using perl 5.8.
Needed is detection of "error" in a line appended to the file.
Also need to detect if "complete" is not found after, say, 5 hours
after invocation.
I expect there is a hard way and an easy way to do this - could some
kind person advise me?
Pointers to Fine Perldocs welcome!
TIA
JJ
------------------------------
Date: Thu, 28 Feb 2008 14:23:42 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: monitor unix file for string
Message-Id: <fq6cjh$g91$1@nntp.fujitsu-siemens.com>
jamesjesse68@yahoo.com wrote:
> Hello,
>
> I have a requirement to monitor a log file in unix using perl 5.8.
> Needed is detection of "error" in a line appended to the file.
> Also need to detect if "complete" is not found after, say, 5 hours
> after invocation.
>
> I expect there is a hard way and an easy way to do this - could some
> kind person advise me?
> Pointers to Fine Perldocs welcome!
perldoc -q tail
How do I do a "tail -f" in perl?
HTH,
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Thu, 28 Feb 2008 13:24:23 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: monitor unix file for string
Message-Id: <87pruh43js.fsf@hacking.dk>
jamesjesse68@yahoo.com writes:
> Hello,
>
> I have a requirement to monitor a log file in unix using perl 5.8.
> Needed is detection of "error" in a line appended to the file.
'perldoc -q tail'
> Also need to detect if "complete" is not found after, say, 5 hours
> after invocation.
'perldoc -f alarm'
might be two useful pointers.
//Makholm
------------------------------
Date: Thu, 28 Feb 2008 04:19:22 -0800 (PST)
From: Telemach <telemach@go2.pl>
Subject: Permutations - Perl or just Javascript embedded ?
Message-Id: <fe8433e8-6a77-4ebc-a0eb-86b31c1fb8b6@h25g2000hsf.googlegroups.com>
Yesterday I was thinking all day long about what to use for
permutations and still can't figure out a solution. Situation is
this :
I found great small javascript function that does permutations but
this is quite an unusual one.
Every single digit is assigned to 3 or 4 letters so for example
permutations of number 23
could look like this :
ad
ae
af
bd
be
bf
cd
ce
cf
javascipt code is very simple and it looks like too simple to
understand by me (Perl newbie)
because there is no direct loop, just calling a sub from inside this
same sub
I'm having troubles in understanding this code and then rewriting in
Perl so my question is this :
would it be easier to use some javascript module for Perl and paste
javascipt code inside perl script or rewriting this but with help of
permutation modules ?
Problem is that there are 3 or 4 letters per digit and user can input
whatever long number string.
- Telemach -
------------------------------
Date: Thu, 28 Feb 2008 13:23:26 +0100
From: Peter Ludikovsky <darthludi@gmail.com>
Subject: Re: Permutations - Perl or just Javascript embedded ?
Message-Id: <1204201464.580536@nntpcache01.si.eunet.at>
Telemach wrote:
> javascipt code is very simple and it looks like too simple to
> understand by me (Perl newbie)
> because there is no direct loop, just calling a sub from inside this
> same sub
http://en.wikipedia.org/wiki/Recursion_(computer_science)
------------------------------
Date: Thu, 28 Feb 2008 13:40:13 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Permutations - Perl or just Javascript embedded ?
Message-Id: <87lk558daq.fsf@zeekat.nl>
Telemach <telemach@go2.pl> writes:
> I found great small javascript function that does permutations but
> this is quite an unusual one.
I can't really make sense of your description. If the code is that
simple it's probably short enough to post it here.
> javascipt code is very simple and it looks like too simple to
> understand by me (Perl newbie)
> because there is no direct loop, just calling a sub from inside this
> same sub
Yes, recursion. If you've never seen it before it may take a little
getting used to, I guess. Perl can do this just fine:
# this is an extremely silly example
function rec {
my $i = shift;
if ($i <= 0) {
return 0;
}
else {
return $i + rec($i-1);
}
}
> I'm having troubles in understanding this code and then rewriting in
> Perl so my question is this :
> would it be easier to use some javascript module for Perl and paste
> javascipt code inside perl script or rewriting this but with help of
> permutation modules ?
Using a javascript module for something that sounds as simple as this is
probably complicating the matter too much. You can translate most
javascript code fairly easily to perl.
> Problem is that there are 3 or 4 letters per digit and user can input
> whatever long number string.
I don't know what you're talking about.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Thu, 28 Feb 2008 14:03:56 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: unicode via DBI on linux to sql server 2005?
Message-Id: <13sdfqdjifcr77e@corp.supernews.com>
I'm not really sure which forum to post this on!
I am attempting to retrieve data from an sql server 2005 database, hosted,
store and manipulated on a Windows box.
My code is running on a Linux box, and I have been given
read-only access to the DB server.
Connection via DBI is working well, but I am failing
to extract unicode data from the DB, which I understand
from googling is stored internally as UCS2.
(I can get ascii data and numeric data fine)
I am using perl, DBI, and the DBD::Sybase driver.
So - has anyone retrieved "international" data
in the same (or similar) circumstances as this?
BugBear
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1316
***************************************