[28797] in Perl-Users-Digest
Perl-Users Digest, Issue: 41 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 17 09:05:49 2007
Date: Wed, 17 Jan 2007 06:05:05 -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 Wed, 17 Jan 2007 Volume: 11 Number: 41
Today's topics:
break ? <xx@wp.pl>
Re: break ? anno4000@radom.zrz.tu-berlin.de
Re: break ? <novafyre@hotmail.com>
Re: break ? <tadmc@augustmail.com>
how to use clearcase commands in perl script <sunil.vvn@gmail.com>
Re: imager sample for text <zentara@highstream.net>
Re: imager sample for text jcharth@hotmail.com
include file? <xx@wp.pl>
Re: include file? <wahab-mail@gmx.de>
Module for user preferences ~/. file traggatt@gmail.com
Re: Module for user preferences ~/. file anno4000@radom.zrz.tu-berlin.de
Re: Module for user preferences ~/. file traggatt@gmail.com
Re: Module for user preferences ~/. file anno4000@radom.zrz.tu-berlin.de
Re: Piping from perl to C <m@remove.this.part.rtij.nl>
Re: Question on SIGTERM <ced@blv-sam-01.ca.boeing.com>
separating attribution, quoted text, and sigs from the <art@example.com>
text converter <pawlaczus@yahoo.com>
Re: text converter <josef.moellers@fujitsu-siemens.com>
Re: text converter <wahab-mail@gmx.de>
Re: text converter anno4000@radom.zrz.tu-berlin.de
Variable substitution sebastien.godier@gmail.com
VB to Perl Excel OLE question....QueryTables gearoidterry@vodafone.ie
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Jan 2007 12:55:35 +0100
From: avlee <xx@wp.pl>
Subject: break ?
Message-Id: <op.tmarexh61sq83a@saturn>
Hello
Is there any command similar to break or continue ?
How can i leave loop earlier ?
Thanx
------------------------------
Date: 17 Jan 2007 12:07:17 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: break ?
Message-Id: <516hrlF1ivhmiU1@mid.dfncis.de>
avlee <xx@wp.pl> wrote in comp.lang.perl.misc:
> Hello
>
> Is there any command similar to break or continue ?
> How can i leave loop earlier ?
perldoc -f last
perldoc -f next
perldoc -f continue
Anno
------------------------------
Date: Wed, 17 Jan 2007 05:20:04 -0700
From: Mark Donovan <novafyre@hotmail.com>
Subject: Re: break ?
Message-Id: <C1D36284.9339%novafyre@hotmail.com>
On 1/17/07 04:55, "avlee" <xx@wp.pl> wrote:
> Is there any command similar to break or continue ?
> How can i leave loop earlier ?
>
The "last" command (like "break" in C) immediately exits a loop, and the
"next" command (like "continue" in C) starts the next iteration of a loop.
Perl also has 'redo' and 'continue' commands.
Here's an explanation from 'perldoc -f continue'.
"last", "next", or "redo" may appear within a "continue" block.
"last" and "redo" will behave as if they had been executed
within the main block. So will "next", but since it will
execute a "continue" block, it may be more entertaining.
while (EXPR) {
### redo always comes here
do_something;
} continue {
### next always comes here
do_something_else;
# then back the top to re-check EXPR
}
### last always comes here
Omitting the "continue" section is semantically equivalent to
using an empty one, logically enough. In that case, "next"
goes directly back to check the condition at the top of the
loop.
--
------------------------------
Date: Wed, 17 Jan 2007 07:02:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: break ?
Message-Id: <slrneqs7io.f4g.tadmc@tadmc30.august.net>
avlee <xx@wp.pl> wrote:
> How can i leave loop earlier ?
See the "Loop Control" section in perlsyn.pod.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Jan 2007 05:53:21 -0800
From: "sunil" <sunil.vvn@gmail.com>
Subject: how to use clearcase commands in perl script
Message-Id: <1169042001.213701.110690@s34g2000cwa.googlegroups.com>
Hi,
Presently I am having a requirement to use clearcase commands
in a perl script.
The requirement is given below.
1)I will set my view manually from the command line in the unix
prompt.
2)Afterwards from the perls script I have to set the configspecs A and
shuld have to go to the where source code presents.
3) I will do some operations over here
4) Setting the other configspecs B and goes to the source code where it
presents.
5) Doing some required tasks
6)Again setting back the config specs A
In this one from step 2 to step 6 I have to perform in the
perls script.
I am unable to set the configspec from a perl script. If anybody knows
please let me know how to set it.
Regards
Sunil
------------------------------
Date: Wed, 17 Jan 2007 12:01:44 GMT
From: zentara <zentara@highstream.net>
Subject: Re: imager sample for text
Message-Id: <fb3sq2167qvi4lhai0i1hdmm1hhtl4uksc@4ax.com>
On 16 Jan 2007 21:13:54 -0800, jcharth@hotmail.com wrote:
>hello anyone has a sample of rendering text in to a jpg using imager. I
>installed imager in my box but the code seems to show only a black
>patch
>
>my $font = Imager::Font->new(file=>"foo.ttf");
>
>$img->string(x => 50, y => 30,
> string => "$randstr",
> font => $font,
> size => 10,
> aa => 1,
> color => 'white');
You probably need to install the Freetype2 library to
support ttf files. Also make sure you have the ttf file
in the script directory, or else give the full path to the font file.
This works on my machine:
#!/usr/bin/perl
use warnings;
use strict;
use Imager;
my $img = Imager->new(xsize=>400,ysize=>300);
$img->box(filled=>1, color=>"ffffff"); #fill the background color
my $blue = Imager::Color->new("#0000FF");
my $font = Imager::Font->new(
file => 'Generic.ttf',
index => 0,
color => $blue,
size => 30,
aa => 1);
$img->string(
font=>$font,
text=>'This is a test string',
x=>20,
y=>70);
$img->write(file=>"$0.jpg", type=>"jpeg") or die "Cannot write file: ",
Imager->errstr;
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: 17 Jan 2007 06:01:04 -0800
From: jcharth@hotmail.com
Subject: Re: imager sample for text
Message-Id: <1169042464.714565.203300@38g2000cwa.googlegroups.com>
Thanks. Looks like I had ttf missing :( i notice when i recompiled
imager works. great now.
zentara wrote:
> On 16 Jan 2007 21:13:54 -0800, jcharth@hotmail.com wrote:
>
> >hello anyone has a sample of rendering text in to a jpg using imager. I
> >installed imager in my box but the code seems to show only a black
> >patch
> >
> >my $font = Imager::Font->new(file=>"foo.ttf");
> >
> >$img->string(x => 50, y => 30,
> > string => "$randstr",
> > font => $font,
> > size => 10,
> > aa => 1,
> > color => 'white');
>
> You probably need to install the Freetype2 library to
> support ttf files. Also make sure you have the ttf file
> in the script directory, or else give the full path to the font file.
>
> This works on my machine:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Imager;
>
> my $img = Imager->new(xsize=>400,ysize=>300);
> $img->box(filled=>1, color=>"ffffff"); #fill the background color
>
> my $blue = Imager::Color->new("#0000FF");
>
> my $font = Imager::Font->new(
> file => 'Generic.ttf',
> index => 0,
> color => $blue,
> size => 30,
> aa => 1);
>
> $img->string(
> font=>$font,
> text=>'This is a test string',
> x=>20,
> y=>70);
>
> $img->write(file=>"$0.jpg", type=>"jpeg") or die "Cannot write file: ",
> Imager->errstr;
> __END__
>
>
> zentara
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html
------------------------------
Date: Wed, 17 Jan 2007 12:47:43 +0100
From: avlee <xx@wp.pl>
Subject: include file?
Message-Id: <op.tmaq1tpa1sq83a@saturn>
Hello
I have some perl files with some basic fucntions which i would like to use.
It's just simple functions (not modules)
I wanted to use them in my next perl script.
How could i do that ?
Thanx
------------------------------
Date: Wed, 17 Jan 2007 13:04:40 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: include file?
Message-Id: <eol3md$e9s$1@mlucom4.urz.uni-halle.de>
avlee wrote:
> I have some perl files with some basic fucntions which i would like to use.
> It's just simple functions (not modules)
>
> I wanted to use them in my next perl script.
> How could i do that ?
If you have a perl file, say stuff.pl
and your script *requires* it for running,
say:
require 'stuff.pl';
But if you want to *do* something
somewhere with it, say:
do 'stuff.pl';
If your file is called stuff.pm and
you want to *use* it, say:
use stuff;
But there are subtle differences here,
it depends almost compltetely on what
you really want to do.
perldoc do
perldoc use
perldoc require
Regards
M.
------------------------------
Date: 17 Jan 2007 03:14:09 -0800
From: traggatt@gmail.com
Subject: Module for user preferences ~/. file
Message-Id: <1169032449.805492.222990@a75g2000cwd.googlegroups.com>
Hi
Does anyone know a module which will store/retreive user preferences
into a ~/.scriptprefs type file (e.g. like ~/.bashrc)?
Cheers
Tim
------------------------------
Date: 17 Jan 2007 12:18:41 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Module for user preferences ~/. file
Message-Id: <516ih1F1ivhmiU2@mid.dfncis.de>
<traggatt@gmail.com> wrote in comp.lang.perl.misc:
> Hi
>
> Does anyone know a module which will store/retreive user preferences
> into a ~/.scriptprefs type file (e.g. like ~/.bashrc)?
It isn't quite clear what you mean with "store/retrieve". For a
start take a look at the File::Tie module.
Anno
------------------------------
Date: 17 Jan 2007 04:33:09 -0800
From: traggatt@gmail.com
Subject: Re: Module for user preferences ~/. file
Message-Id: <1169037189.770811.92680@s34g2000cwa.googlegroups.com>
> It isn't quite clear what you mean with "store/retrieve". For a
> start take a look at the File::Tie module.
Sorry, I mean more of the retrieve really. I would like to store
preferences in a file with a format like this:
UserName tim
Password timspassword
DefaultHost timbox
etc...
This file could be created manually by the user. When executed, my Perl
script would look for the file and automatically load in these
preferences.
I had a look at the File::Tie module and it seems it would load the
file contents ok, but what could I use to parse the file's contents?
Cheers, Tim.
------------------------------
Date: 17 Jan 2007 13:13:12 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Module for user preferences ~/. file
Message-Id: <516ln8F1iinvsU1@mid.dfncis.de>
<traggatt@gmail.com> wrote in comp.lang.perl.misc:
> > It isn't quite clear what you mean with "store/retrieve". For a
> > start take a look at the File::Tie module.
>
> Sorry, I mean more of the retrieve really. I would like to store
> preferences in a file with a format like this:
>
> UserName tim
> Password timspassword
In plain text? Very bad idea. Let the user enter the password
manually when needed. Security and convenience are a trade-off.
> DefaultHost timbox
>
> etc...
>
> This file could be created manually by the user. When executed, my Perl
> script would look for the file and automatically load in these
> preferences.
>
> I had a look at the File::Tie module and it seems it would load the
> file contents ok, but what could I use to parse the file's contents?
File::Tie doesn't have special advantages for what you describe now.
You can still use it, of course.
Your file format looks like a list of name/value pairs, one per line.
That maps naturally to a Perl hash, call it %pref. The split function
can be used to parse the lines (untested):
my %pref;
while ( <$in> ) {
my ( $name, $value) = split $_, ' ', 2;
$pref{ $name} = $value;
}
Later you can access $pref{ UserName} to get the corresponding value.
It would be a good idea to allow comments and blank lines in the
file format.
Anno
------------------------------
Date: Wed, 17 Jan 2007 09:06:31 +0100
From: Martijn Lievaart <m@remove.this.part.rtij.nl>
Subject: Re: Piping from perl to C
Message-Id: <pan.2007.01.17.08.06.31.629318@remove.this.part.rtij.nl>
On Tue, 16 Jan 2007 21:29:55 -0500, Sherm Pendley wrote:
> If you have a question about how to write the C code, this isn't really the
> group for that - I suggest comp.lang.c instead.
I doubt that is an appropriate group. That group is about the C language,
not specific implementations. Better find some unix/posix programmer group.
M4
--
Redundancy is a great way to introduce more single points of failure.
------------------------------
Date: 17 Jan 2007 05:08:48 -0800
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Question on SIGTERM
Message-Id: <1169039328.686868.212590@v45g2000cwv.googlegroups.com>
wing328hk@gmail.com wrote:
> comp.llang.perl.moderated wrote:
>>> ....
> > > My next question is would it be possible to close the data stream from
> > > the client side (basicaly my script below that aims to read the first
> > > line or the mail header only) without reading all the data and without
> > > sending an SIGPIPE back to the mail program?
> > >
> >
> > You could cause the rest of the stream to be discarded:
> >
> > my( $header ) = <STDIN>; # instead of: my $header = <STDIN>
> >
> > this'll avoid the SIGPIPE.
>
> But using
> my( $header ) = <STDIN>;
> would still read all the data from the pipe, and then assign first line
> to $header, right? or it has the intelligence to read only the first
> line into $header and discard the rest.
>
> I want to avoid reading all the data from the pipe, which can be huge
> (~3MB). I'm only interested in email headers (ie the first few lines of
> data).
>
Yes, then we've reached an impasse. You can just just continue
to read the first line of the stream and quit of course ... but then
the SIGPIPE occurs when the next line gets written to the pipe
upstream. Does your upstream process there terminate with
"Broken pipe"... What problem are you trying to solve...?
As Xho mentioned earlier, you'd have to handle this upstream
on the write end of the pipe if that's problematic. If you're able to
catch or ignore the signal from that end or, better yet, filter the
stream and write only the first line, then the problem is solvable.
It may be as easy as including a 'local $SIG{PIPE} = 'IGNORE'...
but it may be more complicated. More details about your program
are needed.
--
Charles DeRykus
------------------------------
Date: 17 Jan 2007 11:36:35 -0000
From: Art Merkel <art@example.com>
Subject: separating attribution, quoted text, and sigs from the body of a post
Message-Id: <HY2RHLIL39099.2337384259@anonymous.poster>
I wonder if anyone would be willing to share some code for pulling out
the "meat" of the body of an e-mail or usenet post? I mean given the
example
=====begin example
On 01/16/07 Fred Smith wrote:
> blah blah
Foo bar! Foo foo bar!
> blah blah blah
That's all I have to say
--
Here's my witty sig.
=====end example
just to return this:
Foo bar! Foo foo bar!
That's all I have to say
I'm thinking of something involving while and the .. operator, but I'm
not sure how to get rid of the "...wrote:"-type line without screwing
up on posts that don't have one, or what pattern to use to catch the
common ones.
------------------------------
Date: 17 Jan 2007 02:18:46 -0800
From: "Abanowicz Tomasz" <pawlaczus@yahoo.com>
Subject: text converter
Message-Id: <1169029126.162346.289000@s34g2000cwa.googlegroups.com>
Hello
I would like to convert multiple characters or one character into one
character. Assume the following example:
Thi\u105 is stAbCange te=B1t
The conversion map looks like:
\u105 -> s
AbC -> r
=B1 -> x
The result after conversion should be:
This is strange text
How can I do that in PERL in order it to be simple and efficient.
I need some hints i.e. functions to use or at most a few lines of
example code.
Great THANKS for help.
------------------------------
Date: Wed, 17 Jan 2007 11:19:25 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: text converter
Message-Id: <eokto2$cfv$1@nntp.fujitsu-siemens.com>
Abanowicz Tomasz wrote:
> Hello
> I would like to convert multiple characters or one character into one
> character. Assume the following example:
>=20
> Thi\u105 is stAbCange te=B1t
>=20
> The conversion map looks like:
>=20
> \u105 -> s
> AbC -> r
> =B1 -> x
>=20
> The result after conversion should be:
>=20
> This is strange text
>=20
> How can I do that in PERL in order it to be simple and efficient.
> I need some hints i.e. functions to use or at most a few lines of
> example code.
I usually do it like this:
my %map =3D (
'\u105' =3D> 's',
'AbC' =3D> 'r',
'=B1' =3D> 'x'
);
my $string =3D 'Thi\u105 is stAbCange te=B1t';
while (my ($orig, $repl) =3D each %map) {
$string =3D~ s/\Q$orig\E/$repl/g;
}
print "$string\n";
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 17 Jan 2007 11:51:19 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: text converter
Message-Id: <eokvcr$d3p$1@mlucom4.urz.uni-halle.de>
Abanowicz Tomasz wrote:
> Hello
> I would like to convert multiple characters or one character into one
> character. Assume the following example:
>
> Thi\u105 is stAbCange teħt
>
> The conversion map looks like:
>
> \u105 -> s
> AbC -> r
> ħ -> x
>
> The result after conversion should be:
>
> This is strange text
>
> How can I do that in PERL in order it to be simple and efficient.
> I need some hints i.e. functions to use or at most a few lines of
> example code.
Joseph did already post a very nice solution,
so I could go and copy/paste some part for mine ;-)
...
my $string = q{Thi\u105 is stAbCange teħt};
$string=~s/\Q$_->[0]\E/$_->[1]/g
for
[ '\u105', 's' ],
[ 'AbC' , 'r' ],
[ 'ħ' , 'x' ]
;
...
Regards
M.
------------------------------
Date: 17 Jan 2007 12:54:38 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: text converter
Message-Id: <516kkeF1i5jooU1@mid.dfncis.de>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in comp.lang.perl.misc:
> Abanowicz Tomasz wrote:
> > Hello
> > I would like to convert multiple characters or one character into one
> > character. Assume the following example:
> >
> > Thi\u105 is stAbCange teħt
> >
> > The conversion map looks like:
> >
> > \u105 -> s
> > AbC -> r
> > ħ -> x
> >
> > The result after conversion should be:
> >
> > This is strange text
> >
> > How can I do that in PERL in order it to be simple and efficient.
> > I need some hints i.e. functions to use or at most a few lines of
> > example code.
>
> I usually do it like this:
>
> my %map = (
> '\u105' => 's',
> 'AbC' => 'r',
> 'ħ' => 'x'
> );
>
> my $string = 'Thi\u105 is stAbCange teħt';
> while (my ($orig, $repl) = each %map) {
> $string =~ s/\Q$orig\E/$repl/g;
> }
> print "$string\n";
Alternatively, one can pack all the patterns into one regex
alternation and do the conversion in a single s///g. To do
this reliably it is best to test long patterns before short
ones. If the map contained 'AbCd' besides 'AbC', the test for
'AbCd' must come first.
Starting from %map as above, the regex can be built like this:
my $re = join '|',
map quotemeta,
sort { length( $b) <=> length( $a) }
keys %map;
Then the conversion becomes
$string = ~ s/($re)/$map{ $1}/g;
On my machine, the one-regex solution is notably, but not
dramatically faster than the looping one (a factor of 2).
Then again it's more code and less direct, so harder to read.
Anyone's call...
Anno
------------------------------
Date: 17 Jan 2007 05:56:59 -0800
From: sebastien.godier@gmail.com
Subject: Variable substitution
Message-Id: <1169042219.914974.182980@38g2000cwa.googlegroups.com>
Hello,
My Perl script is first reading a text file containing a list of
computer names I want to run a command against.
The name of each computer is stored inside $_ variable.
So, I'm trying to generate my external command using this variable
inside a loop. Like this
system ("REG QUERY \"\\\\$_\\HKLM\\SOFTWARE\\MICROSOFT\\Internet
Explorer\\Main\" /v \"Start Page");
The problem is that $_ is not substituted at all. If I replace $_ by a
real computer name, it works. But I don't know how to declare $_ as a
variable in this line.
Any idea welcome!
Thanks
Sebastien
------------------------------
Date: 17 Jan 2007 02:59:57 -0800
From: gearoidterry@vodafone.ie
Subject: VB to Perl Excel OLE question....QueryTables
Message-Id: <1169031597.866351.71510@v45g2000cwv.googlegroups.com>
Hi,
I'm trying to convert this VB code:
ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\perl\2.csv", _
Destination:=Range("A1"))
into Perl and can't seem to get the syntax right. Can someone please
help me out? Here is what I have within Perl:
$xlBook->ActiveSheet->QueryTables->Add(Connection=>"TEXT;C:\perl\2.csv",
Destination=>Range("A1"));
I think the Connection parameter is Ok but the syntax on the
Destination parameter is definitely not correct.
Any advice is greatly appreciated.
Thanks,
Perl07.
------------------------------
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 41
*************************************