[17157] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4569 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 09:05:30 2000

Date: Tue, 10 Oct 2000 06:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971183107-v9-i4569@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 10 Oct 2000     Volume: 9 Number: 4569

Today's topics:
    Re: 2 questions (Clay Irving)
        3rd try. Error Message when close (OUTFILE); but it wor translancer@my-deja.com
        Accessing the values of sub-keys in a multi-dimensional <johnno@nospam.casebook.org>
    Re: Accessing the values of sub-keys in a multi-dimensi (Rafael Garcia-Suarez)
    Re: comparing arrays (Gwyn Judd)
    Re: comparing arrays <wyzelli@yahoo.com>
        ctrl-c signal trap on NT (CDM)
    Re: DMULTIPLICITY flag (Martien Verbruggen)
    Re: Downloadable reference manual? nobull@mail.com
    Re: Downloadable reference manual? <bart.lateur@skynet.be>
    Re: Downloadable reference manual? <djberg96@my-deja.com>
    Re: Perl Books! <ymeydotcom@hotmail.com>
    Re: Perl Books! (Martien Verbruggen)
    Re: Perl Books! (Anthony Peacock)
        Perl newbie has questions about CGI <tharant@metgames.com>
    Re: send email through perl?? (Villy Kruse)
    Re: send email through perl?? (Martien Verbruggen)
        send ICQ message via a perl script ghorghor@my-deja.com
    Re: send ICQ message via a perl script ghorghor@my-deja.com
    Re: substring search <email@address.com>
    Re: substring search (Jay)
    Re: substring search <bart.lateur@skynet.be>
    Re: What does $++ mean? (Villy Kruse)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 10 Oct 2000 12:42:01 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: 2 questions
Message-Id: <slrn8u63kp.ke2.clay@panix3.panix.com>

On Tue, 10 Oct 2000 00:44:07 GMT, iamnotananimal@my-deja.com 
<iamnotananimal@my-deja.com> wrote:

>>> Q. Is there a command I can use to clear the screen before loading
>>> the images as sequential items; giving a slide-show in effect. The
>>> commented lines are just thoughts along this line.

>> That's not a Perl-related question.

> I thought print "Content-type: text/html\n\n"; was specific perl
> notation used to display output to browser from a perl script.
> I was after notation used to clear the screen that is specific to perl.
> I take it there is none.

There is no Perl notation to clear the screen on a browser and display 
sequential images giving a slide show effect.

>>> 2./ I read here in an earlier post a script to strip out all lines
>>> from a log-file containing a certain string of characters begining the
>>> line and rewrite the log-file. Could some kind soul re-post that example
>>> as I'm having no luck recreating it myself. I would like to remove all 
>>> the local machine server accesses lines from my logfile before processing 
>>> with analog.

>> Something like this?
>>
>>   #!/usr/local/bin/perl -w
>>
>>   $string_to_replace = "I want to replace this string ";
>>   $input_string = "I want to replace this string at the beginning of
>the line";
>>   ($output_string = $input_string) =~ s/^$string_to_replace//;
>>
>>   print "$input_string\n";
>>   print "$output_string\n";
>>
>> Result:
>>
>>   I want to replace this string at the beginning of the line
>>   at the beginning of the line

> I want to have the whole line removed (ignored) altogether based on
> whether the line begins with "some string" - not just an applied string
> translation. The method described requires that one knows beforehand
> what the rest of the line will be - where it is not.

Ok, how do you determine which lines in the log file belong to the local
machine?

  $string = "this is the string common to my local machine";
  $line;                       #  this is the line from my log file

  if ($line !~ /$string/) {    # if the string isn't found in the line
      print "$line\n";         # write the line
  }
 
-- 
Clay Irving <clay@panix.com>
PATRIOT, n. One to whom the interests of a part seem superior to those of
the whole. The dupe of statesmen and the tool of conquerors. 
- Ambrose Bierce 


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

Date: Tue, 10 Oct 2000 12:42:51 GMT
From: translancer@my-deja.com
Subject: 3rd try. Error Message when close (OUTFILE); but it works
Message-Id: <8rv2sa$uhs$1@nnrp1.deja.com>

