[18581] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 749 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 23 18:10:54 2001

Date: Mon, 23 Apr 2001 15:10:17 -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: <988063817-v10-i749@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 23 Apr 2001     Volume: 10 Number: 749

Today's topics:
        Installing modules on my server <m.h.a.reuvekamp@student.utwente.nl>
        Is there a neater way to code this? (in) <leapius@hotmail.com>
    Re: Is there a neater way to code this? (in) (Logan Shaw)
    Re: Is there a neater way to code this? (in) (Craig Berry)
        Loading images to Oracle using DBI <penpendisarapen@MailAndNews.com>
    Re: LWP::UserAgent? <smilepak@hotmail.com>
    Re: LWP::UserAgent? <webmaster@webdragon.unmunge.net>
        MQSeries on HP-UX 11 + Oracle <sbaldwin@bigpond.net.au>
    Re: Newbie question: reading variables with CGI <simon@super-simon.com>
    Re: Problem with associative array--what am I doing wro <bweissbo@lucent.com>
        Problems with module PlPRC <weber.m@gmx.de>
        readdir command <rapp@kjunction.com>
        Redirecting messages <jsr@agere.com>
    Re: Redirecting messages <webmaster@webdragon.unmunge.net>
    Re: Redirecting messages <jsr@agere.com>
        RegEx optimization assistance <nospam@newsranger.com>
    Re: RegEx optimization assistance <bart.lateur@skynet.be>
    Re: RegEx optimization assistance <nospam@newsranger.com>
    Re: RegEx optimization assistance <nospam@newsranger.com>
    Re: RegEx optimization assistance <bart.lateur@skynet.be>
    Re: RegEx optimization assistance (Craig Berry)
    Re: RegEx optimization assistance <krahnj@acm.org>
        regular expression question junkm fuse net.put @ after junkm.put.before net
    Re: regular expression question (Steve)
    Re: regular expression question <bart.lateur@skynet.be>
    Re: removing the \n from the data obtained from a text  <webmaster@webdragon.unmunge.net>
    Re: Spoofing a http referer <terrence.brannon@oracle.com>
        Where is my script <martin@djernaes.net>
    Re: Where is my script (Craig Berry)
    Re: Where is my script <martin@djernaes.net>
    Re: Windows Perl for Windows 95 -- Internet Explorer 5  <camerond@mail.uca.edu>
    Re: Windows Perl for Windows 95 -- Internet Explorer 5  <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 23 Apr 2001 23:04:30 +0200
From: "Marcel Reuvekamp" <m.h.a.reuvekamp@student.utwente.nl>
Subject: Installing modules on my server
Message-Id: <9c25c8$3ed$1@dinkel.civ.utwente.nl>

Hi all,

I wrote myself a little script, which uses LWP::Simple. I've tested it on my
own computer and it works fine. Now I want to upload it on my server, but
the module is not installed here. So I've tried to upload the necessary
files in the directory library and put in an extra line in my script (as
second line of the entire script):
use lib qw(/library/lib /library/site/lib);
Unfortunately, it still doesn't work. Does anyone have any tips on how I can
solve this problem?

Thanks.




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

Date: Mon, 23 Apr 2001 20:47:26 +0100
From: "Leo" <leapius@hotmail.com>
Subject: Is there a neater way to code this? (in)
Message-Id: <9c20rm$6um$1@plutonium.btinternet.com>

Hi all,

I have a flat file database in an array ("\t" delimeted) and want to change
one particular element in a record. I am currently using this rather
long-winded approach:

if ($FORM{'startdef'}) {
                foreach $cat (@cats) {

($ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir
,

$cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,

$ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl) = split(/\t/,$cat);
                        $startdef = '';
                        $cat = join("\t",
$ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir,

$cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,

$ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl);
                }
}

So basically I'm simply extracting all the elements or each record
seperately, changing on eof the, and then writing back the record over the
old entry in the array. I don't like my method and I'm sure there must be a
more elegant way of doing it even though it works ok. Any ideas?

cheers,
Leo




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

Date: 23 Apr 2001 15:11:52 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Is there a neater way to code this? (in)
Message-Id: <9c22a8$10k$1@charity.cs.utexas.edu>

In article <9c20rm$6um$1@plutonium.btinternet.com>,
Leo <leapius@hotmail.com> wrote:
>I have a flat file database in an array ("\t" delimeted) and want to change
>one particular element in a record. I am currently using this rather
>long-winded approach:
>
>if ($FORM{'startdef'}) {
>                foreach $cat (@cats) {
>
>($ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir
>,
>
>$cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,
>
>$ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl) = split(/\t/,$cat);
>                        $startdef = '';
>                        $cat = join("\t",
>$ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir,
>
>$cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,
>
>$ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl);
>                }
>}

