[8829] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2447 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 28 19:04:20 1998

Date: Tue, 28 Apr 98 16:01:37 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 28 Apr 1998     Volume: 8 Number: 2447

Today's topics:
    Re: Please suggest: perlfaq4 example does not work <dcameron@nospam.bcs.org.uk>
    Re: Please suggest: perlfaq4 example does not work <uri@sysarch.com>
    Re: Please suggest: perlfaq4 example does not work <rootbeer@teleport.com>
    Re: Please suggest: perlfaq4 example does not work <rpandey@geocities.com>
    Re: Please suggest: perlfaq4 example does not work <danboo@negia.net>
    Re: Problem when terminating process started by system( (Jonathan Stowe)
        Question about Pattern Matching <joshi@ee.tamu.edu>
    Re: rename funciton (was: Re: Dummie question) (Abigail)
    Re: Signal Trapping .. (Jonathan Stowe)
    Re: Splitting a variable ??? <terjekv@ifi.uio.no>
        what is wrong with this code ? indhiraa@hotmail.com
    Re: where are the examples in the newer (blue) camel bo <jsd@gamespot.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 28 Apr 1998 21:08:55 GMT
From: "Duncan Cameron" <dcameron@nospam.bcs.org.uk>
Subject: Re: Please suggest: perlfaq4 example does not work
Message-Id: <01bd72e9$dfac4f40$6f3763c3@dns.btinternet.com>

Rahul

In what way does it not work for you?  It seems fine for me, gives 4
negative numbers.

Rahul Pandey <rpandey@geocities.com> wrote in article
<35463F9E.354FEEB3@geocities.com>...
> Hi,
> 
> The example in perlfaq4 (How can I count the number of occurrences of a
> substring within a string?) at:

<snip> 
>     $string = "-9 55 48 -2 23 -76 4 14 -44";
>     while ($string =~ /-\d+/g) { $count++ }
>     print "There are $count negative numbers in the string";
> 
> does not work for me.
> 
> Though I know that there is alway a better way to do it, at present the
<snip> 
> Suggestions please?
> 
> thanks,
> rahul
> 
> 


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

Date: 28 Apr 1998 17:35:29 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Please suggest: perlfaq4 example does not work
Message-Id: <x790opd3z2.fsf@sysarch.com>

>>>>> "RP" == Rahul Pandey <rpandey@geocities.com> writes:

  RP> Hi, The example in perlfaq4 (How can I count the number of
  RP> occurrences of a substring within a string?) at:

  RP> http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/How_can_I_count_the_number_of_oc.html

  RP>     $string = "-9 55 48 -2 23 -76 4 14 -44";
  RP>     while ($string =~ /-\d+/g) { $count++ }
  RP>     print "There are $count negative numbers in the string";

i got:
There are 4 negative numbers in the string

works fine for me. try adding a \n to the print string so the output
can be read.

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----  8 Years of Perl Experience, Available Immediately
uri@sysarch.com  ---------  Resume and Perl Example at http://www.sysarch.com
Use the Best Search Engine on the Net  --------  http://www.northernlight.com


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

Date: Tue, 28 Apr 1998 21:38:49 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Rahul Pandey <rpandey@geocities.com>
Subject: Re: Please suggest: perlfaq4 example does not work
Message-Id: <Pine.GSO.3.96.980428140547.15049u-100000@user2.teleport.com>

On Tue, 28 Apr 1998, Rahul Pandey wrote:

> The example in perlfaq4 (How can I count the number of occurrences of a
> substring within a string?) at:
> 
> http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/How_can_I_count_the_number_of_oc.html
> 
>     $string = "-9 55 48 -2 23 -76 4 14 -44";
>     while ($string =~ /-\d+/g) { $count++ }
>     print "There are $count negative numbers in the string";
> 
> does not work for me.

In what way does it not work? Does it fail the syntax check? Does it print
a diagnostic message? Is the message listed in the perldiag manpage? Does
your code fail to compile? Does it run out of memory?  Does it run out of
disk space? Does it dump core? Does it compile but fail to run? Does it
run but fail to print a message? Does it print a message but fail to print
the right message? Does it print the right message but fail to print the
correct number? Does it print the correct number but fail to stop
printing? Does it print the correct message but fail to stop running? Does
perl complain that it can't find the script? Does your shell complain that
you've given it a Perl script to run? Does your program's output run into
your shell prompt? Is it asleep, or just pining for the fjords? Do you
wish it also told you the number of positive numbers? Do you wish it
worked on numbers like -.5? Do you wish it didn't count -0? Do you wish it
didn't count 1.23e-10? Do you wish it initialized $count? Do you wish it
used local or lexical variables? Do you wish it printed the string? Does
it let the magic smoke out of your computer chips? Does it run correctly
from the shell but fail when run by a web browser? When it doesn't work,
does it apply for benefits at the unemployment office? Does it march in
front of the building, chanting catchy slogans and holding signs saying
"Rahul is Unfair to Perl Code"? 

It would be helpful if you could be just a little more specific about the
way in which your code does not work. :-)  But it's my guess that you made
some small error in entering the code, or in submitting it to perl. If
that's not it, then try asking again. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/




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