How can I check the result of open, and the result of  close when doing
piped opens after printing to OutFile or modifying it with splice
(@data, $line, $record). They work but I get a final error message. How
can avoid it? Please  I need an answer.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 22:46:12 +1000
From: "Johnno" <johnno@nospam.casebook.org>
Subject: Accessing the values of sub-keys in a multi-dimensional hash
Message-Id: <39e301eb$0$11616$7f31c96c@news01.syd.optusnet.com.au>

How can I access the value of a sub-key in a hash?

Take this example:

my %blah = (
    'Fred' => {
        'about.html' => 'About Fred',
        'blah.html' => 'The Ramblings of Fred',
        'fish.html' => 'Fishing with Fred',
    },
    'Joe' => {
        'holiday.html' => 'Around the World with Joe',
        'garbage.html' => 'Joe the Sanitation Engineer',
        'blah.html' => 'Et cetera',
    },
};

A simple foreach(sort(keys(%blah))) will give me 'Fred' and allow me to do
further processing, but I need to get 'about.html' (etc.) and the
corresponding values of those sub-keys too.

I've worked with multi-dimensional hashes numerous times before, but the
sub-key has been a known entity rather than an unknown entity which has been
dynamically created, so I couldn't simply access $blah{'fred'}{'job_title'}.
for example.  The 'job_title' in this example is unknown.

My search in this regard has thus far been unsuccessful, so pointers in the
right direction would be most welcomed at this point in time.

--
Johnno (johnno@nospam.casebook.org)
http://johnno.casebook.org




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

Date: Tue, 10 Oct 2000 12:42:08 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Accessing the values of sub-keys in a multi-dimensional hash
Message-Id: <slrn8u6420.gck.rgarciasuarez@rafael.kazibao.net>

Johnno wrote in comp.lang.perl.misc:
>How can I access the value of a sub-key in a hash?
>
>Take this example:
>
>my %blah = (
>    'Fred' => {
>        'about.html' => 'About Fred',
>        'blah.html' => 'The Ramblings of Fred',
>        'fish.html' => 'Fishing with Fred',
>    },
>    'Joe' => {
>        'holiday.html' => 'Around the World with Joe',
>        'garbage.html' => 'Joe the Sanitation Engineer',
>        'blah.html' => 'Et cetera',
>    },
>};
>
>A simple foreach(sort(keys(%blah))) will give me 'Fred' and allow me to do
>further processing, but I need to get 'about.html' (etc.) and the
>corresponding values of those sub-keys too.

To get the keys for the sub-hash 'Fred' :
  my @k = keys %{ $blah{'Fred'} }

$blah{'Fred'} is a reference to a hash, %{...} dereferences it.

See the perlref manpage for more examples.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
print map substr($_,7).&$_,grep defined &$_,sort values %::;
sub Just {' another '}; sub Perl {" hacker,\n"};


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

Date: Tue, 10 Oct 2000 11:21:41 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: comparing arrays
Message-Id: <slrn8u5v4g.17l.tjla@thislove.dyndns.org>

[ netiquette suggests that you post replies *below* the text you are
replying to, as I am doing, not above as you did ]

I was shocked! How could dionysus <dionysus39@hotmail.com>
say such a terrible thing:
>>On Tue, 10 Oct 2000 04:44:09 GMT, dionysus39@hotmail.com (dionysus)
>>wrote:
>>I have two arrays, and wish to get a list of all strings in the second
>>array that are not also in the first array. I understand that I could
>>write everything out in (very)longhand, but there surely should be
>>some simple perl set operations like this, shouldn't there? Any and
>>all advice much appreciated.

p.s. before anyone asks, yes I have spent the requisite time searching
>the perl man pages, but haven't come up with anything useful :-<

You mean you didn't find the data type known as a 'hash'? Get thyself
to 'perldoc perldata' and sin no more! And then look at:

perldoq -q duplicate
perldoc -q unique

Alternatively, to do a union:

@union = (@array1, @array2);

to get the items in 1 but not 2:

@array1_not_2 = @array1;
delete @array1_not_2[@array2];

vice versa:

@array2_not_1 = @array2;
delete @array2_not_1[@array1];

to get the intersection:

@intersection = @union;
delete @intersection[@array1_not_2, @array2_not_1];