You can replace this specific code with:

	my @fields;
	foreach my $cat (@cats)
	{	
		@fields = split (/\t/, $cat);
		$fields[4] = '';
		$cat = join ("\t", @fields);
	}

If you'd like to work symbolically (a very desirable thing), you could
use a hash slice, like this:

	@field_names = qw{ ctname ctdesc ctnum ctposts startdef sort1
		sort1dir sort2 sort2dir cttime ctweek ctweekdate
		ctlecture ctlecweek cttopic cttitle ctpost ctduein
		ctdueout ctgroup ctlecturer ctrefs ctdl };

	my %fields;
	foreach my $cat (@cats)
	{
		@fields{@field_names} = split (/\t/, $cat);
		$fields{startdef} = '';
		$cat = join ("\t", @fields{@field_names});
	}

In case you haven't used a hash slice before, basically all
that you have to remember is that this:

	@foo{("a", "b", "c")}

is pretty much the same thing as this:

	($foo{a}, $foo{b}, $foo{c})

So, by using the hash slice, you can get the fields into and out of the
hash in order (the order specified in @field_names), then work with the
hash a random-access thing, then put them back together in the original
order.  You couldn't do this with something like "values %hash",
because it gives you the values in some random, useless order.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Mon, 23 Apr 2001 20:33:50 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Is there a neater way to code this? (in)
Message-Id: <te94defag94d4f@corp.supernews.com>

Leo (leapius@hotmail.com) wrote:
: I have a flat file database in an array ("\t" delimeted) and want to
: change one particular element in a record. I am currently using this
: rather long-winded approach:
: 
: ($ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir,
: $cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,
: $ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl) = split(/\t/,$cat);

  my @fields = split /\t/, $cat;

:                         $startdef = '';

  $fields[4] = '';

:                         $cat = join("\t",
: $ctname,$ctdesc,$ctnum,$ctposts,$startdef,$sort1,$sort1dir,$sort2,$sort2dir,
: $cttime,$ctweek,$ctweekdate,$ctlecture,$ctlecweek,$cttopic,$cttitle,$ctpost,
: $ctduein,$ctdueout,$ctgroup,$ctlecturer,$ctrefs,$ctdl);

  $cat = join "\t", @fields;

: So basically I'm simply extracting all the elements or each record
: seperately, changing on eof the, and then writing back the record over the
: old entry in the array. I don't like my method and I'm sure there must be a
: more elegant way of doing it even though it works ok. Any ideas?

Important Perl style suggestion:  Never name anything you don't have to. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 23 Apr 2001 15:14:38 -0400
From: penpendisarapen <penpendisarapen@MailAndNews.com>
Subject: Loading images to Oracle using DBI
Message-Id: <3B104EA4@MailAndNews.com>

I desperatley need to find out how to load images into an Oracle 8.1.6 long 
raw field ASAP. Can this be done using DBI? Are there code samples I can 
view 
somewhere? I have limited experience with DBI and need to find out fast.

Hope someone can help me. TIA.

Victor



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

Date: Mon, 23 Apr 2001 20:00:33 GMT
From: "smilepak" <smilepak@hotmail.com>
Subject: Re: LWP::UserAgent?
Message-Id: <BR%E6.2883$5t3.237025@newsread1.prod.itd.earthlink.net>

tried that before..didn't work. Actually it turned out i misused the '. Once
i change it to " it worked fine :)

