[28514] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9878 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 22 18:05:44 2006

Date: Sun, 22 Oct 2006 15:05: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           Sun, 22 Oct 2006     Volume: 10 Number: 9878

Today's topics:
    Re: ability to match / detect acronyms ? <jwkenne@attglobal.net>
    Re: bug challenge <attn.steven.kuo@gmail.com>
        can Perl detect / match unicode characters <jack_posemsky@yahoo.com>
    Re: can Perl detect / match unicode characters <hjp-usenet2@hjp.at>
        command to substitute x with y, but only x alone <bootiack@yahoo.com>
    Re: command to substitute x with y, but only x alone <john@castleamber.com>
    Re: command to substitute x with y, but only x alone <xicheng@gmail.com>
    Re: command to substitute x with y, but only x alone <bik.mido@tiscalinet.it>
    Re: comparing 2 arrays strings when the number/name of  <nobull67@gmail.com>
    Re: Is this the correct place to ask for help if I am n <DJStunks@gmail.com>
    Re: Is this the correct place to ask for help if I am n <bik.mido@tiscalinet.it>
        LWP and Javascript -- Not The Same Old Question <sorry_no_email@yahoo.com>
    Re: LWP and Javascript -- Not The Same Old Question <hjp-usenet2@hjp.at>
    Re: need help for text substitution using Perl <nobull67@gmail.com>
    Re: Reverse algorithm with tangent <nospam-abuse@ilyaz.org>
        string substitution for a file, without replacing parti <bootiack@yahoo.com>
    Re: string substitution for a file, without replacing p anno4000@radom.zrz.tu-berlin.de
    Re: string substitution for a file, without replacing p <bootiack@yahoo.com>
    Re: string substitution for a file, without replacing p <xicheng@gmail.com>
    Re: string substitution for a file, without replacing p anno4000@radom.zrz.tu-berlin.de
    Re: string substitution for a file, without replacing p <bik.mido@tiscalinet.it>
        Trying to get past code error in Perl book I'm learning <rankenory@gmail.com>
    Re: Trying to get past code error in Perl book I'm lear anno4000@radom.zrz.tu-berlin.de
    Re: Trying to get past code error in Perl book I'm lear <john@castleamber.com>
    Re: Trying to get past code error in Perl book I'm lear <wahab@chemie.uni-halle.de>
    Re: Trying to get past code error in Perl book I'm lear <bik.mido@tiscalinet.it>
        Use system to start a server then execute commands on i <reggieband@googlemail.com>
    Re: Use system to start a server then execute commands  <sherm@Sherm-Pendleys-Computer.local>
    Re: Use system to start a server then execute commands  <reggieband@googlemail.com>
    Re: Use system to start a server then execute commands  <nobull67@gmail.com>
    Re: Use system to start a server then execute commands  <reggieband@googlemail.com>
    Re: Use system to start a server then execute commands  <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 22 Oct 2006 12:04:43 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: ability to match / detect acronyms ?
Message-Id: <MEM_g.34$8h1.4@newsfe12.lga>

anno4000@radom.zrz.tu-berlin.de wrote:
> Jack <jack_posemsky@yahoo.com> wrote in comp.lang.perl.misc:
>> Jack wrote:
>>> Hi I was wondering if anyone had any code to detect / match / identify
>>> acronyms (AAA, BD) , essentially these are non words..besides just
>>> detecting the capitals of course.
> 
> Some acronyms are words,

All acronyms are words, by definition.

-- 
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
   -- Charles Williams.  "Taliessin through Logres: Prelude"


------------------------------

Date: 22 Oct 2006 10:38:52 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: bug challenge
Message-Id: <1161538732.187520.77220@e3g2000cwe.googlegroups.com>

Uri Guttman wrote:
> a primary user of template::simple found a nasty bug in version .01. it
> took me several hours of hard work in one evening and then i was able to
> find and fix it the next morning when my brain was clear again. so my
> challenge to you is to figure out this bug.


(snipped)


