[24076] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6271 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 17 21:05:37 2004

Date: Wed, 17 Mar 2004 18:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 17 Mar 2004     Volume: 10 Number: 6271

Today's topics:
    Re: [OOPS] Double interpolatioin?? <zoooz@gmx.de>
    Re: [OT] Re: Spreadsheet::WriteExcel - Excel 97 install <usenet@morrow.me.uk>
        ANNOUNCE: List::SkipList v0.40 <perl_ann_skiplist.20.wlkngowl@spamgourmet.com>
    Re: Any Help would be great <jgibson@mail.arc.nasa.gov>
    Re: capitalizing each word in an array <zoooz@gmx.de>
        Double interpolatioin?? (Michael Watts)
    Re: Double interpolatioin?? <zoooz@gmx.de>
    Re: Double interpolatioin?? <dwall@fastmail.fm>
    Re: format printing (Brian)
    Re: How do you reference web form elements? <remorse@partners.org>
    Re: How do you reference web form elements? <baisley@hotmail.com.REMOVETHIS>
    Re: How to fill a hash from the products of a split <jgibson@mail.arc.nasa.gov>
    Re: IO::Pipe::close returns wrong value (Charles DeRykus)
    Re: LWP - build a cookie by hand? <bigal187.invalid@adexec.com>
        My Last post (Matt Carlson)
    Re: My Last post <remorse@partners.org>
    Re: My Last post <jgibson@mail.arc.nasa.gov>
    Re: My Last post <invalid-email@rochester.rr.com>
    Re: reading and writing text based on cursor position. <usenet@morrow.me.uk>
    Re: Retrieving text between 2 tags. <remorse@partners.org>
    Re: Retrieving text between 2 tags. <jgibson@mail.arc.nasa.gov>
        seek help with regular expressions syntax (Mad Scientist Jr)
    Re: Simple Sort Keys Question from a Simpleton <bumble@what.the.heck>
        stripping out ASCII chars using regexp? (Greg)
    Re: stripping out ASCII chars using regexp? <dwall@fastmail.fm>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Mar 2004 02:12:31 +0100
From: Amir Kadic <zoooz@gmx.de>
Subject: Re: [OOPS] Double interpolatioin??
Message-Id: <c3ata1$25p3sj$1@ID-142982.news.uni-berlin.de>

Amir Kadic wrote:

> Michael Watts wrote:

>> What would happen is the $i is interpolated and the integer value
>> would be placed next to the $num and the corrisponding $num would then
>> be interpolated to its value.

Sorry, I made a mistake. Here's the update:
 
Well, let's say, $i=2;

And $num is not defined (right?).

In this case the value you get is the scalar value '2', because $num=''.

Try:
print "$num$i","\n";
( "$num$i" is exactly what you decribed, except that $num is interpolated
 first :-))

If you use soft references, you are basically trying to sell a string 
for a reference to perl. And perl actually buys it, provided there exists 
a symbol table entry (i.e. a variable) with that key (name). 
 
Amir




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

Date: Wed, 17 Mar 2004 23:16:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [OT] Re: Spreadsheet::WriteExcel - Excel 97 install problem
Message-Id: <c3am93$e4h$1@wisteria.csv.warwick.ac.uk>


Quoth Thens <thens@NOSPAMti.com>:
> On Fri, 12 Mar 2004 15:10:35 +0000 (UTC)
> Ben Morrow <usenet@morrow.me.uk> wrote:
> 
> # 
> # Quoth Bhaskar Reddy <rbin.kor901209@in.bosch.com>:
> # > Thens <thens@NOSPAMti.com> wrote in 
> # > news:20040312161200.6de7e876.thens@NOSPAMti.com:
> # > 
> # 
> # Just 'cos I'm bored... (and I bet it's simpler than your Java one :):
> 
> Thanks !
> 
> But, cant you do away with the 'no warnings'

Well, yes: change that line to

$mark = '';

 . But I like the fact that undef stringifies to ''.

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


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

Date: Wed, 17 Mar 2004 23:42:53 GMT
From: Robert Rothenberg <perl_ann_skiplist.20.wlkngowl@spamgourmet.com>
Subject: ANNOUNCE: List::SkipList v0.40
Message-Id: <HuqxpC.KMM@zorch.sf-bay.org>


List::SkipList v0.40 has been uploaded and should begin appearing on
CPAN mirrors near you.

 From the README:

NAME
     List::SkipList - Perl implementation of skip lists

REQUIREMENTS
     Perl 5.6.1 is required.

     "Carp::Assert" is used for validation and debugging. (The assertions can
     be commented out if the module cannot be installed.) Otherwise standard
     modules are used.

SYNOPSIS
       my $list = new List::SkipList();

       $list->insert( 'key1', 'value' );
       $list->insert( 'key2', 'another value' );

       $value = $list->find('key2');

       $list->delete('key1');