Hope that helps.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Youth is a disease from which we all recover.
		-- Dorothy Fuldheim


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

Date: Tue, 10 Oct 2000 22:13:22 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: comparing arrays
Message-Id: <g9EE5.13$Rp4.1876@vic.nntp.telstra.net>

"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn8u5v4g.17l.tjla@thislove.dyndns.org...

@array1 = qw(one two three four five);
@array2 = qw(four five six seven eight);

> @union = (@array1, @array2);
>
#  to get the items in 1 but not 2:
>
> @array1_not_2 = @array1;
> delete @array1_not_2[@array2];

delete argument is not a HASH element or slice at script line 10.

# vice versa:
>
> @array2_not_1 = @array2;
> delete @array2_not_1[@array1];

delete argument is not a HASH element or slice at script line 15.

# to get the intersection:
>
> @intersection = @union;
> delete @intersection[@array1_not_2, @array2_not_1];

delete argument is not a HASH element or slice at script line 20.

> Hope that helps.

Not really... :)

Wyzelli

--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Tue, 10 Oct 2000 09:19:25 +0200
From: cdemaeyer1@mmm.com (CDM)
Subject: ctrl-c signal trap on NT
Message-Id: <8rufv7$8e5$1@magnum.mmm.com>

Hi,
How to trap signal ctrl-c on Windows NT?

Perldoc said:
    $interrupted=0;
    $SIG{INT}= sub {
        $interrupted++;
        syswrite(STDERR,"Ouch!",5);
    }

But above does not work....





Opinions expressed herein are my own and may not represent those of my employer.



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

Date: Tue, 10 Oct 2000 21:03:00 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: DMULTIPLICITY flag
Message-Id: <slrn8u5qak.2tj.mgjv@martien.heliotrope.home>

On Mon, 9 Oct 2000 22:16:49 +0100,
	Makhno <mak@imakhno.freeserve.co.uk> wrote:
> >M> ./Configure -D -D -DMULTIPLICITY
> >M>
> 
> oops...bit of a stutter there...I meant:
> 
> ./Configure -d -D -DMULTIPLICITY
> 
> >IIRC, when you run Configure, it asks if you want to compile for
> >multiplicity, answer yes.
> 
> Hmmm, I was hoping that I could run through the Configure script with
> defaults but just change the single thing.

Hrmmm.. Have you read the file called INSTALL?

It talks about this, starting at line 292 (5.6.0 dist).

Do you make it a habit to compile things with flags that you don't know
anything about? For all you know, you might be enabling some bleedning
edge experimental code that opens up 17 backdoors that people can use to
abuse your perl. You should at least find out what it does.

# man perlguts
# man perlembed
# man perltodo

and, surprisingly:

# man perlcygwin

Also:

http://www.perl.com/pub/2000/04/whatsnew.html

Now, next time you don't know something, use tools like grep and
www.google.com to search your documentation and the Web. Ok? Don't take
things on blind faith without checking them out yourself.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | You can't have everything, where
Commercial Dynamics Pty. Ltd.   | would you put it?
NSW, Australia                  | 


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

Date: 10 Oct 2000 09:31:34 +0100
From: nobull@mail.com
Subject: Re: Downloadable reference manual?
Message-Id: <u9og0tdrmh.fsf@wcl-l.bham.ac.uk>

"Siobhan" <soneill@hotmail.com> writes:

> I have the some of the FAQ documents for Perl, but is the a complete
> reference manual that I can download?

Yes, it is part of the standard Perl distribution.  

If you have Perl you already have an abbridged version of the Camel
book available via the perldoc mechanism.


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

Date: Tue, 10 Oct 2000 10:48:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Downloadable reference manual?
Message-Id: <ags5us81oeect200kb4q7nvu8jm9lnnhge@4ax.com>

Siobhan wrote:

>I have the some of the FAQ documents for Perl, but is the a complete
>reference manual that I can download?

"Some" of the FAQs?

The whole Perl documentation, for which "perlfunc" is the most important
part IMO (followed by perlop, perlre and perlvar), is part of the
standard Perl distribution. And ten large FAQ documents.