> here is a driver script that demonstrates the bug.
>
> #!/usr/local/bin/perl
>
> use warnings ;
> use strict ;
>
> use Template::Simple ;
>
> my $data = {
> 	widgets => [
> 		{
> 			title => "bart",
> 		},
> 		{
> 			title => "marge",
> 		}
> 	],
> } ;
>
> my $template = <<TMPL ;
> [%start widgets%][%title%][%foo%]         [%end widgets%]
> TMPL
>
> my $renderer = Template::Simple->new() ;
>
> my $text = $renderer->render( $template, $data ) ;
>
> print ${$text} ;
>
> and here is the output i get:
>
> -------cut--------------
> Use of uninitialized value in substitution (s///) at /usr/local/lib/perl5/site_perl/5.8.6/Template/Simple.pm line 186.
> Use of uninitialized value in substitution (s///) at /usr/local/lib/perl5/site_perl/5.8.6/Template/Simple.pm line 196.
> Use of uninitialized value in concatenation (.) or string at /usr/local/lib/perl5/site_perl/5.8.6/Template/Simple.pm line 216.
> bart
> -------cut--------------
> those warnings shouldn't be there and there should be both bart and
> marge in the output.
>
> perl -v is
> This is perl, v5.8.6 built for sun4-solaris
>
> the module code is very short, elegant and tight and if you don't grok
> recursion with dispatch tables, don't go near this. or take this
> challenge and prove me a big fool by finding the bug fix in 5 minutes.
>
> have the appropriate amount of fun. flames are welcome and will be
> ignored.
>
> uri


As a matter of habit I never pass around
references to $1, $2 variables.  So this part of the module
looked a bit funny to me:

sub _render_hash {

# ...

	$rendered =~ s{$self->{chunk_re}}
		      {
			# print "CHUNK $1\nBODY\n----\n<$2>\n\n------\n" ;
			${$self->_render_chunk( \$2, $href->{$1} ) }}gex ;



I took a quick shot in the dark and changed it
to use a copy of $2:


	$rendered =~ s{$self->{chunk_re}}
		      {
			# print "CHUNK $1\nBODY\n----\n<$2>\n\n------\n" ;
			${$self->_render_chunk( \"$2", $href->{$1} ) }}gex ;


(with quotes around $2), The warnings go
away and I get "bart" and "marge" in the output.  The existing
regression tests all pass as well.

I haven't looked into the "bonus question" yet.

-- 
Regards,
Steven



------------------------------

Date: 22 Oct 2006 10:54:07 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: can Perl detect / match unicode characters
Message-Id: <1161539647.739290.129220@e3g2000cwe.googlegroups.com>

Hi I have some data that has unicode characters that I want to parse
out and remove since its throwing off regex, does anyone know how to
detect these ?



------------------------------

Date: Sun, 22 Oct 2006 21:16:05 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: can Perl detect / match unicode characters
Message-Id: <slrnejngrl.ic6.hjp-usenet2@yoyo.hjp.at>

On 2006-10-22 17:54, Jack <jack_posemsky@yahoo.com> wrote:
> Hi I have some data that has unicode characters that I want to parse
> out and remove since its throwing off regex, does anyone know how to
> detect these ?

If you tell us what you mean by "unicode characters" (I can think of at
least 3 different definitions which would make some sense in that
context) and how they "throw off" your regexes, we can probably help
you.

Post a short, but complete (i.e. runnable) script which demonstrates the
problem, then we have something concrete to talk about.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: 22 Oct 2006 12:12:02 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: command to substitute x with y, but only x alone
Message-Id: <1161544322.172036.125450@i42g2000cwa.googlegroups.com>

I have text file with 6,000 instances of 50 I want to chagne to 450

I do not want 250 to become 2450

what complete perl command do I issue at the command line to do this?



------------------------------

Date: 22 Oct 2006 19:40:39 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: command to substitute x with y, but only x alone
Message-Id: <Xns9864954EC162Acastleamber@130.133.1.4>

"gavino" <bootiack@yahoo.com> wrote:

> I have text file with 6,000 instances of 50 I want to chagne to 450
> 
> I do not want 250 to become 2450
> 
> what complete perl command do I issue at the command line to do this?

Use a text editor with search and replace, search for

 50

and replace it with

 450

with spaces to the left and the right. If you want "us" to post a complete 
working solution you probably have picked the wrong language and/or group.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


------------------------------

Date: 22 Oct 2006 13:03:49 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: command to substitute x with y, but only x alone
Message-Id: <1161547429.600518.302060@f16g2000cwb.googlegroups.com>

gavino wrote:
> I have text file with 6,000 instances of 50 I want to chagne to 450
>
> I do not want 250 to become 2450
>
> what complete perl command do I issue at the command line to do this?

you can either use word-boundary anchor \b, like

  s/\b50\b/450/g;

or if you dont want 'A50' to become 'A450', then

  s/(?<=\D)50(?=\D)/450/g;   

Xicheng



------------------------------

Date: 22 Oct 2006 23:10:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: command to substitute x with y, but only x alone
Message-Id: <2ennj21g1jikfg692pevmdbpgumvq4vn66@4ax.com>

On 22 Oct 2006 12:12:02 -0700, "gavino" <bootiack@yahoo.com> wrote:

>I have text file with 6,000 instances of 50 I want to chagne to 450

Reposting the same question with a chagned subject is not going to
help you.

>I do not want 250 to become 2450

Reposting the same question with a chagned subject is not going to
help you.

>what complete perl command do I issue at the command line to do this?

Reposting the same question with a chagned subject is not going to
help you.

How did the correct suggestion Anno gave you in the other thread
fail?!?


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: 22 Oct 2006 06:05:31 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: comparing 2 arrays strings when the number/name of arrays is dynamic
Message-Id: <1161522331.078966.131820@k70g2000cwa.googlegroups.com>


anno4000@radom.zrz.tu-berlin.de wrote:
> Jack <jack_posemsky@yahoo.com> wrote in comp.lang.perl.misc:
> > Hello,
> >
> > I was wondering if anyone knows how to get around the problem of a perl
> > array intersection with more than 1 array where the number of arrays,
> > and there names, can be variable... I have noticed that the code below
> > and also List::Compare pmm do not allow one to dynamically at run time
> > build a string for the arrays that need intersecting...  does anyone
> > know how to get around this ?
>
> What would it mean to "build a string for the arrays"?

I'm 85% sure he means "build a list of references to the arrays".



------------------------------

Date: 22 Oct 2006 08:52:15 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Is this the correct place to ask for help if I am new to Perl?
Message-Id: <1161532335.735589.7200@m73g2000cwd.googlegroups.com>

Iridius wrote:
> Hi, I am new to Perl (but know PHP). I am having a difficult time in my
> class, because 1) this is my instructor's first time teaching 2) he
> barely speaks english and 3) his teach method isn't very helpful.
>
> If I had more time I could probably sit down and read Perl books end to
> end, but I really do need some more immediate help.
>
> If anyone is willing to assist me with a pretty simple script, I would
> be most appreciative.

for very simple Perl questions I would recommend perl.beginners over
comp.lang.perl.misc.  At perl.beginners people are generally more
patient and more likely to put up with poor posting technique (at least
for a few posts) than they are here.

This is a much better place to post for more detailed/complex problems.

HTH,
-jp



------------------------------

Date: 22 Oct 2006 19:27:52 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Is this the correct place to ask for help if I am new to Perl?
Message-Id: <gfanj2pee9pd46ma7pito3f18l22n4clmi@4ax.com>

On 21 Oct 2006 22:44:02 -0700, "Iridius" <iridius@gmail.com> wrote:

>Hi, I am new to Perl (but know PHP). I am having a difficult time in my

Also: <http://perlmonks.org/?node_id=579876>!!


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: 22 Oct 2006 08:37:48 -0700
From: "EdwardATeller" <sorry_no_email@yahoo.com>
Subject: LWP and Javascript -- Not The Same Old Question
Message-Id: <1161531468.244303.284630@m73g2000cwd.googlegroups.com>

I am trying to scrape a page that seems to load important info via
javascript, since it isn't there when I just use LWP get.  When I visit
the page with Firefox with javascript turned off, the important info is
right there on my screen, although a litle garbled.  I'm guessing the
page detects javascript and serves accordingly.

Here is my thought.  Can I create a useragent that grabs pages after
telling the webserver it doesn't support javascript?  That way, I'll
get the same page that is served to my javascript-less Firefox browser
that contains the information I want to scrape.

Sorry if this question isn't well-formed, but I am just a old Fortran
programmer trying to make his way in this new-fangled web world.



------------------------------

Date: Sun, 22 Oct 2006 21:02:37 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: LWP and Javascript -- Not The Same Old Question
Message-Id: <slrnejng2d.ic6.hjp-usenet2@yoyo.hjp.at>

On 2006-10-22 15:37, EdwardATeller <sorry_no_email@yahoo.com> wrote:
> I am trying to scrape a page that seems to load important info via
> javascript, since it isn't there when I just use LWP get.  When I visit
> the page with Firefox with javascript turned off, the important info is
> right there on my screen, although a litle garbled.  I'm guessing the
> page detects javascript and serves accordingly.
>
> Here is my thought.  Can I create a useragent that grabs pages after
> telling the webserver it doesn't support javascript?

Not directly, no. There is no way for the browser to tell the server
that it doesn't support JavaScript. A server can detect whether the
browser supports JavaScript by serving a page which contains some
JavaScript which does something that the server can observe (e.g., set a
cookie). However, there should be no difference between LWP and Firefox
with JavaScript disabled in this respect.

Some things you can try:

* Bookmark the page in FF, delete all cookies, delete the cache, load
  the page from bookmarks - does it still contain the information?

* If it doesn't, there is probably some session-context which you need
  to recreate - try to find out what it is.

* If it does, check what other differences there are between a request
  from Firefox and LWP: Find out which of them causes a problem. Likely
  candidates are the User-Agent, Accept and Accept-Language headers.

* If you are using http (not https) it is a good idea to record the
  traffic of your experiments with tcpdump. That way you know what was
  actually transmitted over the network - which may not be the same as
  what you see in the browser. It also serves as a log - you can always
  check if you already tried something and whether it worked or not.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: 22 Oct 2006 09:33:06 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: need help for text substitution using Perl
Message-Id: <1161534786.514746.166610@b28g2000cwb.googlegroups.com>

Jerry wrote:

> (First, sorry for cross-posting, I'm just afraid that I might not get
> an answer on "perl beginners" group)

Please find out the difference between cross-posting and multi-posting.
It is important if you wish to avoid appearing selfish and arrogant.


> Any input (and your time) is greatly appreciated.

It doesn't feel that way. I put effort into helping you in one forum
just to find you've already been given the same help elsewhere. This
does not make me feel "greatly appreciated".



------------------------------

Date: Sun, 22 Oct 2006 20:54:30 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Reverse algorithm with tangent
Message-Id: <ehglq6$2sgv$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Bart Van der Donck
<bart@nijlen.com>], who wrote in article <1161504863.557160.248870@e3g2000cwe.googlegroups.com>:
> > Essentially, what it means in this example is that there is no "loss
> > of precision"; given 39 digits after the point in the encrypted value,
> > you should expect to completely restore 39 digits after the poinit in
> > the decrypted value.  All you need is doing calculation with high
> > enough precision, so the errors do not accumulate.