DESCRIPTION
     This is an implementation of skip lists in Perl.  What are "skip
     lists"?  From WikiPedia <http://en.wikipedia.org/wiki/Skip_list>:

       Skip lists are a probabilistic data structure that seem likely
       to supplant balanced trees as the implementation method of
       choice for many applications. Skip list algorithms have the same
       asymptotic expected time bounds as balanced trees and are
       simpler, faster and use less space.

     (This particular implementation may not necessarily be faster or
     use less space, but in superficial testing, it does appear to be a
     reasonably faster substitute for some tree modules.)

     Skip lists are similar to linked lists, except that they have
     random links at various levels that allow searches to skip over
     sections of the list, like so:

       4 +---------------------------> +----------------------> +
         |                             |                        |
       3 +------------> +------------> +-------> +-------> +--> +
         |              |              |         |         |    |
       2 +-------> +--> +-------> +--> +--> +--> +-------> +--> +
         |         |    |         |    |    |    |         |    |
       1 +--> +--> +--> +--> +--> +--> +--> +--> +--> +--> +--> +
              A    B    C    D    E    F    G    H    I    J   NIL

     A search would start at the top level: if the link to the right
     exceeds the target key, then it descends a level.

     More information is available in the module documentation.

REVISION HISTORY
     Changes since v0.33:

     0.40  Wed Mar 17 2004
	- added Benchmark file to distribution
	* key_cmp now ignores when key is undefined
	- _insert returns the value of $node->key_cmp($key)
	- broke up test cases into separate files
	- added finger caching to speed up sequential inserts
	- fixed bugs with values, keys, copy, merge, first_key and next_key
           methods related to use of search fingers
	- fixed bug with append method
	- fixed bug with search fingers: they were not being used
	- _debug now prints to STDERR
	* reset method is not called when a new node is added or deleted
           (which is in accord with documentation)
	- stub for next method added
	- List::SkipList::Node ignores invalid and extra arguments
	- minor optimizations in List::SkipList and List::SkipList::Node
	- improved speed of _random_level
	- disabled assertions (for 50% speed improvement!)
	- inserted corrected comment in README about actual performance in
	  comparison to trees

     A detailed revision history is in the Changes file included with
     this distribution.

AUTHOR
     Robert Rothenberg <rrwo at cpan.org>

LICENSE
     Copyright (c) 2003-2004 Robert Rothenberg. All rights reserved. This
     program is free software; you can redistribute it and/or modify it
     under the same terms as Perl itself.




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

Date: Wed, 17 Mar 2004 16:28:32 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Any Help would be great
Message-Id: <170320041628320398%jgibson@mail.arc.nasa.gov>

In article <7698d2a2.0403171345.4ec6f6ef@posting.google.com>, Matt
Carlson <saryon@swbell.net> wrote:

> Hello all, I have been asked to write a quick and dirty perl script. 
> I unfortunatly dont know the first thing about perl, and neither do
> the people who asked me.  It is kind of time critical, and the only
> thing I could think of is to come here.
> 
> I think this script should be easy.(At least in my head).  
> 
> What it needs to do is this.  Open a file, and read its contents.
> 
> EX. 
> 
> Wed Mar 17 14:00:00 CST 2004
> ent0: Bytes: 106779649 Bytes: 3539900048
> ent2: Bytes: 16579540 Bytes: 2862382308
> Wed Mar 17 15:00:00 CST 2004
> ent0: Bytes: 156590900 Bytes: 7441862213
> ent2: Bytes: 14765674 Bytes: 752784621
> 
> A little bit of playing with numbers is needed as well.  
> The output needs to print the date line, and then the numbers after
> manipulation.  This output is the transmit and recieve of two ethernet
> cards.
> 
> They want the numbers to be divided by 3600(to make per second), by
> 1024(for KB/s), and then again by 1024 to have the result shown as
> MB/s.
> 
> This file is going to be appended to, and would be just as easy if it
> were printed in one long list.
> 
> I would appreciate any help anyone would have, and if anyone wants to
> make it, hey, I have no problems with that at all.

Well, I was feeling magnanimous and had a few spare minutes, so I
dashed off the following:


#!/usr/local/bin/perl
use strict;
use warnings;

use constant MB_PER_HOUR => 3600 * 1024 * 1024;

my $infile = "put your input file name here";

# replace report.txt with your real output report file in the next line
my $outfile = "report.txt";

# uncomment the following 'open' line for your real file:
# (and for future safety change both occurences of DATA to something
else; it's special)
#open(DATA, $infile) or die("Can't open $infile for reading: $!");