Date: Tue, 28 Apr 1998 14:37:14 -0700
From: Rahul Pandey <rpandey@geocities.com>
Subject: Re: Please suggest: perlfaq4 example does not work
Message-Id: <35464C0A.621AEBEF@geocities.com>

I found one more way to do it, i.e. using grep function:

    my $string = "-9 55 48 -2 23 -76 4 14 -44";
    my @modstr = split(/ /, $string);
    my $count = grep(/-\d+/, @modstr);
    print "There are $count negative numbers in the string";

But here also, I need to first convert the string into an array. Luckily, I know the separator
between the substrings in the original string to construct the @modstr. If the original string was
something like:

my $string = "firstNegative     numberIs-9 secondNegativeNumber  Is-2";

Then this solution would not have worked.

Rahul Pandey wrote:

> Hi,
>
> The example in perlfaq4 (How can I count the number of occurrences of a substring within a string?)
> at:
>
> http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/How_can_I_count_the_number_of_oc.html
>
>     $string = "-9 55 48 -2 23 -76 4 14 -44";
>     while ($string =~ /-\d+/g) { $count++ }
>     print "There are $count negative numbers in the string";
>
> does not work for me.
>
> Though I know that there is alway a better way to do it, at present the
> only way I see to get it working is:
>
>     my $string = "-9 55 48 -2 23 -76 4 14 -44";
>     my @modstr = split(/ /, $string);
>     my $num;
>     my $count = 0;
>     foreach $num (@modstr) {
>         if ($num =~ /-\d+/) {
>             $count++;
>         }
>     }
>     print "count = $count\n";
>
> Suggestions please?
>
> thanks,
> rahul





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

Date: Tue, 28 Apr 1998 17:18:21 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Please suggest: perlfaq4 example does not work
Message-Id: <3546479D.F7543C36@negia.net>

Rahul Pandey wrote:
> 
> Hi,
> 
> The example in perlfaq4 (How can I count the number of occurrences of a
> substring within a string?) at:
> 
> http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/How_can_I_count_the_number_of_oc.html
> 
>     $string = "-9 55 48 -2 23 -76 4 14 -44";
>     while ($string =~ /-\d+/g) { $count++ }
>     print "There are $count negative numbers in the string";
> 
> does not work for me.

hmm, i get:

There are 4 negative numbers in the string

is this not what you were expecting? what do you get?
you could also try:

$count = () = ($string =~ /-\d+/g);

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Tue, 28 Apr 1998 00:34:22 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Problem when terminating process started by system() call
Message-Id: <3545149a.12059662@news.btinternet.com>

On Tue, 28 Apr 1998 17:21:18 +0100, Chris wrote :

<snip>
>
>I can open files in the editor correctly via the script, but when I close
>the editor I get a Server Error 500, with the message
>
>                "Empty output from CGI program c:/www/cgi-bin/pfe3.pl".
>
<snip>
>---------------------------------------------------------------------
>#! /usr/binw/perl
>push(@INC,"c:/www/cgi-bin");
>#
># Using CGI-LIB.PL v2.12
>#
>require("cgi-lib.pl");
>#
># Parse the forms input data
>#
>&ReadParse;
>#
># Return appropriate MIME type to browser
>#
>print "Content-type: application/x-perl\n\n";
>#
># Open the specified file in PFE at the desired line number
>#
>system("c:/utils/pfe/pfe32.exe /m /g $in{'lnum'} $in{'fname'}");
>---------------------------------------------------------------------
>

Firstly you might want to (should) consider using CGI.pm.  It will
simplify the majority of CGI work and is well documented.

The problem is very much as the error message says.  Having sent the
"Content-Type" header you are expected to send some content.  However
that is a CGI rather than Perl issue.  You might get more information
from the newsgroup comp.infosystems.www.authoring.cgi or its FAQ.

/J\
Jonathan Stowe
Some of your questions answered http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm


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

Date: Tue, 28 Apr 1998 17:19:19 -0500
From: Sanjay Joshi <joshi@ee.tamu.edu>
Subject: Question about Pattern Matching
Message-Id: <Pine.SOL.3.96.980428171652.25448H-100000@mimolette.tamu.edu>


Hi,
	I have an access log file with entries similar to:

usr47-dialup50.mix2.boston.mci.net - - [24/Apr/1998:14:18:28 -0500] "GET
/~joshi/view.gif HTTP/1.0" 304 -

What I want to do is extract the date, in this case, 24. I want to know
about 2 methods:

1. Extract the date from the '[' to the '/'
2. Any other.