> > So do the calcs in some higher-precision-math Perl module.

> I've a feeling that this must be the core of the problem, yes. I just
> hope it's possible to perform such hi-res calculations in the first
> place.

No NEED to.  Alternatively, since you know the approximate answer, it
is easy to increase its precision by binary search.  Your function is
monotonic, after all (on small intervals)...

Yours,
Ilya

P.S.  Answering some other post: tan() IS injective on the intervals
      in question; but the FP approximation is not injective.

      E.g., near 0 tan(x) behaves very similar to (1+eps)*x for a very
      small eps.  So an interval of length delta is mapped to an
      interval practically the same length.

      Take such an interval near AND BELOW 2**(-n) so that tan(x) is
      near AND ABOVE 2**(-n).  We get a mapping which sends an
      interval of length delta to an interval of length (1+eps)delta;
      but the latter interval contains approx. 1/2 of the number of
      exactly representable floating point values of the former
      interval.



------------------------------

Date: 22 Oct 2006 10:24:46 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: string substitution for a file, without replacing partial string?
Message-Id: <1161537886.265514.33900@e3g2000cwe.googlegroups.com>

I have a file 50.txt and want to replace each 50 by itself with 450.
I do not want 250 to become 2450 for example.
What perl expression does this?
perl -pi.bak -e 's/\b50\b/450/g' 50.txt                          #
fails!
activeperl on win xp