# read and process input file, printing results to standard output
while( my $line = <DATA>) {
  if( $line =~ /^(ent\d):\s+Bytes:\s+(\d+)\s*Bytes:\s*(\d+)/ ) {
    my($card,$transmit,$receive) = ($1,$2,$3);
    printf "%s:  %.2f MB/S  %.2f MB/S \n", $card,
      ($transmit/MB_PER_HOUR), ($receive/MB_PER_HOUR);
  }else{
    print $line;
  }
}

# the following is your test data that I can put in the program file
because I used the
# special file hand DATA. You can remove this when you put your real
file in $infile.

__DATA__
Wed Mar 17 14:00:00 CST 2004
ent0: Bytes: 106779649 Bytes: 3539900048
ent2: Bytes: 16579540 Bytes: 2862382308
Wed Mar 17 15:00:00 CST 2004
ent0: Bytes: 156590900 Bytes: 7441862213
ent2: Bytes: 14765674 Bytes: 752784621


That should be enough to get you started. Check the various options for
the open function if you want to print to a file instead of your
screen.


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

Date: Thu, 18 Mar 2004 00:18:56 +0100
From: Amir Kadic <zoooz@gmx.de>
Subject: Re: capitalizing each word in an array
Message-Id: <c3amk3$26d43a$1@ID-142982.news.uni-berlin.de>

D. Alvarado wrote:

I would say

@uppercase_array= map uc,@lowercase_array;

Amir



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

Date: 17 Mar 2004 16:26:21 -0800
From: colorado_ski_bum@hotmail.com (Michael Watts)
Subject: Double interpolatioin??
Message-Id: <69ab9d4d.0403171626.390ef74c@posting.google.com>

I have seen a scenario like the following work before but I cannot
remember the exact syntax.  Does anyone know how to get this to work?

Say you have the following variables:
$num1;
$num2;
$num3;

then you have a for loop with an $i incrementer.

I have seen something like the following that would allow you to loop
through your $num variables and allow the $i to interpolate to the
integer value that is on the variable name.  Something like $num{$i} .

What would happen is the $i is interpolated and the integer value
would be placed next to the $num and the corrisponding $num would then
be interpolated to its value.

Any help would be greatly appreciated.

colorado_ski_bum#NOSPAM#@hotmail.com


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

Date: Thu, 18 Mar 2004 02:03:08 +0100
From: Amir Kadic <zoooz@gmx.de>
Subject: Re: Double interpolatioin??
Message-Id: <c3aso4$25i4aq$1@ID-142982.news.uni-berlin.de>

Michael Watts wrote:

> Say you have the following variables:
> $num1;
> $num2;
> $num3;
> 
> then you have a for loop with an $i incrementer.
> 
> I have seen something like the following that would allow you to loop
> through your $num variables and allow the $i to interpolate to the
> integer value that is on the variable name.  Something like $num{$i} .

You want soft references (doesn't work with the strict pragma).

for $i (1..3) {
        print ${'num'.$i};
}

> What would happen is the $i is interpolated and the integer value
> would be placed next to the $num and the corrisponding $num would then
> be interpolated to its value.

Well, let's say, $i=2;
In this case the value you get is the string value 'num2'
Try:
print "$num$i","\n";
( "$num$i" is exactly what you decribed, except that $num is interpolated
first :-))

You might enjoy reading man perlref.

Amir



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

Date: Thu, 18 Mar 2004 01:24:20 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Double interpolatioin??
Message-Id: <Xns94AFCF946D810dkwwashere@216.168.3.30>

colorado_ski_bum@hotmail.com (Michael Watts) wrote:

> I have seen a scenario like the following work before but I cannot
> remember the exact syntax.  Does anyone know how to get this to work?
> 
> Say you have the following variables:
> $num1;
> $num2;
> $num3;
> 
> then you have a for loop with an $i incrementer.
> 
> I have seen something like the following that would allow you to loop
> through your $num variables and allow the $i to interpolate to the
> integer value that is on the variable name.  Something like $num{$i} .
> 
> What would happen is the $i is interpolated and the integer value
> would be placed next to the $num and the corrisponding $num would then
> be interpolated to its value.

It sounds like you want to use symbolic references.  This is almost always 
a bad idea. For a detailed discussion, see 
http://perl.plover.com/varvarname.html.

What are you really trying to do? I'm pretty sure that someone can suggest 
a better way than using symbolic references.

-- 
David Wall
"Oook."


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