KN
"xarbos" <xarbosa@yahoo.com> wrote in message
news:988047738.456958@perla.rotterdam.luna.net...
> Quickie...
>
> make an extra string like:
> my $url = "'https://mydomain.com/".$filename;
> then replace the url in the LWP GET statement with $url like:
> my $req = new HTTP:Request 'GET', $url;
>
> Hope this helps,
>     Xarbosa...
>
> "smilepak" <smilepak@hotmail.com> wrote in message
> news:_CZE6.1875$Ee1.180039@newsread2.prod.itd.earthlink.net...
> > I have a question.
> >
> > I have a list of file in which would like to pull using LWP::UserAgent,
> > however it seem like using $filename doesn't seem to work, but typing in
> the
> > actual filename works. Anyway around this?
> >
> > HERE IS THE SCRIPT THAT DOESN'T WORK:
> >
> > foreach $line(@list) {
> >     chomp($line);
> >     &sub_https($line);
> > }
> >
> > sub sub_https {
> > $filename = shift;
> > $ua = new LWP::UserAgent;
> > my $req = new HTTP:Request 'GET', 'https://mydomain.com/$filename';
> > $res = $ua -> request($req, "$filename");
> >
> > this method doesn't seem to work. However, if i replace $filename in
> > https://mydomain.com/actualfilename it works..see below
> >
> > my $req = new HTTP:Request 'GET', "https://mydomain.com/actualfilename';
> >
> > it work..anyway around this so I could specifiy the list of file to
> > download?
> >
> > Thanx,
> > KN
> >
> >
> >
>
>
>




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

Date: 23 Apr 2001 20:17:31 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: LWP::UserAgent?
Message-Id: <9c22kr$rgp$2@216.155.32.16>

In article <_CZE6.1875$Ee1.180039@newsread2.prod.itd.earthlink.net>,
 "smilepak" <smilepak@hotmail.com> wrote:

 | I have a question.
 | 
 | I have a list of file in which would like to pull using LWP::UserAgent,
 | however it seem like using $filename doesn't seem to work, but typing in the
 | actual filename works. Anyway around this?
 | 
 | HERE IS THE SCRIPT THAT DOESN'T WORK:
 | 
 | foreach $line(@list) {
 |     chomp($line);
 |     &sub_https($line);
 | }
 | 
 | sub sub_https {
 | $filename = shift;
 | $ua = new LWP::UserAgent;
 | my $req = new HTTP:Request 'GET', 'https://mydomain.com/$filename';
 | $res = $ua -> request($req, "$filename");
 | 
 | this method doesn't seem to work. However, if i replace $filename in
 | https://mydomain.com/actualfilename it works..see below
 | 
 | my $req = new HTTP:Request 'GET', "https://mydomain.com/actualfilename';
 | 
 | it work..anyway around this so I could specifiy the list of file to
 | download?

Simplicity itself.

your code used single quotes ' ' on a string that needs to be 
interpolated via double-quotes " ".

I'll leave WHICH string needs to be interpolated as an exercise for you 
;) 

BTW, comp.lang.perl is a dead group -- e-mail your newsadmin to remove 
it, as it's been generally rmgrouped everywhere but where people aren't 
aware of this.

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Mon, 23 Apr 2001 20:07:46 GMT
From: "Steve Baldwin" <sbaldwin@bigpond.net.au>
Subject: MQSeries on HP-UX 11 + Oracle
Message-Id: <mY%E6.11455$ff.80598@news-server.bigpond.net.au>

I've currently got a Perl installation (5.6) where I've got DBI-1.14 and
DBD-Oracle-1.06 installed and working.  On HP-UX 11, this requires a bit of
stuffing around (including rebuilding Perl), but it all now works fine.  I
now want to get MQ for perl working as well, but I'm not having much luck.
Basically I fall over at the 'make test' step.

Has anyone out there got this combination working ?

Thanks,

Steve




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

Date: Mon, 23 Apr 2001 20:55:00 +0200
From: "Super-Simon" <simon@super-simon.com>
Subject: Re: Newbie question: reading variables with CGI
Message-Id: <9c1tlh$b7m$1@news1.xs4all.nl>

I read the perldoc but I didn't understand really what they meant (my
english is not that good). But someone was so friendly to give me some
examplecode by email..

<nobull@mail.com> wrote in message news:u91yqjo85s.fsf@wcl-l.bham.ac.uk...
> Unless it is your intension to be insulting then you should quote _in_
> _context_ only _relevant_ bits of the message to which you are
> replying.
>
> Is it your intension to be insulting?
>
> "Super-Simon" <simon@super-simon.com> writes:
>
> > "brian d foy" <comdog@panix.com> wrote in message
> > news:comdog-CFCF7A.11442523042001@news.panix.com...
> > > use CGI.pm.  it comes with Perl and is documented.
> > >
> > I know, but I can't find an example of how to use it...
>
> The manuals for Perl modules can be displayed using the "perldoc"
> command.
>
> Actually GCI.pm is (pointlessly) an execption to this rule but this
> doesn't matter.
>
> > Please help me,
> >
> > Newbie
>
> If you'd lurked for a while before posting In this group the term
> Newbie when applied to someone by themselves is usually correctly
> interpreted as "person too lazy to read the manual".
>
> This is not the correct use of the term but is apparently what it
> means to people who use it of themselves.
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\




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