------------------------------

Date: 22 Oct 2006 17:49:44 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <4q1p9oFl8jijU1@news.dfncis.de>

gavino <bootiack@yahoo.com> wrote in comp.lang.perl.misc:
> I have a file 50.txt and want to replace each 50 by itself with 450.
> I do not want 250 to become 2450 for example.
> What perl expression does this?
> perl -pi.bak -e 's/\b50\b/450/g' 50.txt                          #
> fails!

Sure, wrong tool.  "\b" is a *word* boundary, unfit to delimit numbers.
A better way is to forbid digits left and right of the "50":

    s/(?<!\d)50(?!\d)/450/g;

That may need refinement, depending on what you consider a number.
Should "-50" be replaced with "-450"?

Anno


------------------------------

Date: 22 Oct 2006 11:35:34 -0700
From: "gavino" <bootiack@yahoo.com>
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <1161542134.441921.244130@m73g2000cwd.googlegroups.com>

Didn't work
what would the complete command from command line be?



------------------------------

Date: 22 Oct 2006 13:09:54 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <1161547794.004893.316650@m7g2000cwm.googlegroups.com>

gavino wrote:
> Didn't work
> what would the complete command from command line be?

err, you asked the same question twice.

If you were using ActivePerl under Windows, you should use double
quotes instead of single quotes to enclose Perl commands..

   perl -pi.bak -e "s/\b50\b/450/g" 50.txt