Date: 17 Mar 2004 17:55:42 -0800
From: leetiger_cn@hotmail.com (Brian)
Subject: Re: format printing
Message-Id: <b5e6fb4e.0403171755.6c39c880@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c3989q$9vt$1@mamenchi.zrz.TU-Berlin.DE>...
> Brian <leetiger_cn@hotmail.com> wrote in comp.lang.perl.misc:
> > Hello everyono
> > Here is a question, how to print out the elements of a array according
> > to a format? For example, print out the arry consists of float
> > numbers, 6 numbers in every line?
> 
> What do you mean by "format"?  A Perl format in the technical sense?
> A printf format?  Something else?  Do you just want lines of six each,
> or should the columns be aligned?  Do you want a fixed field width,
> or should the width adapt to the data?  Should there be separators
> between the columns?
> 
> Explain what you want to do.  Here is how to print an array @x in
> groups of six:
> 
>     print join( ", ", splice @x, 0, 6), "\n" while @x;
> 
> If you want more, say what it is you want.
> 
> Anno

Thanks Anno, What I want is just lines of six each and the columns be
right aligned and a fixed field width,say f12.3.   I try to use printf
but I can not control the lines of six each
         for ($id=0; $id<100; $id++)     
         printf '%12.3f',"$num[$id]";

I will check if  splice works.
Thanks again!


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

Date: Wed, 17 Mar 2004 18:42:25 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: How do you reference web form elements?
Message-Id: <remorse-CD7C72.18422517032004@plato.harvard.edu>

In article <lE46c.118972$IF6.3973962@ursa-nb00s0.nbnet.nb.ca>,
 "Brett Baisley" <baisley@hotmail.com.REMOVETHIS> wrote:

> "Richard Morse" <remorse@partners.org> wrote in message
> news:remorse-55EE04.17114117032004@plato.harvard.edu...
> > It's the difference between client-side and server-side.  The web page
> > is viewed in a web browser on the client's computer.  Javascript in the
> > web page executes on the client's computer.
> >
> > However, CGIs execute on the _server_ -- any thing that you wish to do
> > with the CGI requires submitting a form to the server and waiting to
> > return information to the client.
> >
> > Thus, a CGI (on the server) can't call the "focus()" method on the
> > client.
> >
> > HTH,
> > Ricky
> 
> 
> Ok then, can I call a Perl function from within a javascript one?

Not from a CGI -- remember, CGI is _all_ server-side -- unless you are 
using .NET and doing ASPX using JScript, javascript is all client-side.

Why do you think that you need to call Perl functions from javascript?

Ricky


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

Date: Thu, 18 Mar 2004 00:05:03 GMT
From: "Brett Baisley" <baisley@hotmail.com.REMOVETHIS>
Subject: Re: How do you reference web form elements?
Message-Id: <PI56c.119033$IF6.3975787@ursa-nb00s0.nbnet.nb.ca>

Because I need to get results from a database and I know that Javascript
can't do it, as its client side, or if you can, I'm not sure how. I do know
how to with Perl tho.

But, I'm reworking my stragety, so don't worry about it. Thanks for the
input tho, I understand the concepts better now.

"Richard Morse" <remorse@partners.org> wrote in message
news:remorse-CD7C72.18422517032004@plato.harvard.edu...
> In article <lE46c.118972$IF6.3973962@ursa-nb00s0.nbnet.nb.ca>,
>  "Brett Baisley" <baisley@hotmail.com.REMOVETHIS> wrote:
>
> > "Richard Morse" <remorse@partners.org> wrote in message
> > news:remorse-55EE04.17114117032004@plato.harvard.edu...
> > > It's the difference between client-side and server-side.  The web page
> > > is viewed in a web browser on the client's computer.  Javascript in
the
> > > web page executes on the client's computer.
> > >
> > > However, CGIs execute on the _server_ -- any thing that you wish to do
> > > with the CGI requires submitting a form to the server and waiting to
> > > return information to the client.
> > >
> > > Thus, a CGI (on the server) can't call the "focus()" method on the
> > > client.
> > >
> > > HTH,
> > > Ricky
> >
> >
> > Ok then, can I call a Perl function from within a javascript one?
>
> Not from a CGI -- remember, CGI is _all_ server-side -- unless you are
> using .NET and doing ASPX using JScript, javascript is all client-side.
>
> Why do you think that you need to call Perl functions from javascript?
>
> Ricky




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

Date: Wed, 17 Mar 2004 16:47:44 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to fill a hash from the products of a split
Message-Id: <170320041647449537%jgibson@mail.arc.nasa.gov>

In article <uznafjepf.fsf@notvalid.se>, <moller@notvalid.se> wrote:

> Uri Guttman <uri@stemsystems.com> writes:
> 
> > >>>>> "ga" == gabe anzelini <usenet@c0s.org> writes:
> > 
> >   ga> what I would do:
> >   ga> map{
> >   ga>   $img_titles{$1}=$2 if /(.*?)\t(.*)/;
> >   ga> }<TITLEFILE>;
> > 
> > another map in void context!!! 
> > 
> > and in this case not needed so no fighting.
> > 
> > use File::Slurp ;
> > 
> > my $text = read_file( 'whatever' ) ;
> > 
> > my %img_titles = $text =~ /^(.*?)\t(.*)/gm ;
> 
> Please someone!! Explain this line to a noob..... 