Date: Mon, 23 Apr 2001 14:31:47 -0500
From: "Bill Weissborn" <bweissbo@lucent.com>
Subject: Re: Problem with associative array--what am I doing wrong here?
Message-Id: <9c1vu1$41c@nntpa.cb.lucent.com>


Tad McClellan <tadmc@augustmail.com> wrote in message
news:slrn9e19r5.7pr.tadmc@tadmc26.august.net...
> This is some pretty bad code. Did you grab this from the 'net somewhere?

Well...at the beginning of my post I did say it has been awhile since I
coded in Perl......
Nope, didn't grab it...I thunk this up all by myself....  8-)

> Have you tried debugging it with simple print statements yet?
>
>    print "\$pooltouse is '$pooltouse'\n";
>
>    print "$_ => $foundit{$_}\n" for keys %foundit;
>

Yup or at least something similar.
>

> Ask for all of the help that you can get:
>
>    #!/usr/local/bin/perl -w
>    use strict;

Yup did that too.....

> You should always, yes *always*, check the return value from open():

Production code, definitely....proof-of-concept type stuff....I don't think
so....especially when I "KNOW" the file is there and readable.

> Another piece of 5-year old Perl code, suspicions mount...
>

"Thank you sir.....may I have another?"     8-)





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

Date: Mon, 23 Apr 2001 22:14:46 +0200
From: "Mathias-H. Weber" <weber.m@gmx.de>
Subject: Problems with module PlPRC
Message-Id: <3AE48D36.6998C8ED@gmx.de>

I tried to install Bundle::PlRPC. Everything went fine up to "make test"
of module "PlRPC-0.2015". The error message is not very valuable ("Use
of uninitialized value in concatenation (.)") - the problem is deeper
and may have something to do with incorrect usage of Sys::Syslog.

I tried to create an own server and client and got them running. But I
had to explicitly include "require Sys::Syslog;" in my server. 

I have tried hard to find the problem with "make test" but did not
succeed. Has anybody used/installed this module recently and give some
hints?

Thanks in advance
(Perl is 5.6.0)
--
Mathias-H.Weber                        mailto:weber.m@gmx.de


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

Date: Mon, 23 Apr 2001 21:57:48 GMT
From: "Kerstin Rapp" <rapp@kjunction.com>
Subject: readdir command
Message-Id: <wz1F6.12371$SI5.1876387@news1.telusplanet.net>

Hi there:

I'm trying to use readdir. It goes into a foreach loop and is supposed to
print and then copy the found files if they have a certain extension.

Everything works - just it iterates through the directory 95 times and
therefore tries to execute the command 95 times (what is very annoying).

I tried shift, push, etc. what didn't make any difference.

What am I doing wrong?

Any help would be appreciated

Thanks, Kerstin




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

Date: Mon, 23 Apr 2001 14:02:05 -0400
From: Steve Roberts <jsr@agere.com>
Subject: Redirecting messages
Message-Id: <3AE46E1D.9CA54E27@agere.com>

I have a couple of programs that I cannot change but I must use. These
send out tons of messages to STDERR. Is there any way I can redirect
these messages to another file so that I don't clutter up the log files
and so it is easier to see what errors these programs generated? Thank
you for your help.

--
Steve Roberts
Agere Systems
9333 S. John Young Pkwy.
Orlando, FL 32819
Ph: 407-371-7690
jsr@agere.com




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

Date: 23 Apr 2001 20:20:06 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: Redirecting messages
Message-Id: <9c22pm$rgp$3@216.155.32.16>

In article <3AE46E1D.9CA54E27@agere.com>, Steve Roberts <jsr@agere.com> 
wrote:

 | I have a couple of programs that I cannot change but I must use. These
 | send out tons of messages to STDERR. Is there any way I can redirect
 | these messages to another file so that I don't clutter up the log files
 | and so it is easier to see what errors these programs generated? Thank
 | you for your help.

Easy. 

    open(STDERR, ">>errors.txt") or die("Cannot redirect STDERR : $!");

is one way. :)

 | --
 | Steve Roberts
[snip]