You probably can find it online as HTML as well, from <www.perl.com>
and/or CPAN. Oh yes, there it is:

	<http://www.perl.com/pub/v/documentation>
	<http://www.cpan.org/doc/manual/html/index.html>

-- 
	Bart.


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

Date: Tue, 10 Oct 2000 12:51:56 GMT
From: Daniel Berger <djberg96@my-deja.com>
Subject: Re: Downloadable reference manual?
Message-Id: <8rv3da$uvn$1@nnrp1.deja.com>

I recommend the ActiveState documentation (even if you don't like the
distribution).  It's in nicely formatted and arranged HTML.  Has all the
FAQ's, etc.

DJB

In article <ags5us81oeect200kb4q7nvu8jm9lnnhge@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> Siobhan wrote:
>
> >I have the some of the FAQ documents for Perl, but is the a complete
> >reference manual that I can download?
>
> "Some" of the FAQs?
>
> The whole Perl documentation, for which "perlfunc" is the most
important
> part IMO (followed by perlop, perlre and perlvar), is part of the
> standard Perl distribution. And ten large FAQ documents.
>
> You probably can find it online as HTML as well, from <www.perl.com>
> and/or CPAN. Oh yes, there it is:
>
> 	<http://www.perl.com/pub/v/documentation>
> 	<http://www.cpan.org/doc/manual/html/index.html>
>
> --
> 	Bart.
>

--
In the immortal words of Socrates, "I drank what?"


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 05:27:50 -0400
From: YMEY <ymeydotcom@hotmail.com>
Subject: Re: Perl Books!
Message-Id: <39E2E116.7B202C4C@hotmail.com>

Elaine Ashton wrote:
> 
> in article 39e1e827.411347526@localhost, Ben Coleman at
> oloryn@mindspring.com quoth:
> > I'm going to have to agree with RMS on this one.  Piracy *is* about
> > Captain Hook.  Copyright infringement has nothing to do with piracy.
> 
> Main Entry:    pi·ra·cy
> Function:    noun
> Date:    1537
> 1 : an act of robbery on the high seas; also : an act resembling such
> robbery
> 2 : robbery on the high seas
> 3 : the unauthorized use of another's production, invention, or conception
> especially in infringement of a copyright
> 
> e.

Before you go preaching about what you think the law should be.... You
better know what the law is :)

Copy Right::Fair use

/*
Not with standing the provisions of sections 106 and 106A, the fair use
of a copyrighted work, including such use by reproduction in copies or
phonorecords or by any other means specified by that section, for
purposes such as criticism, comment, news reporting, **teaching
(including multiple copies for classroom use), scholarship, or research,
is not an infringement of copyright. 
*/


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

Date: Tue, 10 Oct 2000 21:13:30 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl Books!
Message-Id: <slrn8u5qua.2tj.mgjv@martien.heliotrope.home>

On Tue, 10 Oct 2000 05:27:50 -0400,
	YMEY <ymeydotcom@hotmail.com> wrote:
> 
> Copy Right::Fair use
> 
> /*
> Not with standing the provisions of sections 106 and 106A, the fair use
> of a copyrighted work, including such use by reproduction in copies or
> phonorecords or by any other means specified by that section, for
> purposes such as criticism, comment, news reporting, **teaching
> (including multiple copies for classroom use), scholarship, or research,
> is not an infringement of copyright. 
> */

Your use is not covered by any of those. Now just fsck off, will you?

*plonk*

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: 10 Oct 2000 11:20:47 GMT
From: a.peacock@chime.ucl.ac.uk (Anthony Peacock)
Subject: Re: Perl Books!
Message-Id: <8ruu2f$f0m$1@uns-a.ucl.ac.uk>