I'll give it a shot (and I am sure someone will correct me if I am
wrong).

$text contains the contents of the file as a scalar string with
embedded newlines. The lines consist of two words separated by tab
characters. The expression '$text =~ /^(.*?)\t(.*)/gm' returns all of
the pairs of words in the file (see the g and m modifiers to the match
operator m/// and the non-greedy qualifier '?'). These pairs are used
to populate the %img_titles hash, with the first word in each pair
becoming the key and the second becoming the value. So if the line
"key\tvalue\n" exists in the file, $img_titles{'key'} will be equal to
'value'.

Good enough?


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

Date: Wed, 17 Mar 2004 23:04:26 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: IO::Pipe::close returns wrong value
Message-Id: <HuqtFE.7z7@news.boeing.com>

In article <4055a83d$0$29350$3b214f66@usenet.univie.ac.at>,
Heinrich Mislik <Heinrich.Mislik@univie.ac.at> wrote:
>In article <HuGt0F.Mx7@news.boeing.com>, ced@bcstec.ca.boeing.com says...
>
>>And from perldoc -f close:
>>
>>  Closing a pipe also waits for the process executing on the pipe 
>>  to complete, in case you want to look at the output of the pipe 
>>  afterwards, and implicitly puts the exit status value of that  
>>  command into "$?".
>
>Just before this it says:
>
> If the file handle came from a piped open "close" will addi-
> tionally return false if one of the other system calls involved
> fails or if the program exits with non-zero status.
>
>But Pipe::close returns true, even if the program returns non-zero.
>
>...
>True, but only the first warning is printed, and I think, this 
>is not as documented.
>

But, that quoting is from CORE::close, not IO::Handle's close,
which IO::Pipe inherits. That's probably a bug since IO::Handle
says it's just a front end for the builtin function and, hopefully, 
would mirror the builtin's semantics . But, it doesn't explicitly 
guarantee that it will do so.
  
A quick, ugly workaround: 

do {$pipe->close; !$?} or warn "IO::Pipe close failed: \$?=$?"


--
Charles DeRykus


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

Date: Wed, 17 Mar 2004 15:13:00 -0800
From: "187" <bigal187.invalid@adexec.com>
Subject: Re: LWP - build a cookie by hand?
Message-Id: <c3alu7$2608is$1@ID-196529.news.uni-berlin.de>

"Brian McCauley" <nobull@mail.com> wrote in message
news:u9fzc7i846.fsf@wcl-l.bham.ac.uk...
> "187" <bigal187.invalid@adexec.com> writes:
>
> > Is it possible to build your own cookies by hand, to send with a GET
or
> > POST ?
>
> Yes, of course, just do it (using header()), but why not use
> HTTP::Cookies?

That lets one make cookies from scratch (pardon the pun) ?




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

Date: 17 Mar 2004 15:08:49 -0800
From: saryon@swbell.net (Matt Carlson)
Subject: My Last post
Message-Id: <7698d2a2.0403171508.7a70a0aa@posting.google.com>

I am sorry about my last post.  I have since done some reasearch, and
developed a "sample" I guess you would call it.  It however is not
working.  I am very foreign with regex, and realize that I have
probably made a mistake in it somewhere.


########################################
# Wed Mar 17 15:00:00 CST 2004                      #
# ent0: Bytes: 156590900 Bytes: 7441862213    #
# ent2: Bytes: 14765674 Bytes: 752784621        #
########################################
#!/usr/bin/perl
#stat.pl - display stats from network interfaces

while (<>) {
	my ($day, $month, $num, $hr, $min, $sec, $zone, $year, $iface1,
$word, $if1tx, $word, $if1rx, $iface2,

$word, $if2tx, $word, $if2rx) = /^(\S+) (\S+) (\S+) (\d+):(\d+):(\d+)
(\S+) (\S+) (\S+): (\S+): (\S+) (\S+): (\S+) (\S+): (\S+): (\S+)
(\S+): (\S+)$/;
}

$if1tx1 = $if1tx / 3600 ;
$if1tx2 = $if1tx1 / 1024;
$if1tx3 = $if1tx2 / 1024;

$if1rx1 = $if1rx / 3600 ;
$if1rx2 = $if1rx1 / 1024;
$if1rx3 = $if1rx2 / 1024;

$if2tx1 = $if2tx / 3600 ;
$if2tx2 = $if2tx1 / 1024;
$if2tx3 = $if2tx2 / 1024;

$if2rx1 = $if2rx / 3600 ;
$if2rx2 = $if2rx1 / 1024;
$if2rx3 = $if2rx2 / 1024;

print ($day, $month, $num, $hr, $min, $sec, $zone, $year,"\n");
print ($iface1, $word, $if1tx3,"Transmitted", $word,
$if1rx3,"Recieved","\n");
print ($iface2, $word, $if2tx3,"Transmitted", $word,
$if2rx3,"Recieved","\n");



This is what I have so far, and the data in the ##'s are what it
should match, obviously sans the #'s.  If anyone could point me to the
correct lines, I would appreciate it.

The problem is that the information is not entering the variables when
doing ./tmp.pl < tmp .  I hope someone maybe can see my mistake very
quickly.

Thanks

Matt Carlson
saryon at swbell dot net


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

Date: Wed, 17 Mar 2004 18:54:33 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: My Last post
Message-Id: <remorse-31BE61.18543317032004@plato.harvard.edu>

In article <7698d2a2.0403171508.7a70a0aa@posting.google.com>,
 saryon@swbell.net (Matt Carlson) wrote:

> ########################################
> # Wed Mar 17 15:00:00 CST 2004                      #
> # ent0: Bytes: 156590900 Bytes: 7441862213    #
> # ent2: Bytes: 14765674 Bytes: 752784621        #
> ########################################
> #!/usr/bin/perl
> #stat.pl - display stats from network interfaces
> 
> while (<>) {
> 	my ($day, $month, $num, $hr, $min, $sec, $zone, $year, $iface1,
> $word, $if1tx, $word, $if1rx, $iface2,
> 
> $word, $if2tx, $word, $if2rx) = /^(\S+) (\S+) (\S+) (\d+):(\d+):(\d+)
> (\S+) (\S+) (\S+): (\S+): (\S+) (\S+): (\S+) (\S+): (\S+): (\S+)
> (\S+): (\S+)$/;
> }

What you're doing is executing this loop once for each line read off of 
STDIN.  Perhaps you want something like this?

while(<>) {
   # check to see if the line is a date
   if (m/^[A-Z]/) {
      # do date processing
   } else {
      # do interface processing
   }
}

This uses a really stupid (ie, will probably break) test to determine if 
the line is a date line or not: is the first letter upper-case?

To get the data out of the interface lines, you probably want something 
like:

my ($interface, $received, $sent) = m/^(\w+): Bytes: (\d+) Bytes: (\d+)/;

This will put the interface name (ent0, ent2, etc) into $interface, the 
first set of digits into $received, and the second set into $sent.

The rest is left as an exercise to the reader...

HTH,
Ricky


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

Date: Wed, 17 Mar 2004 16:55:54 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: My Last post
Message-Id: <170320041655548907%jgibson@mail.arc.nasa.gov>

In article <7698d2a2.0403171508.7a70a0aa@posting.google.com>, Matt
Carlson <saryon@swbell.net> wrote:

> I am sorry about my last post.  I have since done some reasearch, and
> developed a "sample" I guess you would call it.  It however is not
> working.  I am very foreign with regex, and realize that I have
> probably made a mistake in it somewhere.

Matt:

I responded to your first post before I saw this one. Rather than
creating a new post, it helps people to help you if you keep all of the
posts together by responding to your own post, rather than posting anew
(I am going postal in that sentence?)

Thanks.


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

Date: Thu, 18 Mar 2004 01:35:50 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: My Last post
Message-Id: <4058FCF5.2070805@rochester.rr.com>

Matt Carlson wrote:

> I am sorry about my last post.  I have since done some reasearch, and
> developed a "sample" I guess you would call it.  It however is not
> working.  I am very foreign with regex, and realize that I have
> probably made a mistake in it somewhere.
> 
> 
> ########################################
> # Wed Mar 17 15:00:00 CST 2004                      #
> # ent0: Bytes: 156590900 Bytes: 7441862213    #
> # ent2: Bytes: 14765674 Bytes: 752784621        #
> ########################################


Some commentary on this code follows:


> #!/usr/bin/perl
> #stat.pl - display stats from network interfaces
> 


You are missing the two lines:

    use warnings;
    use strict;

Those two lines enable Perl to help you with common problems with your 
program -- make use of that help!


> while (<>) {
> 	my ($day, $month, $num, $hr, $min, $sec, $zone, $year, $iface1,
> $word, $if1tx, $word, $if1rx, $iface2,
> 
> $word, $if2tx, $word, $if2rx) = /^(\S+) (\S+) (\S+) (\d+):(\d+):(\d+)
> (\S+) (\S+) (\S+): (\S+): (\S+) (\S+): (\S+) (\S+): (\S+): (\S+)
> (\S+): (\S+)$/;
> }


The above may be garbled a little bit by your news-sender and/or my news 
viewer.  But in general, you are attempting to match an entire 
multi-line entity while reading your input line-by-line.  One single 
line of input will never match the supplied regexp.  Also, note that the 
<> construction will attempt to read from files specified by 
command-line arguments, or, if none, from STDIN.  If you want to read 
from a specific file, you will need to call the open() function.  And if 
you do that, don't forget to check its return code.

Also, there is another glitch here:  You use the results of the supposed 
match without first checking to see if the match succeeded.  In this 
case, it didn't, so the code below will be working on values other than 
what you probably expected.


> 
> $if1tx1 = $if1tx / 3600 ;
> $if1tx2 = $if1tx1 / 1024;
> $if1tx3 = $if1tx2 / 1024;
> 
> $if1rx1 = $if1rx / 3600 ;
> $if1rx2 = $if1rx1 / 1024;
> $if1rx3 = $if1rx2 / 1024;
> 
> $if2tx1 = $if2tx / 3600 ;
> $if2tx2 = $if2tx1 / 1024;
> $if2tx3 = $if2tx2 / 1024;
> 
> $if2rx1 = $if2rx / 3600 ;
> $if2rx2 = $if2rx1 / 1024;
> $if2rx3 = $if2rx2 / 1024;
> 
> print ($day, $month, $num, $hr, $min, $sec, $zone, $year,"\n");
> print ($iface1, $word, $if1tx3,"Transmitted", $word,
> $if1rx3,"Recieved","\n");
> print ($iface2, $word, $if2tx3,"Transmitted", $word,
> $if2rx3,"Recieved","\n");
> 


In the above print() calls, you might want to format your numbers, 
perhaps using printf() or sprintf(), as you wish.  The divisions above 
might give a number with a non-exact decimal representation, which could 
lead to a number like 0.33333333333333333, for example, which, while 
technically correct, isn't very pretty and probably isn't what you 
really wanted.


> 
> 
> This is what I have so far, and the data in the ##'s are what it
> should match, obviously sans the #'s.  If anyone could point me to the
> correct lines, I would appreciate it.


Some other posters have given good ideas.


> 
> The problem is that the information is not entering the variables when
> doing ./tmp.pl < tmp .  I hope someone maybe can see my mistake very
> quickly.
 ...


> Matt Carlson
 ...

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Wed, 17 Mar 2004 23:18:56 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: reading and writing text based on cursor position.
Message-Id: <c3amd0$e4h$2@wisteria.csv.warwick.ac.uk>


Quoth molivier@caregroup.harvard.edu (supportgeek):
> I need to read text from a Windows Application based on cursor
> position.
> And enter text based on what is read.

You can't, in general. Get or write a command-line or batch version of
the program concerned.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Wed, 17 Mar 2004 18:43:39 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Retrieving text between 2 tags.
Message-Id: <remorse-331037.18433917032004@plato.harvard.edu>

In article <ant1719129eefNdQ@nospam.demon.co.uk>,
 James Taylor <spam-block-@-SEE-MY-SIG.com> wrote:

> In article <c3a5e6$s6j$1@mamenchi.zrz.TU-Berlin.DE>,
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > 
> >     my $begin = qr!:70E::ADTX//!;
> >     my $end = qr/:16S|:95Q/; # two alternatives
> > 
> >     my $content;
> >     while ( <DATA> ) {
> >         $content .= $_ if s/.*$begin// .. s/($end).*//s;
> >         last if $1; # end matched
> >     }

How does this work?

Ricky


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

Date: Wed, 17 Mar 2004 17:17:41 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Retrieving text between 2 tags.
Message-Id: <170320041717417354%jgibson@mail.arc.nasa.gov>

In article <remorse-331037.18433917032004@plato.harvard.edu>, Richard
Morse <remorse@partners.org> wrote:

> In article <ant1719129eefNdQ@nospam.demon.co.uk>,
>  James Taylor <spam-block-@-SEE-MY-SIG.com> wrote:
> 
> > In article <c3a5e6$s6j$1@mamenchi.zrz.TU-Berlin.DE>,
> > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > > 
> > >     my $begin = qr!:70E::ADTX//!;
> > >     my $end = qr/:16S|:95Q/; # two alternatives
> > > 
> > >     my $content;
> > >     while ( <DATA> ) {
> > >         $content .= $_ if s/.*$begin// .. s/($end).*//s;
> > >         last if $1; # end matched
> > >     }
> 
> How does this work?
> 
> Ricky

Check out 'perldoc perlop' and search for 'Range Operators'.


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

Date: 17 Mar 2004 17:27:21 -0800
From: usenet_daughter@yahoo.com (Mad Scientist Jr)
Subject: seek help with regular expressions syntax
Message-Id: <7a93f3c4.0403171727.2b400525@posting.google.com>

hi

i am trying to do a replace in HTML of all instances of 
  <LI><FONT FACE="Times New Roman" SIZE="3" COLOR="#000000"></FONT></LI>

for all font faces, all sizes, and all colors

with

  <P>&nbsp;</P>

for instance, my document of 

  abc
  <LI><FONT FACE="Times New Roman" SIZE="3" COLOR="#000000"></FONT></LI>
  123

would look like 

  abc
  <P>&nbsp;</P>
  123

when replaced

i think regular expressions is the way to go, 
but i am getting caught up in the syntax

some formulas have tried to use: 

  <LI><FONT FACE="*" SIZE="*" COLOR="*"></FONT></LI>

  \<LI\>\<FONT FACE="*" SIZE="*" COLOR="*"\>\</FONT\>\</LI\>

  \<LI\>\<FONT*FACE="*"*SIZE="*"*COLOR="*"\>\<\/FONT\>\<\/LI\>

any help appreciated! 
reg expressions seem a really important thing to know
and if i can just get the basics down then i think i'll be ok

thanks in advance


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

Date: Wed, 17 Mar 2004 23:50:36 -0000
From: "Bumble" <bumble@what.the.heck>
Subject: Re: Simple Sort Keys Question from a Simpleton
Message-Id: <c3ao5i$rvu$1@news8.svr.pol.co.uk>

Paul Lalli wrote:
>
> What exactly are you *thinking* this is going to do?  %totsales
> doesn't exist.  It's therefore defaulting to an empty hash, so there
> are clearly no keys in it.  Earlier in the script, you repeatedly
> assign values to three different scalar variables (one of which is
> named $totsales - but this is still unrelated to %totsales), and then
> do absolutely nothing with those values.
>
> So again, what are you *trying* to do?
>
> Paul Lalli

Yeah, I think it's gone wrong somewhere... :)

It's basically reading in a line of text at a time, 3 values (fname, sname
and sales), then it's supposed to sort the lines in the hash array by the
'sales' value and output them to a file?