by the way, you need to put a space after the -- to get the rest to 
register as a proper sig.

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Mon, 23 Apr 2001 16:30:33 -0400
From: Steve Roberts <jsr@agere.com>
Subject: Re: Redirecting messages
Message-Id: <3AE490E9.CD6FF53C@agere.com>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Thanks. I found out I can also use 2> "filename" after the program call.
Yours works great too.
<p>"Scott R. Godin" wrote:
<blockquote TYPE=CITE>In article &lt;3AE46E1D.9CA54E27@agere.com>, Steve
Roberts &lt;jsr@agere.com>
<br>wrote:
<p>&nbsp;| I have a couple of programs that I cannot change but I must
use. These
<br>&nbsp;| send out tons of messages to STDERR. Is there any way I can
redirect
<br>&nbsp;| these messages to another file so that I don't clutter up the
log files
<br>&nbsp;| and so it is easier to see what errors these programs generated?
Thank
<br>&nbsp;| you for your help.
<p>Easy.
<p>&nbsp;&nbsp;&nbsp; open(STDERR, ">>errors.txt") or die("Cannot redirect
STDERR : $!");
<p>is one way. :)
<p>&nbsp;| --
<br>&nbsp;| Steve Roberts
<br>[snip]
<p>by the way, you need to put a space after the -- to get the rest to
<br>register as a proper sig.
<p>--
<br>unmunge e-mail here:
<br>#!perl -w
<br>print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
<br># ( damn spammers. *shakes fist* take a hint. =:P )</blockquote>

<p>&nbsp;--
<br>Steve Roberts
<br>Agere Systems
<br>9333 S. John Young Pkwy.
<br>Orlando, FL 32819
<br>Ph: 407-371-7690
<br>jsr@agere.com
<br>&nbsp;</html>



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

Date: Mon, 23 Apr 2001 18:24:05 GMT
From: Drew <nospam@newsranger.com>
Subject: RegEx optimization assistance
Message-Id: <9r_E6.2211$QV4.180869@www.newsranger.com>


I'd like to consolidate the following RE into one pass, but I'm not sure how to
do it.

Here's the data file:

TimeStamp: 2001 095 00 05 01 4 Thu Apr 05
VM
memory                     page                          faults
avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
21996  203131    0    0     0    0     9    0     0   3054  27087   806
CPU
cpu          procs
us sy id    r     b     w
17  3 80    2     0     0
18  4 78
18  4 78
17  4 79
20  7 73
21 11 69


Here's my code:
#!/usr/bin/perl -w
use strict;

my $testfile="/home/s46601/perl/vm05";
open (TESTFILE,$testfile) || die "Can't open testfile: $!\n";
my $free;
while ( <TESTFILE> ) {
if (/free/ .. /CPU/) {
if (/.\s+\d+\s+(\d+)/) {
print "$1\n";
}
}
}
close (TESTFILE) || die "Can't close testfile: $!\n";

Is there a way I can:

while (<TESTFILE>) {
print "$1\n" if (/consolidatedRE/);
}

Thanks in advance for the assist!





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

Date: Mon, 23 Apr 2001 18:53:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RegEx optimization assistance
Message-Id: <21u8etg9vgi00ka3i94umck6t139l94fb3@4ax.com>

Drew wrote:

>I'd like to consolidate the following RE into one pass, but I'm not sure how to
>do it.
>
>Here's the data file:
 ...
>avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
>21996  203131    0    0     0    0     9    0     0   3054  27087   806
>CPU

>Here's my code:
>while ( <TESTFILE> ) {
>if (/free/ .. /CPU/) {
>if (/.\s+\d+\s+(\d+)/) {
>print "$1\n";
>}
>}
>}

>Is there a way I can:
>
>while (<TESTFILE>) {
>print "$1\n" if (/consolidatedRE/);
>}
>
>Thanks in advance for the assist!

I think not. You're using the range operator, which is not something you
can emulate with regexes alone.

But you can combine both "if" statements, thanks to shortcircuiting:

	while ( <TESTFILE> ) {
	    if (/free/ .. /CPU/ and /.\s+\d+\s+(\d+)/) {
		print "$1\n";
	    }
	}

Or, you can use the numerical result of the range operator, because it
has a built-in counter:

	while ( <TESTFILE> ) {
	    if (((/free/ .. /CPU/)||0)==2) {
		print "$1\n" if /.\s+\d+\s+(\d+)/;
	    }
	}

p.s. I don't understand which column your regex is trying to match. You
want that zero under "si"?

-- 
	Bart.


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

Date: Mon, 23 Apr 2001 19:14:22 GMT
From: Drew <nospam@newsranger.com>
Subject: Re: RegEx optimization assistance
Message-Id: <ia%E6.2259$QV4.186039@www.newsranger.com>