Xicheng



------------------------------

Date: 22 Oct 2006 20:52:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <4q2400Fl66k4U1@news.dfncis.de>

gavino <bootiack@yahoo.com> wrote in comp.lang.perl.misc:

> Didn't work

That's a pretty rude reply to a helpful message, don't you think?
Not to mention the lack of any context.

My code does work as explained.

> what would the complete command from command line be?

Find that out yourself.

Anno


------------------------------

Date: 22 Oct 2006 23:08:47 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: string substitution for a file, without replacing partial string?
Message-Id: <acnnj21003irbga8kc74i7i3bl4p1ti4eg@4ax.com>

On 22 Oct 2006 11:35:34 -0700, "gavino" <bootiack@yahoo.com> wrote:

>Didn't work

Didn't quote relevant context

>what would the complete command from command line be?

What would be the complete description of how it failed to work?


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: 22 Oct 2006 10:08:21 -0700
From: "rankenory@gmail.com" <rankenory@gmail.com>
Subject: Trying to get past code error in Perl book I'm learning from
Message-Id: <1161536901.711417.33800@m7g2000cwm.googlegroups.com>

I'm learning Perl from a book called "Learn Perl in a Weekend."  I like
the book a lot as far as how it is structured, but there are errata,
and no online errata page to resolve them.