In article <39E2E116.7B202C4C@hotmail.com>, ymeydotcom@hotmail.com says...
>
>Elaine Ashton wrote:
>> 
>> in article 39e1e827.411347526@localhost, Ben Coleman at
>> oloryn@mindspring.com quoth:
>> > I'm going to have to agree with RMS on this one.  Piracy *is* about
>> > Captain Hook.  Copyright infringement has nothing to do with piracy.
>> 
>> Main Entry:    pi·ra·cy
>> Function:    noun
>> Date:    1537
>> 1 : an act of robbery on the high seas; also : an act resembling such
>> robbery
>> 2 : robbery on the high seas
>> 3 : the unauthorized use of another's production, invention, or conception
>> especially in infringement of a copyright
>> 
>> e.
>
>Before you go preaching about what you think the law should be.... You
>better know what the law is :)
>
>Copy Right::Fair use
>
>/*
>Not with standing the provisions of sections 106 and 106A, the fair use
>of a copyrighted work, including such use by reproduction in copies or
>phonorecords or by any other means specified by that section, for
>purposes such as criticism, comment, news reporting, **teaching
>(including multiple copies for classroom use), scholarship, or research,
>is not an infringement of copyright. 
>*/

What jursidiction does this passage relate to?



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

Date: Tue, 10 Oct 2000 08:44:31 GMT
From: "Tharant" <tharant@metgames.com>
Subject: Perl newbie has questions about CGI
Message-Id: <PFAE5.3561$JV3.476040@paloalto-snr1.gtei.net>

Hey folks,
   I need to build a simulator to test the integrity of some CGIs.

Question 1- Can I build build a Perl script to communicate, preferably over
a network, with my CGIs. (i.e. emulate a web user sending GET and POST URLs)
I only need to be able to talk with the CGI to initiate different functions.
I do not need to know how the CGI responds because my CGI logs all of it's
acivities.
Question 2- Could someone give me some pointers on how to do this.
Question 3- Could someone tell me what modules, if any, I will need.

Any other information would be helpfull.

Thanks in advance.

-tharant




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

Date: 10 Oct 2000 09:33:27 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: send email through perl??
Message-Id: <slrn8u5oi3.gaf.vek@pharmnl.ohout.pharmapartners.nl>

On Tue, 10 Oct 2000 05:15:00 GMT,
             Martien Verbruggen <mgjv@tradingpost.com.au> wrote:


>
>The FAQ suggests using mail or mailx, but forgets to stress that that
>should only ever be done if you have no other options. It's generally
>not a safe idea to use those directly. They're too prone to bugs and
>other problems.
>



Nowadays if a system has mail or mailx it usualy also have a sendmail
command installed, as sendmail is required by mailx or mail for mail
transport.  You have to go about 10 years back to find a system
where mailx could deliver without help of sendmail.



BTW. your header requests Mail-Copies-To: nobody

This seems an invalid address to send copies to, so I appoligize for
not doing so.



Villy


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

Date: Tue, 10 Oct 2000 21:11:50 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: send email through perl??
Message-Id: <slrn8u5qr6.2tj.mgjv@martien.heliotrope.home>

On 10 Oct 2000 09:33:27 GMT,
	Villy Kruse <vek@pharmnl.ohout.pharmapartners.nl> wrote:
> On Tue, 10 Oct 2000 05:15:00 GMT,
>              Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> 
> 
> >
> >The FAQ suggests using mail or mailx, but forgets to stress that that
> >should only ever be done if you have no other options. It's generally
> >not a safe idea to use those directly. They're too prone to bugs and
> >other problems.
> 
> Nowadays if a system has mail or mailx it usualy also have a sendmail
> command installed, as sendmail is required by mailx or mail for mail
> transport.  You have to go about 10 years back to find a system
> where mailx could deliver without help of sendmail.

\begin{offtopic}

Indeed. Although, of course, there are machines where sendmail isn't
locally available, and where people use other MDA or MTA solutions.

> BTW. your header requests Mail-Copies-To: nobody

Which is correct [1].

> This seems an invalid address to send copies to, so I appoligize for
> not doing so.

It isn't an address. It's an instruction to your newsreader to not ever
send me email copies. If your newsreader does not read this correctly,
then it is broken :). It seems that it goes through the trouble of only
partly implementing the optional Mail-Copies-To header.

In the meantime, I'll change it to the other allowed value: 'never'
(when I get back to work tomorrow), which also isn't a user on most
systems, but means the same thing.

So, your not mailing a copy to nobody is exactly what was wanted :)

Martien

[1] Reference: http://www.newsreaders.com/misc/mail-copies-to.html

\end{offtopic}
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