In article <21u8etg9vgi00ka3i94umck6t139l94fb3@4ax.com>, Bart Lateur says...
>
>Drew wrote:
>
>>I'd like to consolidate the following RE into one pass, but I'm not sure how to
>>do it.
>>
>>Here's the data file:
>...
>>avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
>>21996  203131    0    0     0    0     9    0     0   3054  27087   806
>>CPU

--SNIP--

>p.s. I don't understand which column your regex is trying to match. You
>want that zero under "si"?

whoops.  I guess that would've helped.  I'm trying to get the number under the
"free" column.  

The next problem is how to only get the even numbered matches (which I think the
builtin range counter you mentioned will make that fairly simple).  But I'll
play with that off-line.

Thanks Bart,
Drew




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

Date: Mon, 23 Apr 2001 19:18:50 GMT
From: Drew <nospam@newsranger.com>
Subject: Re: RegEx optimization assistance
Message-Id: <ue%E6.2265$QV4.186491@www.newsranger.com>

In article <21u8etg9vgi00ka3i94umck6t139l94fb3@4ax.com>, Bart Lateur says...
>
>Drew wrote:
>
>>I'd like to consolidate the following RE into one pass, but I'm not sure how to
>>do it.
>>
>>Here's the data file:
>...
>>avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
>>21996  203131    0    0     0    0     9    0     0   3054  27087   806
>>CPU

--SNIP--

>p.s. I don't understand which column your regex is trying to match. You
>want that zero under "si"?

whoops.  I guess that would've helped.  I'm trying to get the number under the
"free" column.  

The next problem is how to only get the even numbered matches (which I think the
builtin range counter you mentioned will make that fairly simple).  But I'll
play with that off-line.

Thanks Bart,
Drew




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

Date: Mon, 23 Apr 2001 20:06:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RegEx optimization assistance
Message-Id: <hs29etgqjds8ohij6ptvff6utaobkogpfg@4ax.com>

Drew wrote:

>>>avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
>>>21996  203131    0    0     0    0     9    0     0   3054  27087   806
>>>CPU
>
>--SNIP--
>
>>p.s. I don't understand which column your regex is trying to match. You
>>want that zero under "si"?
>
>whoops.  I guess that would've helped.  I'm trying to get the number under the
>"free" column.  

	/^\s*\d+\s+(\d+)/

-- 
	Bart.


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

Date: Mon, 23 Apr 2001 20:28:27 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: RegEx optimization assistance
Message-Id: <te943b7oui1ba0@corp.supernews.com>

Drew (nospam@newsranger.com) wrote:
: I'd like to consolidate the following RE into one pass, but I'm not
: sure how to do it.
: Here's the data file:
: 
: TimeStamp: 2001 095 00 05 01 4 Thu Apr 05
: VM
: memory                     page                          faults
: avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
: 21996  203131    0    0     0    0     9    0     0   3054  27087   806
: CPU
: cpu          procs
: us sy id    r     b     w
: 17  3 80    2     0     0
: 18  4 78
: 18  4 78
: 17  4 79
: 20  7 73
: 21 11 69
: 
: 
: Here's my code:
[snip]
: while ( <TESTFILE> ) {
: if (/free/ .. /CPU/) {
: if (/.\s+\d+\s+(\d+)/) {
: print "$1\n";
: }
: }
: }

The only line you care about is also the only one with 12 integers on it.
I'd do this:

  while (<TESTFILE>) {
    my @chunks = m/(\d+)/g;
    print "$chunks[1]\n" if @chunks == 12;
  }

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 23 Apr 2001 21:55:09 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: RegEx optimization assistance
Message-Id: <3AE4A4B9.6F8E901F@acm.org>

Drew wrote:
> 
> In article <21u8etg9vgi00ka3i94umck6t139l94fb3@4ax.com>, Bart Lateur says...
> >
> >Drew wrote:
> >
> >>I'd like to consolidate the following RE into one pass, but I'm not sure how to
> >>do it.
> >>
> >>Here's the data file:
> >...
> >>avm    free   si   so    pi   po    fr   de    sr     in     sy    cs
> >>21996  203131    0    0     0    0     9    0     0   3054  27087   806
> >>CPU
> 
> --SNIP--
> 
> >p.s. I don't understand which column your regex is trying to match. You
> >want that zero under "si"?
> 
> whoops.  I guess that would've helped.  I'm trying to get the number under the
> "free" column.
> 
> The next problem is how to only get the even numbered matches (which I think the
> builtin range counter you mentioned will make that fairly simple).  But I'll
> play with that off-line.