My way is below, I think it is pretty clumsy. Can anyone help?


		if ($input =~ /\[[0-9]*\//) {
			$date =$&;
			$date =~/[0-9]+/;
			$date =$&;
			$mainday{$date} +=1;
		}


Sanjay

----------------------------------------------------------------------
Sanjay Joshi                                   http://ee.tamu.edu/~joshi
News Page:			     http://ee.tamu.edu/~joshi/news.html
------------------------------------------------------------------------



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

Date: 28 Apr 1998 22:35:01 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: rename funciton (was: Re: Dummie question)
Message-Id: <6i5lil$9oc$1@client3.news.psi.net>

Tom Phoenix (rootbeer@teleport.com) wrote on MDCCI September MCMXCIII in
<URL: news:Pine.GSO.3.96.980428130928.15049m-100000@user2.teleport.com>:
++ On 28 Apr 1998, Abigail wrote:
++ 
++ > Tom Phoenix (rootbeer@teleport.com) wrote on MDCCI September MCMXCIII in
++ > <URL: news:Pine.GSO.3.96.980428101400.15049J-100000@user2.teleport.com>:
++ 
++ Was that a Tuesday? :-)

Did you post that on a Tuesday?

++ > ++ On Mon, 27 Apr 1998, yary h. wrote:
++ > ++ 
++ > ++ > It always bothered me that Perl comes with "rename", but not "copy".
++ > ++ 
++ > ++ Give us a system call which does "copy", and we'll make a Perl built-in
++ > ++ which does so. :-)
++ 
++ > Could you point out the "grep" system call from me?
++ 
++ No, I couldn't. But you knew that, and were merely being sarcastic,
++ weren't you?


Yes, I was merely pointing out that the reply "it isn't there because
there's no system call" doesn't make much sense in Perl.

If Perl just had functions for which there were system calls, we might
as well use C!


Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Tue, 28 Apr 1998 00:34:27 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Signal Trapping ..
Message-Id: <35451ba1.13803421@news.btinternet.com>

On Tue, 28 Apr 1998 11:59:05 -0400, Anonymous wrote :

>Hi .. I started learning Perl less than 3 weeks ago .. and I need some
>help.
>
Dont we all.

>I am trying to trap a signale (SIGINT to be specific) and cause that to
>exist the current subroutine I am in (call it &current_subroutine). I
>use something like
>
>$SIG{INT} = \&another_subroutine;
>
>This conveniently traps the Ctrl-C signal and invokes
>another_subroutine(). But once that is over, current_subroutine()
>continues executing. How can I cause the Ctrl-C signal to exit the
>current_subroutine()?
>
>NB. The current_subroutine is called from the main body of the program
>.. that is where I want the execution to continue.
>
A possible solution is to use a global variable that is set in your
signal handler which is used to control the flow of execution in the
interrupted subroutine.  This is most appropriate when you are
executing in a loop construct for instance.

/J\ 
Jonathan Stowe
Some of your questions answered http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm


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

Date: 29 Apr 1998 00:09:21 +0200
From: Terje Kvernes <terjekv@ifi.uio.no>
Subject: Re: Splitting a variable ???
Message-Id: <wxxd8e1r432.fsf@refil.ifi.uio.no>

"Igor Krivokon" <igor.k@usa.net> writes:

> $string = "042498a";
> ($a, $b, $c, $d ) = $string =~ /(\d\d)(\d\d)(\d\d)(\w)/;

why not \d{2} instead of \d\d? Hm...

Or, the funny way...

($a, $b, $c, $d ) = grep /./,  split /(.{2})/;

-- 
Terje Kvernes
http://www.stud.ifi.uio.no/~terjekv/


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

Date: Tue, 28 Apr 1998 16:49:33 -0600
From: indhiraa@hotmail.com
Subject: what is wrong with this code ?
Message-Id: <6i5itd$igp$1@nnrp1.dejanews.com>

Hi:

Here is a function which is called when a button is clicked.

sub showFile {

  use FileHandle;
  $fh = new FileHandle "/tmp/foo", "r";

  $showButton->fileevent($fh, "readable", \&read_file);

  sub read_file {

    my $buf;

    if (eof($fh)) {
      $showButton->fileevent($fh, "readable", undef);
      return;
    }

    if (sysread ($fh, $buf, 1024)) {
      $textArea->insert('end', $buf);
    } else {
      $textArea->insert('end', "ERROR!!!");
      $showButton->fileevent($fh, "readable", undef);
    }

  }
}

But sysread fails always complaining ..

"Use of uninitialized value at that line.."

I mean the filehandle $fh remains uninitialized.

Any suggestions please..

Thanks,

Indira.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 28 Apr 1998 14:14:16 -0700
From: Jon Drukman <jsd@gamespot.com>
Subject: Re: where are the examples in the newer (blue) camel book?
Message-Id: <354646A8.E39EDFA8@gamespot.com>

Randal Schwartz wrote:
> But stop rewriting history.  If you can't get this accurate, stop
> saying it.  If you don't understand the definition or the
> responsibilities of a "lead writer" in the technical writing industry,
> stop using the term.  Hint: "it's not the guy with the most pages".

i was a technical writer at SCO and Oracle for many years and we never
used the term "lead writer."  the job as you described it sounds more
like "project lead."

> Tom, it's messages like these that make it appear that you hate me, or
> that I hate you.  [To those watching in, I like Tom.  I think he's a
> great guy, but he gets his history a little confused sometimes.]

i love you both.  now kiss and make up.

-- 
Jon Drukman                                            jsd@gamespot.com
-----------------------------------------------------------------------
Plan: Eat right, exercise regularly, die anyway.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2447
**************************************

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