In the book (pp. 45-46) the author erroneously demonstrates code to
convert a number to a percentage (author's comment lines included):
--------------------------------------------------------------------------------
# Assign a floating point number to the scalar $number
$number = 1.1111;
# Print $number
print "$number\n";
# Change to a percentage
print sprintf "%%f\n", $number;
--------------------------------------------------------------------------------
The resulting output is:
1.1111
%f

Well, obviously %f is wrong.  I tried removing the "f" but then the
result using the %% function was the % sign alone (with no number,
despite the fact that it precedes the $number).  So I played around
with this a while (remember, I'm new to this), and figured out that I
could make the number look like a percentage.  1.1111 becomes 111.11%
if multiplied by 100, so I created a variable to do that, and then
attached the % sign after it (using %%):
------------------------------------------------------------------------------
# Assign a floating point number to the scalar $number
$number = 1.1111;
# Multiply it by 100 to convert to percent
$numberX100 = $number * 100;
# Print $number
print "$number\n";
# Change to a percentage and move to next line
print $numberX100, sprintf "%%\n";
------------------------------------------------------------------------------
Yes, this did make the 1.1111 look like 111.11%, but since the author
displayed a sprintf function for it, that leads me to believe there is
a shortcut method.  Is there?  If so, what would be the correct format
for it?

Thanks



------------------------------

Date: 22 Oct 2006 17:34:38 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Trying to get past code error in Perl book I'm learning from
Message-Id: <4q1odeFksruhU1@news.dfncis.de>

rankenory@gmail.com <rankenory@gmail.com> wrote in comp.lang.perl.misc:
> I'm learning Perl from a book called "Learn Perl in a Weekend."  I like
> the book a lot as far as how it is structured, but there are errata,
> and no online errata page to resolve them.
> 
> In the book (pp. 45-46) the author erroneously demonstrates code to
> convert a number to a percentage (author's comment lines included):
> --------------------------------------------------------------------------------
> # Assign a floating point number to the scalar $number
> $number = 1.1111;
> # Print $number
> print "$number\n";
> # Change to a percentage
> print sprintf "%%f\n", $number;

If that's a literal quote, The author doesn't know enough Perl to write
decent code.  Cut your losses and throw the book away .

Whatever the purpose of the botched format, "print sprintf" should
definitely be "printf".

> --------------------------------------------------------------------------------
> The resulting output is:
> 1.1111
> %f
> 
> Well, obviously %f is wrong.  I tried removing the "f" but then the
> result using the %% function was the % sign alone (with no number,
> despite the fact that it precedes the $number).

Right.  "%%" prints a single percent sign and does nothing else.
See "perldoc -f sprintf".

> So I played around
> with this a while (remember, I'm new to this), and figured out that I
> could make the number look like a percentage.  1.1111 becomes 111.11%
> if multiplied by 100, so I created a variable to do that, and then
> attached the % sign after it (using %%):
> ------------------------------------------------------------------------------
> # Assign a floating point number to the scalar $number
> $number = 1.1111;
> # Multiply it by 100 to convert to percent
> $numberX100 = $number * 100;
> # Print $number
> print "$number\n";
> # Change to a percentage and move to next line
> print $numberX100, sprintf "%%\n";
> ------------------------------------------------------------------------------
> Yes, this did make the 1.1111 look like 111.11%, but since the author
> displayed a sprintf function for it, that leads me to believe there is
> a shortcut method.  Is there?  If so, what would be the correct format
> for it?

    printf "%.2f%%\n", 100*$number;

No shortcut, every step is there (but unnecessary steps left out).
It limits the decimal places of the percentage to 2.

Anno


------------------------------

Date: 22 Oct 2006 17:41:58 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Trying to get past code error in Perl book I'm learning from
Message-Id: <Xns9864812FBDFC9castleamber@130.133.1.4>

"rankenory@gmail.com" <rankenory@gmail.com> wrote:

> I'm learning Perl from a book called "Learn Perl in a Weekend."

I am sorry for you. Throw that piece of junk out of the window and get a 
good book. Books like learn xxx in yyy are a waste of more then yyy time 
sadly.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


------------------------------

Date: Sun, 22 Oct 2006 20:42:22 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Trying to get past code error in Perl book I'm learning from
Message-Id: <ehgeb5$ft6$1@mlucom4.urz.uni-halle.de>

Thus spoke rankenory@gmail.com (on 2006-10-22 19:08):

> I'm learning Perl from a book called "Learn Perl in a Weekend."  

Look at the customer reviews:

http://www.amazon.com/Learn-Perl-Weekend-Indianapolis-Ind/dp/1931841772

Regards

M.



------------------------------

Date: 22 Oct 2006 23:07:03 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Trying to get past code error in Perl book I'm learning from
Message-Id: <k5nnj2pfub73meeaq1b8rl758iujr0hk6d@4ax.com>

On 22 Oct 2006 10:08:21 -0700, "rankenory@gmail.com"
<rankenory@gmail.com> wrote:

>I'm learning Perl from a book called "Learn Perl in a Weekend."  I like

: And:  Every book which has a title that promises you to learn something in
: x weeks, day or even hours is lying.
: - Tore Aursand in clpmisc, "Re: wow...jackpot."

(now a .sig of mine!)


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: 22 Oct 2006 06:38:25 -0700
From: "James Fassett" <reggieband@googlemail.com>
Subject: Use system to start a server then execute commands on it
Message-Id: <1161524305.716433.230190@k70g2000cwa.googlegroups.com>

Hi,

I have a script set up that allows me to execute a seperate process
(start a perfoce server) and then call against it.

e.g.

system( "cmd to start perforce server &" );
 ... sometime later within the same script ...
`some cmd on perforce server`;

The problem is `some cmd` reacts as if the original system call had not
been made (i.e. as if perforce is not running).  If I run a seperate
terminal and sleep between the calls I can see that the perforce server
has been properly started and I can call commands on the server;
however once the sleep expires `some cmd` still fails.   `some cmd`
works as expected if the perforce server has been started externally to
the script (as in subsequent runs)

I have searched docs, tried fork (which didn't do what I wanted) and
I'm a bit stuck.
Any help appreciated.

Thanks,
James.



------------------------------

Date: Sun, 22 Oct 2006 10:55:00 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Use system to start a server then execute commands on it
Message-Id: <m2ods4mmd7.fsf@Sherm-Pendleys-Computer.local>

"James Fassett" <reggieband@googlemail.com> writes:

> system( "cmd to start perforce server &" );
>  ... sometime later within the same script ...
> `some cmd on perforce server`;
>
> The problem is `some cmd` reacts as if the original system call had not
> been made (i.e. as if perforce is not running).  If I run a seperate
> terminal and sleep between the calls I can see that the perforce server
> has been properly started and I can call commands on the server;
> however once the sleep expires `some cmd` still fails.   `some cmd`
> works as expected if the perforce server has been started externally to
> the script (as in subsequent runs)
>
> I have searched docs, tried fork (which didn't do what I wanted) and
> I'm a bit stuck.
> Any help appreciated.

Why ask thousands of people for random guesses, when Perl *knows* what the
problem was?

     if ($? == -1) {
        print "failed to execute: $!\n";
     }
     elsif ($? & 127) {
        printf "child died with signal %d, %s coredump\n",
        ($? & 127),  ($? & 128) ? 'with' : 'without';
     }
     else {
        printf "child exited with value %d\n", $? >> 8;
     }

Funny, how you "searched" the docs, and still managed to miss the example
code that's given in the docs for the very function you're having trouble
with.

     perldoc-f system

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: 22 Oct 2006 08:24:48 -0700
From: "James Fassett" <reggieband@googlemail.com>
Subject: Re: Use system to start a server then execute commands on it
Message-Id: <1161530688.163680.244390@m73g2000cwd.googlegroups.com>


Sherm Pendley wrote:
> > system( "cmd to start perforce server &" );
> >  ... sometime later within the same script ...
> > `some cmd on perforce server`;
> >
> > The problem is `some cmd` reacts as if the original system call had not
> > been made (i.e. as if perforce is not running).

> Why ask thousands of people for random guesses, when Perl *knows* what the
> problem was?
>
>      if ($? == -1) {
>         print "failed to execute: $!\n";
>      }
>      elsif ($? & 127) {
>         printf "child died with signal %d, %s coredump\n",
>         ($? & 127),  ($? & 128) ? 'with' : 'without';
>      }
>      else {
>         printf "child exited with value %d\n", $? >> 8;
>      }
>
> Funny, how you "searched" the docs, and still managed to miss the example
> code that's given in the docs for the very function you're having trouble
> with.

Hi sherm, thanks for the reply

The call to system does not fail - the perforce server does indeed
correctly start (I can see it running and execute commands on it from a
second terminal).  However, any commands I'd like to run on the sever
from within the script react as if the server isn't started.

printf "exit value: %d | signal: %d | core: %d\n", $? >> 8, $? & 127,
$? & 128;
after the failed system call, I get an exit code that suggests perforce
isn't running when I know it is.

Hope this clarifies the question.

James.



------------------------------

Date: 22 Oct 2006 09:02:03 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Use system to start a server then execute commands on it
Message-Id: <1161532923.666304.43240@k70g2000cwa.googlegroups.com>


James Fassett wrote:
> Hi,
>
> I have a script set up that allows me to execute a seperate process
> (start a perfoce server) and then call against it.
>
> e.g.
>
> system( "cmd to start perforce server &" );
>  ... sometime later within the same script ...
> `some cmd on perforce server`;
>
> The problem is `some cmd` reacts as if the original system call had not
> been made (i.e. as if perforce is not running).  If I run a seperate
> terminal and sleep between the calls I can see that the perforce server
> has been properly started and I can call commands on the server;
> however once the sleep expires `some cmd` still fails.

Even if we are not going to be able to reproduce your problem reliably
without a perforce server (whatever that is) you should still follow
SOP and produce a _minimal_ but _complete_ script that you have run and
observed to produce the symtoms. You should then _show_ us the symptoms
rather than describe them.

Make sure your test script has the sleep() in it, without it there's a
obvious explaination of the failure, i.e. the server process hasn't had
time to reach the point where it's accepting connections.



------------------------------

Date: 22 Oct 2006 09:32:37 -0700
From: "James Fassett" <reggieband@googlemail.com>
Subject: Re: Use system to start a server then execute commands on it
Message-Id: <1161534757.917012.21380@h48g2000cwc.googlegroups.com>

Brian McCauley wrote:
> Even if we are not going to be able to reproduce your problem reliably
> without a perforce server (whatever that is) you should still follow
> SOP and produce a _minimal_ but _complete_ script that you have run and
> observed to produce the symtoms. You should then _show_ us the symptoms
> rather than describe them.

Fair enough Brian - however I can't think of an easy test case that
involves starting a server process that everyone would have installed
(I'm on Mac OSX).  I had assumed this was a simple problem and I would
get sent to an appropriate FAQ (i.e. I hadn't phrased my perldoc
queries correctly).

> Make sure your test script has the sleep() in it, without it there's a
> obvious explaination of the failure, i.e. the server process hasn't had
> time to reach the point where it's accepting connections.

My first test (before posting) was to sleep for 100 seconds and try and
execute commands on the server process external to the script (the
exact same command FWIW).  While the script sleeps I can access the
perforce (a source control system) process it spawns but when the
script awakes it cannot.

Perhaps a fair question is - is this the type of thing people do all
the time and it usually just works? ('This' being start a server
process from within a script and within the same script execute
commands on that server process)

thank you for your patience,
James.



------------------------------

Date: 22 Oct 2006 20:48:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Use system to start a server then execute commands on it
Message-Id: <h9enj213bdb13jflnk4hvnbhuipj48hhku@4ax.com>

On 22 Oct 2006 09:32:37 -0700, "James Fassett"
<reggieband@googlemail.com> wrote:

>> Even if we are not going to be able to reproduce your problem reliably
>> without a perforce server (whatever that is) you should still follow
>> SOP and produce a _minimal_ but _complete_ script that you have run and
>> observed to produce the symtoms. You should then _show_ us the symptoms
>> rather than describe them.
[snip]
>Fair enough Brian - however I can't think of an easy test case that
>involves starting a server process that everyone would have installed
>(I'm on Mac OSX).  I had assumed this was a simple problem and I would

That's not what he asked you. Just prepare a "_minimal_ but _complete_
script" that *does* exhibit the problem, even if it has calls to
perforce (and thus we cannot run it). This will help us to understand
what's going on.

In other words, extracting some "code" from your first post: does a
full test script like

  #!/usr/bin/perl
  
  use strict;
  use warnings;
  
  if (my $s=system "cmd to start perforce server &") {
      die "Couldn't start perforce server:",
        ($s == -1 ? $! : $?), "\n";
  }
  sleep 60;
  my $stuff=qx/some cmd on perforce server/;
  
  __END__

(or some suitable modification of it) have the problem you're
describing?


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: 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 V10 Issue 9878
***************************************


home help back first fref pref prev next nref lref last post