Date: Tue, 10 Oct 2000 11:54:25 GMT
From: ghorghor@my-deja.com
Subject: send ICQ message via a perl script
Message-Id: <8rv01f$san$1@nnrp1.deja.com>

hello

I need to know how to send icq message with a perl script, i have
search during a long time and i don't find anything

i have seen that a net::icq have been a little developp but not finished

please can someone help me


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 12:07:41 GMT
From: ghorghor@my-deja.com
Subject: Re: send ICQ message via a perl script
Message-Id: <8rv0qa$sqm$1@nnrp1.deja.com>

In article <8rv01f$san$1@nnrp1.deja.com>,
  ghorghor@my-deja.com wrote:
> hello
>
> I need to know how to send icq message with a perl script, i have
> search during a long time and i don't find anything
>
> i have seen that a net::icq have been a little developp but not
finished
>
> please can someone help me
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

i have juste found this for people who are interested :
http://diabcam.braenet.com.au/example/icq.txt

bye


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 07:57:13 GMT
From: "Rob" <email@address.com>
Subject: Re: substring search
Message-Id: <tZzE5.14076$aD2.59198@news-server.bigpond.net.au>

my ($matchregex) = qq/Runner is done/;

my ($count) = 0;

open (FILE, "mytextfile.text") || die $!;
foreach (<FILE>) {
    $count++ if (m/$matchregex/);
}
close (FILE);

print STDOUT $count.qq/ matches found\n/;

exit 0;


Rob



--
The email address should read - rob at cowsnet dot com


<jack_1236@hotmail.com> wrote in message news:8ru80i$b1p$1@nnrp1.deja.com...
> Hi,
>
> I am new to Perl and have an urgent need to find number of occurrences
> of a given expression like "Runner is done" in a text file *.txt) using
> Perl. how is it done in perl?.
>
> jack
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: 10 Oct 2000 08:41:02 GMT
From: jay@castlelink.co.uk (Jay)
Subject: Re: substring search
Message-Id: <8FC965C5Ejabrealprogrammercom@158.43.128.9>

jack_1236@hotmail.com wrote in <8ru80i$b1p$1@nnrp1.deja.com>:

>Hi,
>
>I am new to Perl and have an urgent need to find number of
>occurrences of a given expression like "Runner is done" in a text
>file *.txt) using Perl. how is it done in perl?.
>
>jack
>

A quick "one line" soloution:

$ perl -ne'$i+=s/Runner is done//g;END{print"$i\n"}' foo.txt

jay


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

Date: Tue, 10 Oct 2000 10:39:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: substring search
Message-Id: <0bs5usgevqlm9d6h8nkrt9lrad10fql77v@4ax.com>

Rob wrote:

>my ($matchregex) = qq/Runner is done/;
>
>my ($count) = 0;
>
>open (FILE, "mytextfile.text") || die $!;
>foreach (<FILE>) {

what's wrong with "while"? 

>    $count++ if (m/$matchregex/);
>}
>close (FILE);
>
>print STDOUT $count.qq/ matches found\n/;

The problem here is that this counts the lines where the string is
found, not the number of occurences of that string.

This will do that (I hope):

	while (<FILE>) {
	    $count++ while m/$matchregex/g;
	}

or this:

	while (<FILE>) {
	    $count += () = m/$matchregex/g;
	}

-- 
	Bart.


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

Date: 10 Oct 2000 09:38:12 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: What does $++ mean?
Message-Id: <slrn8u5oqt.gaf.vek@pharmnl.ohout.pharmapartners.nl>

On Mon, 9 Oct 2000 11:40:12 -0400,
                  Brad Baxter <bmb@ginger.libs.uga.edu> wrote:


>On Mon, 9 Oct 2000, Greg Miller wrote:
>
>> 	Even if it's a misprint, it's still incrementing a variable
>> which hasn't been initialized.
>
>Uh, actually, as it is, it's not doing anything because it won't compile.
>That's what led me to believe that it was a misprint.
>


What variable would that be? 

$+ +;  syntax error as a lone plus after a variable doesn't make sense.
       $+ is read-only anyway and can't be modified.

$ ++;  syntax error as a lone dollar sign doesn't make sense, and certainly
       isn't a variable.



Villy


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4569
**************************************


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