Try something like this.
[untested]

#!/usr/bin/perl -w
use strict;

my $testfile = '/home/s46601/perl/vm05';
open TESTFILE,$testfile or die "Can't open testfile: $!\n";

my %stats;
while ( <TESTFILE> ) {
    if ( /\bfree\b/ ) {
        my @keys = split " ";
        @stats{ @keys } = split " ", <TESTFILE>;
        }
    }

print "$stats{free}  $stats{in}\n";


John
-- 
use Perl;
program
fulfillment


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

Date: 23 Apr 2001 20:06:46 GMT
From: junkm fuse net.put @ after junkm.put.before net
Subject: regular expression question
Message-Id: <9c220m$mp0$1@news.netmar.com>


I would like to replace all multiple whitespace characters within a string
with a single space unless that whitespace appears within
<pre></pre> or
<script></script> tags.

I know just enough to be dangerous.  I have this:

    [^<(pre|script)>.*<[/](pre|script)>]

for "match all characters including and within the specified tags".  

And then the whitespace [:space:] or \s

How do I say, "match all whitespace that does not appear between pre or
script
tags"?

Thanks,
Andy



 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: 23 Apr 2001 21:08:38 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: regular expression question
Message-Id: <slrn9e96bd.d70.steve@zero-pps.localdomain>

On net.put@after junkm.put.before net wrote:
>
>I would like to replace all multiple whitespace characters within a string
>with a single space unless that whitespace appears within
><pre></pre> or
><script></script> tags.
>
>I know just enough to be dangerous.  I have this:
>
>    [^<(pre|script)>.*<[/](pre|script)>]

You're probably better off using HTML::Parser and it's 
appropriate friends.  It's not worth rolling your own. 
 
>
>for "match all characters including and within the specified tags".  
>
>And then the whitespace [:space:] or \s

Something like  tr/\s+/\s/;

>How do I say, "match all whitespace that does not appear between pre or

As mentioned in the above solutions, so read the manpages on 
HTML::Parser and related pages plus the docs that deal with the tr function, 
but there'll be more than one way to do it, find what's best for you. 

Hope some of that helps. 

-- 
Cheers
Steve              email mailto:steve@zeropps.uklinux.net

%HAV-A-NICEDAY Error not enough coffee  0 pps. 

web http://www.zeropps.uklinux.net/

or  http://start.at/zero-pps

  9:49pm  up 80 days, 22:34,  2 users,  load average: 1.50, 1.66, 1.45


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

Date: Mon, 23 Apr 2001 21:19:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regular expression question
Message-Id: <7079etok1mtrdlaams463p40jq850mlfi9@4ax.com>

whitetigercat wrote:

>If I have a pattern, how can i delete everything in the string doesn't
>match that pattern? For example, if $content is an HTML page that
>contains a FORM and $pattern = "<input ([^>]|\n)*>" i.e. input
>statements in an HTML FORM, how can i delete everything in the page
>except these INPUT tags so I can do further processing on them?

I think I would try capturing every match and create a new string from
joining those.

	$pattern = '<input ([^>]|\n)*>';
	$stripped = join '', /$pattern/g;

-- 
	Bart.


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

Date: 23 Apr 2001 20:09:34 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: removing the \n from the data obtained from a text area in a form
Message-Id: <9c225u$rgp$0@216.155.32.16>

In article <3AE31093.983E4FD4@cornell.edu>,
 Young Chi-Yeung Fan <yf32@cornell.edu> wrote:

 | Is the script running on Windows, or Unix, or Mac? I think Windows 
 | uses "\r\n" for the end-of-line, so you'd have to replace \r\n with 
 | <P>. I think Mac uses "\r", and Unix uses "\n".

on the Mac, under MacPerl, I use \n, but it effectively translates to 
\015 (IIRC) and unix uses \012, while Whinedows uses \012\015..

so while my scripts still use \n, and unix scripts can/may also use \n, 
the mapping internally is different to what character Perl actually 
generates. (something to bear in mind, anyway.)

HTH

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Mon, 23 Apr 2001 11:32:56 -0700
From: Terrence Monroe Brannon <terrence.brannon@oracle.com>
Subject: Re: Spoofing a http referer
Message-Id: <3AE47557.1D95A27F@oracle.com>

http://www.linpro.no/lwp/ is the homepage for LWP. You should also join the
mailing list discussed there for help:

The mailing list address is

                 libwww@perl.org

            and administrivia (including subscribe requests) should be sent