-- 
Bumble
http://bumble.rumble.at
http://www.cossar.co.uk

"PaulB is nowt more than a top-posting fuckwit. Ignore the prat." -
Paul-B




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

Date: 17 Mar 2004 15:23:48 -0800
From: djbitchpimp@snowboard.com (Greg)
Subject: stripping out ASCII chars using regexp?
Message-Id: <7e312ede.0403171523.78527fee@posting.google.com>

I am trying to get rid of the ASCII chars from the end of a string
that I download from a webpage using LWP::Simple. The script downloads
the HTML from a webpage and  then uses HTML::TableExtract to extract
the information from specific tables on the page.

This basically gives me a string like this:

&#65533;&#65533;&#65533;,Temper Tantrum&#65533;,Take Care Comb Your
Hair&#65533;,,,CD&#65533;,23.56&#65533;&#65533;,&#65533;,0 Days
Ago&#65533;,Scotla&#65533;

which I then split into an array using:

my @line = split (',', $line) ;

I then do a comparison on $line [6]:

if ($line [6] >= 75) {

 ... do something

When I run this using -w, I get the following error:

Argument "15.99M- M- " isn't numeric in numeric ge (>=) at
 ./parse_wants.pl line 49.

This is because somehow some extended ASCII chars got in the end of
the string. If I do:

my @chars = split ('', $line [6]) ;
foreach $char (@chars) {
    print "$char ";
    print ord ($char) ;
    print "\n" ;
}

It gives me 

1 49
5 53
 . 46
9 57
9 57
&#65533; 160
&#65533; 160

I have tried stripping off these trailing ASCII 160 chars a number of
ways:

s/\240//g
s/[\200-\377]//g
tr/\177-\377//d 
s/\&#65533//g 

but the only way I could get rid of them was using:

chop $line [6]
chop $line [6]
 
Can anyone figure out a way to get rid of these trailing ASCII
characters using a regular expression?

Thanks

Greg


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

Date: Thu, 18 Mar 2004 01:13:56 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: stripping out ASCII chars using regexp?
Message-Id: <Xns94AFCDD09F09Adkwwashere@216.168.3.30>

djbitchpimp@snowboard.com (Greg) wrote:

[using HTML::TableExtract to extract data from a table]
[snip]
> I then do a comparison on $line [6]:
> 
> if ($line [6] >= 75) {
> 
> ... do something
> 
> When I run this using -w, I get the following error:
> 
> Argument "15.99M- M- " isn't numeric in numeric ge (>=) at
> ./parse_wants.pl line 49.
> 
> This is because somehow some extended ASCII chars got in the end of
> the string. 
[snip]
> Can anyone figure out a way to get rid of these trailing ASCII
> characters using a regular expression?

Unless I've misunderstood, you just want to make sure $line[6] is a number, 
correct?  If so, 

    $line[6] =~ tr/0-9.//d;

*may* be all you need.

I haven't used HTML::TableExtract and don't feel like looking it up, but 
perhaps your real problem may be with it? <shrug>

-- 
David Wall


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

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


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