[29146] in Perl-Users-Digest
Perl-Users Digest, Issue: 390 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 28 14:09:54 2007
Date: Sat, 28 Apr 2007 11:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 28 Apr 2007 Volume: 11 Number: 390
Today's topics:
Re: $ENV HOME on windows <bik.mido@tiscalinet.it>
Can a network client specify an IP on the source side? yong321@yahoo.com
Re: Cat file a to *.xls files <glennj@ncf.ca>
Re: How to get the variable name, not values? <bik.mido@tiscalinet.it>
How to handling string contains single quote and double <vikrant.kansal@gmail.com>
Re: How to handling string contains single quote and do <vikrant.kansal@gmail.com>
Re: How to handling string contains single quote and do <mritty@gmail.com>
Re: How to handling string contains single quote and do <vikrant.kansal@gmail.com>
Re: How to handling string contains single quote and do (Jens Thoms Toerring)
Re: How to handling string contains single quote and do <vikrant.kansal@gmail.com>
How to open and read pdf file in Perl. <ranjitmaddipatla@gmail.com>
Re: How to open and read pdf file in Perl. <Peter@PSDT.com>
Re: Memory Management <mjcarman@mchsi.com>
perl newbie <saint.delasi@gmail.com>
Re: perl newbie <1usa@llenroc.ude.invalid>
Rounding up to the next .5 <justin.0704@purestblue.com>
Re: Rounding up to the next .5 <jurgenex@hotmail.com>
Re: Weird error after a configuration change <nobull67@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Apr 2007 12:22:27 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: $ENV HOME on windows
Message-Id: <518633ldudlnj877jn6o62piscu5ar3kji@4ax.com>
On Wed, 25 Apr 2007 23:53:48 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:
>What puzzles me deep is why Perl on Windows is not faking $ENV{HOME}
>if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present... I think this
I bet that if $ENV{HOMEPATH} is defined, then so is $ENV{HOMEPATH}!
;-)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 28 Apr 2007 07:34:54 -0700
From: yong321@yahoo.com
Subject: Can a network client specify an IP on the source side?
Message-Id: <1177770894.703714.158040@p77g2000hsh.googlegroups.com>
When I initiate a network connection to a remote server, is there a
way to specify an IP address on the source side? Take a Perl snippet
as an example (modified from "Programming Perl"):
#!/usr/local/bin/perl -w
require 5.002;
use Socket;
$remote = shift || 'locahost';
$port = shift || 2345;
$iaddr = inet_aton($remote) or die "No host: $remote";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname("tcp");
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
#Does it make sense to bind the socket with an IP on the source? How?
bind(SOCK, sockaddr_in(0, "10.6.143.111")) or die "bind: $!";
connect(SOCK, $paddr) or die "connect: $!";
print while <SOCK>;
close SOCK or die "close: $!";
exit;
I've never seen a bind() call on a client. I added it because I want
to designate a specific IP on a multihomed server. But it throws
error:
$ client.pl some.destination.example.com 22
bind: Cannot assign requested address at client.pl line <line number
pointing to the bind() line>.
That IP does exist as shown in ifconfig output. I suspect the first
argument to sockaddr() should not be 0. Any help is appreacited.
Yong Huang
[This message was posted to another group without a definitive answer]
------------------------------
Date: 28 Apr 2007 13:25:48 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Cat file a to *.xls files
Message-Id: <slrnf36iqs.8fm.glennj@smeagol.ncf.ca>
At 2007-04-27 08:52PM, "Tad McClellan" wrote:
> # untested
> for file in *.xls; do
> cat filea.txt $file >tmp
> mv tmp $file
> done
Pedantically, shell variables should always be quoted to protect spaces
et al:
# untested
for file in *.xls; do
cat filea.txt "$file" >tmp
mv tmp "$file"
done
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Sat, 28 Apr 2007 12:26:50 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How to get the variable name, not values?
Message-Id: <ga8633pnsp6vtbrni1vlgv298t103293ce@4ax.com>
On Sun, 22 Apr 2007 23:28:31 +0200, Mirco Wahab <wahab-mail@gmx.de>
wrote:
>Another problem here is 'my'-Variables, which don't have
>any entry into the symbol table (names) of the program,
>they use a so called 'local scratchpad'.
But then there's PadWalker.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 28 Apr 2007 01:41:14 -0700
From: vikrant <vikrant.kansal@gmail.com>
Subject: How to handling string contains single quote and double quote
Message-Id: <1177749674.198547.49420@e65g2000hsc.googlegroups.com>
Hi,
I facing a problem in saving a string contains single and double quote
into a file .The string look like the following:-
Example:-
Developer's community "com.lang.perl"
--------------------------------------------------------
The part of Code is:-
#!/bin/perl -w
use strict;
my $Date="10-09-2007";
system("echo '$Date;$String_Value' > data.txt");
----------------------------------------------------------------------------------------
Here,the $String_Value Variable store the string which i have
mentioned above.
I cannot put the slash( \ ) before the double quote's because in my
case value of input string is dynamic.
Also,I know putting a slash before double quote do not solve my
problem because single quote is left which will create the problem.I
get to know about this when i put slash before the double quote's.
The error coming on screen is:-
------------------------------------------------------------------------------------------------
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
-----------------------------------------------------------------------------------------------------
So,please tell me how do i handle this type of input.
I apologize if someone already asked this question earlier.
Thanks and Regards,
Vikrant
------------------------------
Date: 28 Apr 2007 01:45:21 -0700
From: vikrant <vikrant.kansal@gmail.com>
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <1177749921.546340.233670@y80g2000hsf.googlegroups.com>
On Apr 28, 1:41 pm, vikrant <vikrant.kan...@gmail.com> wrote:
> Hi,
> I facing a problem in saving a string contains single and double quote
> into a file .The string look like the following:-
>
> Example:-
> Developer's community "com.lang.perl"
> --------------------------------------------------------
> The part of Code is:-
>
> #!/bin/perl -w
> use strict;
>
> my $Date="10-09-2007";
>
> system("echo '$Date;$String_Value' > data.txt");
> ----------------------------------------------------------------------------------------
> Here,the $String_Value Variable store the string which i have
> mentioned above.
>
> I cannot put the slash( \ ) before the double quote's because in my
> case value of input string is dynamic.
> Also,I know putting a slash before double quote do not solve my
> problem because single quote is left which will create the problem.I
> get to know about this when i put slash before the double quote's.
>
> The error coming on screen is:-
> ------------------------------------------------------------------------------------------------
> sh: -c: line 0: unexpected EOF while looking for matching `''
> sh: -c: line 1: syntax error: unexpected end of file
> -----------------------------------------------------------------------------------------------------
>
> So,please tell me how do i handle this type of input.
> I apologize if someone already asked this question earlier.
>
> Thanks and Regards,
> Vikrant
Sorry for the Subject line mistake it should be something like
following:-
How to handle the string contains single quote and double quote
------------------------------
Date: 28 Apr 2007 03:26:26 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <1177755986.269514.48550@n59g2000hsh.googlegroups.com>
On Apr 28, 4:41 am, vikrant <vikrant.kan...@gmail.com> wrote:
> Hi,
> I facing a problem in saving a string contains single and double quote
> into a file .The string look like the following:-
>
> Example:-
> Developer's community "com.lang.perl"
> --------------------------------------------------------
> The part of Code is:-
>
> #!/bin/perl -w
> use strict;
>
> my $Date=3D"10-09-2007";
>
> system("echo '$Date;$String_Value' > data.txt");
> -------------------------------------------------------------------------=
--=AD-------------
> Here,the $String_Value Variable store the string which i have
> mentioned above.
>
> I cannot put the slash( \ ) before the double quote's because in my
> case value of input string is dynamic.
> Also,I know putting a slash before double quote do not solve my
> problem because single quote is left which will create the problem.I
> get to know about this when i put slash before the double quote's.
>
> The error coming on screen is:-
> -------------------------------------------------------------------------=
--=AD---------------------
> sh: -c: line 0: unexpected EOF while looking for matching `''
> sh: -c: line 1: syntax error: unexpected end of file
> -------------------------------------------------------------------------=
--=AD--------------------------
>
> So,please tell me how do i handle this type of input.
> I apologize if someone already asked this question earlier.
Why are you calling a system command to do the echoing? Just open the
file for writing in Perl, and print the line to the file in Perl.
Then you don't have to worry about any escaping of quotes.
open my $fh, '>', 'data.txt' or die "Cannot open file: $!";
print $fh "$Date;$String_Value\n";
close $fh;
Paul Lalli
------------------------------
Date: 28 Apr 2007 04:35:24 -0700
From: vikrant <vikrant.kansal@gmail.com>
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <1177760124.686655.177990@n59g2000hsh.googlegroups.com>
On Apr 28, 3:26 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Apr 28, 4:41 am, vikrant <vikrant.kan...@gmail.com> wrote:
>
>
>
> > Hi,
> > I facing a problem in saving a string contains single and double quote
> > into a file .The string look like the following:-
>
> > Example:-
> > Developer's community "com.lang.perl"
> > --------------------------------------------------------
> > The part of Code is:-
>
> > #!/bin/perl -w
> > use strict;
>
> > my $Date=3D"10-09-2007";
>
> > system("echo '$Date;$String_Value' > data.txt");
> > -----------------------------------------------------------------------=
----=AD-------------
> > Here,the $String_Value Variable store the string which i have
> > mentioned above.
>
> > I cannot put the slash( \ ) before the double quote's because in my
> > case value of input string is dynamic.
> > Also,I know putting a slash before double quote do not solve my
> > problem because single quote is left which will create the problem.I
> > get to know about this when i put slash before the double quote's.
>
> > The error coming on screen is:-
> > -----------------------------------------------------------------------=
----=AD---------------------
> > sh: -c: line 0: unexpected EOF while looking for matching `''
> > sh: -c: line 1: syntax error: unexpected end of file
> > -----------------------------------------------------------------------=
----=AD--------------------------
>
> > So,please tell me how do i handle this type of input.
> > I apologize if someone already asked this question earlier.
>
> Why are you calling a system command to do the echoing? Just open the
> file for writing in Perl, and print the line to the file in Perl.
> Then you don't have to worry about any escaping of quotes.
>
> open my $fh, '>', 'data.txt' or die "Cannot open file: $!";
> print $fh "$Date;$String_Value\n";
> close $fh;
>
> Paul Lalli
Thanks for the information.Actually,the code is a part of a
function,which called again and again.So,i thought that opening and
closing a file on each call may effect the performance.That was the
only reason of using the system command.
Comments are most welcome.
Thanks and Regards,
Vikrant
------------------------------
Date: 28 Apr 2007 11:45:35 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <59gqevF2k6kbdU2@mid.uni-berlin.de>
vikrant <vikrant.kansal@gmail.com> wrote:
> On Apr 28, 3:26 pm, Paul Lalli <mri...@gmail.com> wrote:
> > On Apr 28, 4:41 am, vikrant <vikrant.kan...@gmail.com> wrote:
> >
> > > system("echo '$Date;$String_Value' > data.txt");
> >
> > Why are you calling a system command to do the echoing? Just open the
> > file for writing in Perl, and print the line to the file in Perl.
> > Then you don't have to worry about any escaping of quotes.
> >
> > open my $fh, '>', 'data.txt' or die "Cannot open file: $!";
> > print $fh "$Date;$String_Value\n";
> > close $fh;
> >
> > Paul Lalli
> Thanks for the information.Actually,the code is a part of a
> function,which called again and again.So,i thought that opening and
> closing a file on each call may effect the performance.That was the
> only reason of using the system command.
Actually, your approach uses a lot more resources and time.
The system() function must create a new process, which in turn
executes a shell to deal with the command you sent to system().
And the file must be opened and closed again anyway, but now
the shell will do that. So all the system() call does is add
overhead, saving you nothing at all (beside making it harder
to check for errors).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: 28 Apr 2007 08:38:42 -0700
From: vikrant <vikrant.kansal@gmail.com>
Subject: Re: How to handling string contains single quote and double quote
Message-Id: <1177774722.027039.171110@e65g2000hsc.googlegroups.com>
On Apr 28, 4:45 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> vikrant <vikrant.kan...@gmail.com> wrote:
> > On Apr 28, 3:26 pm, Paul Lalli <mri...@gmail.com> wrote:
> > > On Apr 28, 4:41 am, vikrant <vikrant.kan...@gmail.com> wrote:
>
> > > > system("echo '$Date;$String_Value' > data.txt");
>
> > > Why are you calling a system command to do the echoing? Just open the
> > > file for writing inPerl, and print the line to the file inPerl.
> > > Then you don't have to worry about any escaping of quotes.
>
> > > open my $fh, '>', 'data.txt' or die "Cannot open file: $!";
> > > print $fh "$Date;$String_Value\n";
> > > close $fh;
>
> > > Paul Lalli
> > Thanks for the information.Actually,the code is a part of a
> > function,which called again and again.So,i thought that opening and
> > closing a file on each call may effect the performance.That was the
> > only reason of using the system command.
>
> Actually, your approach uses a lot more resources and time.
> The system() function must create a new process, which in turn
> executes a shell to deal with the command you sent to system().
> And the file must be opened and closed again anyway, but now
> the shell will do that. So all the system() call does is add
> overhead, saving you nothing at all (beside making it harder
> to check for errors).
> Regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de
Hi JensThoms,
Thanks for sharing the information.It is very helpful to me.
Regards,
Vikrant
------------------------------
Date: 28 Apr 2007 06:51:05 -0700
From: Ranjit <ranjitmaddipatla@gmail.com>
Subject: How to open and read pdf file in Perl.
Message-Id: <1177768265.777447.310590@o5g2000hsb.googlegroups.com>
Hi All,
Could any one share some information on a pdf file is beign read and
work on its data in Perl .
Thanks in Advance.
Regards,
Ranjit
------------------------------
Date: Sat, 28 Apr 2007 13:57:04 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: How to open and read pdf file in Perl.
Message-Id: <pan.2007.04.28.13.57.03.382567@PSDT.com>
On Sat, 28 Apr 2007 06:51:05 -0700, Ranjit wrote:
> Could any one share some information on a pdf file is beign read and
> work on its data in Perl .
http://search.cpan.org/~areibens/PDF-API2-0.60/lib/PDF/API2.pm
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Sat, 28 Apr 2007 16:59:21 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Memory Management
Message-Id: <J3LYh.22078$n_.15692@attbi_s21>
On 4/27/2007 10:18 PM, Shiraz wrote:
>
> I need to keep a hash of arrays in memory and keep adding things to it and
> when the hash has so many things in it that it can cause a perl out of memory
> error, i want to prune it. almost like a cache.
So whatever gets flushed from the cache can be recalculated if necessary? You
haven't said how you're filling it, but take a look at the Memoize and
Memoize::Expire modules on CPAN. They *might* do what you want.
If not, my advice is to create a class for your cache with get/set methods. When
it gets too big, start undef'ing entries. Devel::Size will give you accurate
results but be slow. If your array refs are of roughly equal size, you could use
scalar keys on the hash for a faster (but crude) estimate.
-mjc
------------------------------
Date: 28 Apr 2007 08:50:10 -0700
From: saintangelo <saint.delasi@gmail.com>
Subject: perl newbie
Message-Id: <1177775410.561984.155330@u30g2000hsc.googlegroups.com>
Hi everyone, i'm a complete newbie to perl and I need a good pdf on
perl for newbies. Thanks.
------------------------------
Date: Sat, 28 Apr 2007 16:20:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl newbie
Message-Id: <Xns99207D97254C6asu1cornelledu@127.0.0.1>
saintangelo <saint.delasi@gmail.com> wrote in news:1177775410.561984.155330
@u30g2000hsc.googlegroups.com:
> Hi everyone, i'm a complete newbie to perl and I need a good pdf on
> perl for newbies. Thanks.
Please first read the posting guidelines for this group. Then, read the FAQ
pages on learning Perl:
perldoc -q learn
http://books.perl.org/
http://learn.perl.org/
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Sat, 28 Apr 2007 16:09:38 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Rounding up to the next .5
Message-Id: <slrnf36se2.ii.justin.0704@justin-catteralls-computer.local>
Not strictly a perl problem, I'm just happen to be using perl to do
this.
I'm writing a utility for work that will calculate the price to send a
parcel. The courier charges by the half kilo and they never round down.
I'm trying to round weights (with up to two decimal places) up to the
next half kilo (unless the weight is an exact or .5 kilo already).
I've looked at the 'round' in the docs. You can round, for example, four
decimal places to three, two, one, or none, but there's no mention of
rounding, say, .3 to .5.
Things look OK with:
$weight = ( int( $kilos + .4 ) *2 ) / 2 ;
Those work until you go to two decimal places, which our scales do
(there is also something called dimensional weight - if your parcel
takes up too much space for how much it weighs, they give it a weight
appropriate for it's size and charge you that instead - we often have to
go to two decimal places).
I've got close with this:
$weight = ( int( $kilos + .455 ) * 2 ) / 2 ;
But it's not right, the first fifty grammes over the kilo/half-kilo get
rounded down.
Any suggestions on how I might tackle this?
Thank you for any help you can give.
One last thought, I could use a spreadsheet to create one huge hash,
with all the weights from .01kg up to, say, 200kg. The weights being the
keys and the values being the rounded weight... but there *has* to be a
better way... doesn't there?
Justin.
--
Justin C, by the sea.
------------------------------
Date: Sat, 28 Apr 2007 16:34:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Rounding up to the next .5
Message-Id: <AIKYh.2898$r77.978@trndny08>
Justin C wrote:
> I'm writing a utility for work that will calculate the price to send a
> parcel. The courier charges by the half kilo and they never round
> down.
>
> I'm trying to round weights (with up to two decimal places) up to the
> next half kilo (unless the weight is an exact or .5 kilo already).
I think you are making this waaaay to complicated.
For one I am pretty sure there are modules on CPAN that do floor() and
ceiling() functions.
And second there are really only three simple cases that you need to
distinguish:
if the decimal portion is 0 then the shipping weight is the actual weight
If 0 < decimal portion <= 0.5 then the shipping weight is the integer part
plus 0.5
If 0.5 < decimal portion then the shipping weight is the integer part plus 1
jue
------------------------------
Date: 28 Apr 2007 10:41:17 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Weird error after a configuration change
Message-Id: <1177782077.937821.48200@u30g2000hsc.googlegroups.com>
On Apr 28, 12:40 am, Nikos <nikos1...@gmail.com> wrote:
> referer is stil 'http://dell'although index.pl posts data to
> admin.pl....
>
> As matter of fact i tried to pritn the referrrer var in every script
> of mine called by another perl cgi script and every tiem the result
> washttp://dell why?!!
This is possibly a feature of the browser you are using. The browser
can send whtever it likes as a referer.
------------------------------
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 390
**************************************