to

                 libwww-request@perl.org

Bastian Ballmann wrote:

> Hi @ll!!
> I have downloaded the Bundle::LWP and have read most of the manual but I
> still dont know how to spoof a http referer.
> Can anyone explain that to me, please?
> Greetz
>
> Basti

--
Terrence Brannon
Oracle Corporation
500 Oracle Parkway
M/S 3op1556a
Redwood Shores, CA 94065
(650) 607-5482




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

Date: Mon, 23 Apr 2001 12:57:53 -0700
From: Martin Djernaes <martin@djernaes.net>
Subject: Where is my script
Message-Id: <3AE48941.DBD76F0B@djernaes.net>

Hi,

What's the way to find the location of a script (from within the
script)?

I have a CGI script in /home/someuser/public_html/adir/ called
ascript.pl. When ever it's called by Apache I can use '.' for the
current dir, which is also the dir of the script, but if I'm in
/home/someuser and call /usr/bin/perl public_html/adir/ascript.pl I look
that information - how do I find "my own" location?

Martin


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

Date: Mon, 23 Apr 2001 20:35:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Where is my script
Message-Id: <te94gqkoemtp84@corp.supernews.com>

Martin Djernaes (martin@djernaes.net) wrote:
: What's the way to find the location of a script (from within the
: script)?

  perldoc FindBin

: I have a CGI script in /home/someuser/public_html/adir/ called
: ascript.pl. When ever it's called by Apache I can use '.' for the
: current dir, which is also the dir of the script,

This does work for Apache (and many other servers), but beware of counting
on it; port to IIS, and you will experience great pain.  I've learned this
the hard way. :P

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 23 Apr 2001 14:36:54 -0700
From: Martin Djernaes <martin@djernaes.net>
Subject: Re: Where is my script
Message-Id: <3AE4A076.77C3FD64@djernaes.net>

Hi Craig,

Craig Berry wrote:
> Martin Djernaes (martin@djernaes.net) wrote:
> : What's the way to find the location of a script (from within the
> : script)?
> 
>   perldoc FindBin
> 
> : I have a CGI script in /home/someuser/public_html/adir/ called
> : ascript.pl. When ever it's called by Apache I can use '.' for the
> : current dir, which is also the dir of the script,
> 
> This does work for Apache (and many other servers), but beware of counting
> on it; port to IIS, and you will experience great pain.  I've learned this
> the hard way. :P
;)

I want to use it as command line as well as cgi script, and found the
problem. 

Did I understand FindBin correctly if it doesn't work if I use 'perl
myscript.pl' when calling! It it "just" looking at the path - doesn't
perl offer this information to the script itself?

Martin


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

Date: Mon, 23 Apr 2001 13:26:57 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Windows Perl for Windows 95 -- Internet Explorer 5 required?
Message-Id: <3AE473F1.622CFC87@mail.uca.edu>

Bart Lateur wrote:
> 
> Charles M. Kozierok wrote:
> 
> >Perl newbie here, trying to download a win32 binary so I can write
> >code offline. I went to Active State but their system requirements
> >seems to say I need IE5 and a bunch of other stuff to use the distribution.
> >Is this really the case for all of the contents, or is it needed for
> >only portions of the package?
> 
> Well... it SAYS so. I've heard people saying that it does not really
> need it all.

Perhaps it's because (1) you need a web browser to read the help files
and (2) some of their PPM links for installing extra modules don't work
well at all in Netscape (word is that they can hang up your machine for
minutes, and whether they work well in IE4, I don't know).

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Mon, 23 Apr 2001 19:13:44 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Windows Perl for Windows 95 -- Internet Explorer 5 required?
Message-Id: <qev8etc1eqk76u3kre4prq77eb3ev1ul4k@4ax.com>

Charles M. Kozierok wrote:

>Is Indigo as "good as" ActiveState, which seems to be the usual
>"default" recommendation?

What I means is that it is actually binary compatible with it. Not only
is it a Perl of the same version, it is likely even built from the same
source, and even modules that use a custom DLL, written and compiled for
Activestate, can be used by IndigoPerl.

And yes, it's "as good as" Activestate. I think. I use it all the time.
So I can't really compare.  ;-)

>Again, all I need is based interpreter capabilities
>for the most part.

Sorry, no "light" versions of Perl available. ;-) But if you're saying
that you don't need any extra bells and whistles, well, it looks to me
as if ActiveState's Perl has a few more of those.

-- 
	Bart.


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

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.  

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 749
**************************************


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