[11621] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5221 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 25 00:01:45 1999

Date: Wed, 24 Mar 99 21:00:20 -0800
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, 24 Mar 1999     Volume: 8 Number: 5221

Today's topics:
    Re: accessing class specific variables in inherited cla (Damian Conway)
        Database utilisation in web site design <sing.loon@uq.net.au>
    Re: Deep Recursion error in a tie'd variable <rick.delaney@home.com>
        Email With Attachment <kcchan@csis.hku.hk>
    Re: Email With Attachment (Bob Trieger)
    Re: How to create a new directory <rick.delaney@home.com>
    Re: How to interpolate subroutines in here-documents? (Tad McClellan)
    Re: never mind... <eric.schwartz@acm.org>
    Re: never mind... (Larry Rosler)
    Re: never mind... (Tad McClellan)
    Re: New @ Perl, Need a Good Tutorial <jbc@shell2.la.best.com>
    Re: New @ Perl, Need a Good Tutorial <webmaster@bnicewd.com>
    Re: New Bee Alert (Tad McClellan)
        Not possible in Perl?? (Joe)
        Pass FileHandler in CGI <kcchan@csis.hku.hk>
    Re: Perl newbie problem: <pmak@iname.com>
    Re: Perl newbie problem: <pmak@iname.com>
    Re: Perl newbie problem: (Bob Trieger)
        regular expression rheinman@my-dejanews.com
    Re: regular expression (Bob Trieger)
    Re: regular expression <rick.delaney@home.com>
        Standard Deviation <kenrose@home.com>
        String manipulation jatgal@my-dejanews.com
        String manipulation jatgal@my-dejanews.com
    Re: String manipulation (Bob Trieger)
    Re: Web Mail <alan@empresa.com>
    Re: What isn't getting reset? <bwegman@HiWAAY.net>
    Re: What isn't getting reset? (Sam Holden)
        What to use for X gui? <rclang@rclangtos.lewan.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 25 Mar 1999 01:58:06 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: accessing class specific variables in inherited classes
Message-Id: <7dc57e$k4i$1@towncrier.cc.monash.edu.au>

Tom Christiansen <tchrist@mox.perl.com> writes:

Tom> Class variables should have references to them placed on their
Tom> self objects and accessed indirectly.
Tom>
Tom>	 [sample code deleted]

Alternatively, you can access them via class methods:

	package A;

	{
	    # as in Tom's version...

		my %hash = (  # block private
			valA => 1,
			valB => 2,
		);

	    # but put the printhash method here

		sub printhash  { return join "\n", keys %hash }

	    # other accessors to %hash here, e.g...

		sub valA { $hash{valA} = $_[1] if defined $_[1]; $hash{valA} }
	}


	sub new {
		my $class = shift;
		my $self = {};
		bless $self, $class;
		return $self;
	}


Tom> And yes, that means that if B inherits A::new, that
Tom> your B object will have a pointer to A's hash.  But
Tom> that makes sense, because B doesn't have its own new.

In the version I'm suggesting, you can add a B-specific %hash
and *still* use A's new:


	package B;
	@ISA = qw( A );

	{
		my %hash = (  # block private
		valC => 3,
		valD => 4,
		);

		sub printhash  { return join "\n", keys %hash }

		# other class attribute accessors here, e.g...

		sub valC { $hash{valC} = $_[1] if defined $_[1]; $hash{valC} }
	}


Now you can do this:

	my $a = A->new();	# calls A::new('A')
	my $b = B->new();	# calls A::new('B')

	print A->printhash();	# accesses A's %hash
	print $a->printhash();	# accesses A's %hash

	print B->printhash();	# accesses B's %hash
	print $b->printhash();  # accesses B's %hash

	print B->valA;		# accesses A's %hash (!)
	print $b->valA;		# accesses A's %hash (!)
	print B->valC;		# accesses B's %hash
	print $b->valC;		# accesses B's %hash


Best of all, if the constructor (or any other inherited method)
were to call printhash:

	sub new {
		my $class = shift;
		my $self = {};
		bless $self, $class;
		print $self->printhash();	# debugging maybe
		return $self;
	}


you'd *still* get the correct behaviour in B objects.  That is:

	my $a = A->new();	# calls A::new('A') which then
				# internally calls A::printhash

	my $b = B->new();	# calls A::new('B'), which then
				# internally calls B::printhash (!)


Damian


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

Date: Thu, 25 Mar 1999 11:37:18 +1100
From: "liu singloon" <sing.loon@uq.net.au>
Subject: Database utilisation in web site design
Message-Id: <7dc46d$85f$1@bunyip.cc.uq.edu.au>

Hi need some info and advice on the following,

I have recently signed up with a paid web hosting provide and registered my
own domain name.

My web host package supports the following:


SSI, Server Side Support for Java, PERL 4, 5, 5.003, 5.004, C++, TCL, and
Python, IMAP4 and Procmail. mySQL 2.0.3 AND 3.22

and

Support For MS Frontpage 97 and 98 Extensions and HTML Script Applets and
Miva Mia ?.

What I want to do is be able to easily update my entertainment web sites
movie release dates listing and to generate a html file which I have
designed around my web site layout etc.  It can be generated offline and I
can upload it or can be done on the fly.

The site will be divided among 2 -7 countries = each with categories listed
by month from Jan - Dec - showing release dates for that country.

I have no experience with databases - apart from my 1 single uni subject on
Access 2 which I have little memory of.

My current set of design tools are,

Dreamweaver 1.2/2, Homesite 3/4, Adobe Pagemaker, Adobe Photoshop 4.01,
Fireworks 1, Flash 3, GIF Movie Gear 2.6, MS GIF Animator and WS_FTP LE and
Pro 6.

Does anyone know of some programs that will allow me to

1. Create an easy to use database ? - I have Access 7 but don't know much
about it.
2. Generate custom designed html files for database data on movie release
dates ?

I tried Drumbeat 2000 evaluation but it crashes my pc and stalls ....

Thanks, my current web site is below, but will be moving to the new paid web
host hopefully by the end of the month or middle of next month.

--
George Liu

=====================================
http://georges-place.webjump.com/
- Australian/US/HK movie release dates
- Oscars, Movies, Trailers & Info  for  1999
- Oscars Winners List
=====================================





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

Date: Thu, 25 Mar 1999 04:40:33 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Deep Recursion error in a tie'd variable
Message-Id: <36F9C034.E698F5A1@home.com>

[posted & mailed]

Kelly E Jones wrote:
> 
> This time, I get a 'Deep Recursion' warning from the line referencing
> $$xref1[$subscript], presumably because it is recursively using this
> FETCH method to obtain the value.

If the deep recursion was from FETCH, perl should tell you.  It's hard
to tell what the problem is exactly without a snippet that I can run
that produces the error.  You haven't shown your tie statement for the
array case, for instance.

> Is there a better way to do this, use a tied variable to return
> something that is a function of the variable and some other variable?

You should not be using a reference to the array you're tying in the
object since that can recursively call FETCH when you access it.  I
think you want a closure.  Here the function is concatenation of
elements with the same index.

#!/usr/local/bin/perl -w

use strict;

sub TIEARRAY {
    my ($pkg, $constant) = @_;
    my $closure;
    my $var = [];
    $constant = [ @$constant ];
    $closure = sub {
        my ($aref, $i) = @_;
        $aref->[$i] . $constant->[$i];
    };
    return(bless [$var, $closure], $pkg);
}
sub FETCH {
    my ($obj, $subscript) = @_;
    return $obj->[1]->($obj->[0], $subscript);
}
sub STORE {
    my ($self, $idx, $value) = @_;
    return $self->[0][$idx] = $value;
}

my @a = ('a', 'b');
my @b;

tie @b, 'main', @b, \@a;
$b[0] = 'y';
$b[1] = 'z';

print "$b[0]\n$b[1]\n";

__END__
ya
zb

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 25 Mar 1999 05:45:11 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
Subject: Email With Attachment
Message-Id: <Pine.GSO.4.03.9903250543290.2381-100000@virtue.csis.hku.hk>

Dear All,

	Is there any SIMPLE method to send a email with attachment..I have
seen some response which need some modules MIME:XXXX....but the server I
am using do not have such module....what can I do???...thanks for your
help...

Regards,
Rollo



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

Date: Thu, 25 Mar 1999 03:56:51 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Email With Attachment
Message-Id: <7dcc88$4mr$3@birch.prod.itd.earthlink.net>

Rollo Chan Ka Chun <kcchan@csis.hku.hk> wrote:
>Dear All,
>
>        Is there any SIMPLE method to send a email with attachment..I have
>seen some response which need some modules MIME:XXXX....but the server I
>am using do not have such module....what can I do???...thanks for your
>help...


Install the module. If you have to do it in your own directory, the FAQ has 
the answer.

Bob Trieger
sowmaster@juicepigs.com       



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

Date: Thu, 25 Mar 1999 04:45:03 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to create a new directory
Message-Id: <36F9C147.E223EA19@home.com>

[posted & mailed]

Dale Sutcliffe wrote:
> 
> What is the command for creating a new directory from within a 
> perl/cgi script?
> 
> What is the command for deleting a directory?
> 
> What is the command for deleting a file?

Perl commands are called functions.  You can find out about them in the
perlfunc man page.  Search this page for words like "directory" and
"delete".

perldoc perlfunc

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 24 Mar 1999 17:10:05 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to interpolate subroutines in here-documents?
Message-Id: <trnbd7.lj3.ln@magna.metronet.com>

J. S. Jensen (jsjensen@Paramin.COM) wrote:

: How do I interpolate subroutine references within a here-document?

   A here-document is just a quoted string.

   So you interpolate things just as you would in a quoted string :-)

   And perl doesn't interpolate subroutine calls without
   resorting to some trickery.

   Perl FAQ, part 4:

      "How do I expand function calls in a string?"


: $a = "I";
: print <<EOF;
: hello, it is $a talking.
: EOF

: will appropriately substitute "me" where $a is.  Now how do I
: interpolate (substitute subroutines/functions into the here-doc?)


   See the FAQ above.


: sub aa {
:     print "I";
: }

   Calling the print() function to interpolate it, will cause
   this print() to be executed before the print() in your main::

   Which is why you get the 'I' as the first thing on the line.

   This subroutine should probably just be returning a string:

      sub aa { "I" }


: $aaref = \&aa();


   Stick __END__ here, or cut out the here-doc, and see what
   output you get. (with your version of sub aa() )

   Hmmmm. Looks like the subroutine is being _executed_
   by that line of code.

   Lose the parenthesis:

      $aaref = \&aa;


: print <<EOF;
: hello, it is $aaref talking.
: EOF

: will actually print:

: Ihello,it is SCALAR(0x80b6020) talking.

: Which kind of makes sense that perl is dumping the physical scalar
: reference.


   No, it should sound a little alarm.

   SCALAR it says?

   I was expecting it to be a CODE reference (which it will be
   once you lose the parenthesis).


: So:  How do I do this?  And how do I provide arguments to the
: subroutine?  use the {} somehow?


   Read the FAQ, then give up and copy the sub's return value 
   into a variable and interpolate the variable   :-)

      $aaref = aa();  # not a REFerence anymore...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 24 Mar 1999 18:24:24 -0700
From: Eric The Read <eric.schwartz@acm.org>
Subject: Re: never mind...
Message-Id: <xkfzp52icon.fsf@valdemar.col.hp.com>

sowmaster@juicepigs.com (Bob Trieger) writes:
> $var?do something:do something else;
> 
> will work but I am hoping somebody will tell me why it shouldn't be
> done this way.

It's hard to read, unless you document it extensively.

A surprisingly hard lesson to learn is: Unless it's time-critical, you're 
MUCH better off writing code for programmers instead of compilers.

-=Eric


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

Date: Wed, 24 Mar 1999 17:38:07 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: never mind...
Message-Id: <MPG.1163335978bbe5b69897c2@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <x7bthi9ykb.fsf@home.sysarch.com> on 24 Mar 1999 19:56:35 -
0500, Uri Guttman <uri@home.sysarch.com> says...
> >>>>> "BT" == Bob Trieger <sowmaster@juicepigs.com> writes:
>   BT> kwoody@citytel.net wrote:
>   >> if (not defined $var) {
>   >> do something
>   >> } else {
>   >> do someting else
>   >> } 
> 
>   BT> $var?do something:do something else;
>   BT> will work but I am hoping somebody will tell me why it shouldn't
>   BT> be done this way.
> 
> because that is a conditional expression which is meant to return a
> value. using it in a void context instead of a proper conditional is
> very bad style.
> 
> this is along the lines of never use map/grep in a void context. they
> will work but it is misleading and poor style.

All right.  I don't use it.  But I do use the following, quite often:

  $condition and do_something();

rather than

  do_something() if $condition;

when I want to emphasize the condition, not the consequent.  I might 
even write:

  $condition and do_something() or do_something_else();

provided do_something() always returns TRUE.

Isn't that very close to the

  $condition ? do_something() : do_something_else();

that we don't seem to like.

And we all do this, don't we:

  open FOO, 'bar' or die "Like a dog, because $!\n";

Now substitute '&&' for 'and' and '||' for 'or' in any of the above 
(fixing the priorities of the last one, of course), and see if that 
changes your feelings about anything.  Mine do.  I begin to feel as bad 
about them as about the ?:.

It may be that the short-circuit lowest-precedence logicals 'and' and 
'or' imply evaluation for flow control, while the conditional expression 
and the short-circuit higher-precedence logicals imply evaluation for a 
value, as you say -- because an assignment on the left means what it 
looks like.

Or is it just a question of TIMTOWTDI?

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 24 Mar 1999 16:19:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: never mind...
Message-Id: <hskbd7.lj3.ln@magna.metronet.com>

Keith Woodworth (kwoody@citytel.net) wrote:

: as is the case just about every time I post to this group or some other
: because after much fscking about trying to figure something out I figured
: it out...

: if (not defined $var) {
:    do something
: } else {
:      do someting else
: } 


   Or, if you like it better, you can write "if not" as "unless":

      unless (defined $var) {
         do something
      }
      else
         do something else
      }


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 25 Mar 1999 01:53:58 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: New @ Perl, Need a Good Tutorial
Message-Id: <36f99736$0$208@nntp1.ba.best.com>

Brian \"BNice\" Byrdsong <webmaster@bnicewd.com> wrote:
> Hi,
>     I'm new to Perl and would like to know if there are any good tutorials
> out there for beginners.  I have experience with html, javascript, asp and
> others but no Perl.  Very Eager to learn.

Try these:

http://www.lies.com/begperl/
http://www.netcat.co.uk/rob/perl/win32perltut.html

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: Wed, 24 Mar 1999 22:53:26 -0500
From: "Brian \"BNice\" Byrdsong" <webmaster@bnicewd.com>
Subject: Re: New @ Perl, Need a Good Tutorial
Message-Id: <7dcbd4$u11$1@camel29.mindspring.com>

Thanks for the links.  I also found one at this address,
http://www.digitaled.com/preview/oreilly/home.html

--
---------------------------------------------------------------------------
Go Play, BNice
The Un-Official Falcon 4.0 Command Center
http://www.bnicewd.com/falcon4/f4home.htm
---------------------------------------------------------------------------
John Callender <jbc@shell2.la.best.com> wrote in message
news:36f99736$0$208@nntp1.ba.best.com...
> Brian \"BNice\" Byrdsong <webmaster@bnicewd.com> wrote:
> > Hi,
> >     I'm new to Perl and would like to know if there are any good
tutorials
> > out there for beginners.  I have experience with html, javascript, asp
and
> > others but no Perl.  Very Eager to learn.
>
> Try these:
>
> http://www.lies.com/begperl/
> http://www.netcat.co.uk/rob/perl/win32perltut.html
>
> --
> John Callender
> jbc@west.net
> http://www.west.net/~jbc/




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

Date: Wed, 24 Mar 1999 16:29:14 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: New Bee Alert
Message-Id: <aflbd7.lj3.ln@magna.metronet.com>

Gabriel Richards (grichard@uci.edu) wrote:

: Be gentle with me, please...


   OK, but you should have put the subject of your post in
   the Subject: header of your posting. That is what it
   is there for.

   You are not discussing a programmer of small experience here...


: I'm reading in a text file which contains blank lines. 


   Where's your code?


: I would like Perl to
: print the file's contents literally, but Perl seems to ignore blank lines.


   Perl does not ignore blank lines.

   Where's your code?


: Is that right? 


   Nope.


: Why? 


   I don't know until ... well, until I see the code (hint hint)


: I assume I must add something like: if ($_ eq \n) {print
: "\n"}  ?


   Nope.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 25 Mar 1999 05:53:12 GMT
From: painter2000@Cybernex.Net (Joe)
Subject: Not possible in Perl??
Message-Id: <7dc8en$7a9$1@news.cybernex.net>

I wish to read in a file, add 10 to each byte in the file and write it back out
to another file. I checked PERL FAQ, asked PERL programmers, checked the FAQ and
I cannot find a simple answer on how to do such an elementary task. Is it
possible??

Help!
[our email address is 'painter2000@Cybernex.Net' but WITHOUT
 the numbers and with all letters lowercase. Very sorry about
 that but I am trying to avoid all those spammers.]



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

Date: Thu, 25 Mar 1999 05:13:44 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
Subject: Pass FileHandler in CGI
Message-Id: <Pine.GSO.4.03.9903250513010.21774-100000@virtue.csis.hku.hk>

        This is a question about PERL CGI...can a filehandler be passed by
hidden field???...If yes...how can I do that???...I have try to print
hidden but failed...is there any method to do so?...since I don't hope to
upload the file in the first page after I submit the form...I want to do
it in the following page...is that possible??? Thanks for your help...

REMARK: I am using CGI.pm

Regards,
Rollo



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

Date: Thu, 25 Mar 1999 09:28:36 +0800
From: Phil Mak <pmak@iname.com>
Subject: Re: Perl newbie problem:
Message-Id: <36F99143.DAEEA2C4@iname.com>

Try:

if (($line =~ /Stop now/) || ($line =~ /Stop again/);



Martin Fischer wrote:

> Perl newbie problem:
> I have to include a second condition for
> "last if .." in line No. 7.
> My "Perl Cookbook" is some 1.200 km away.
> If someone could help:
>
> 1:      $start=0;
> 2:      foreach $line (@page){
> 3:      print "$line\n" if($start == 1);
> 4:        if($line =~ /Global Appeal/){
> 5:          $start = 1;
> 6:        }
> 7:        last if($line =~ /Stop now/);
> 8:      }
>
> NEED: last if($line =~ /Stop now/ OR /Stop again/);
>                                   ^^
>                                   ??
>
> Thank you for your kind understanding.
> RGS
> Martin



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

Date: Thu, 25 Mar 1999 09:30:26 +0800
From: Phil Mak <pmak@iname.com>
Subject: Re: Perl newbie problem:
Message-Id: <36F991B2.B9E91D7C@iname.com>

Oops, I meant try:

if (($line =~ /Stop now/) || ($line =~ /Stop again/));

(forgot to add the final closing parenthesis last time)

Phil Mak wrote:

> Try:
>
> if (($line =~ /Stop now/) || ($line =~ /Stop again/);
>
> Martin Fischer wrote:
>
> > Perl newbie problem:
> > I have to include a second condition for
> > "last if .." in line No. 7.
> > My "Perl Cookbook" is some 1.200 km away.
> > If someone could help:
> >
> > 1:      $start=0;
> > 2:      foreach $line (@page){
> > 3:      print "$line\n" if($start == 1);
> > 4:        if($line =~ /Global Appeal/){
> > 5:          $start = 1;
> > 6:        }
> > 7:        last if($line =~ /Stop now/);
> > 8:      }
> >
> > NEED: last if($line =~ /Stop now/ OR /Stop again/);
> >                                   ^^
> >                                   ??
> >
> > Thank you for your kind understanding.
> > RGS
> > Martin



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

Date: Thu, 25 Mar 1999 03:53:08 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Perl newbie problem:
Message-Id: <7dcc19$4mr$2@birch.prod.itd.earthlink.net>

or even simpler:

last if ($line =~ /Stop (now|again)/);

pmak@iname.com wrote:

>if (($line =~ /Stop now/) || ($line =~ /Stop again/);
>

>Martin Fischer wrote:

>> NEED: last if($line =~ /Stop now/ OR /Stop again/);

Bob Trieger
sowmaster@juicepigs.com       



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

Date: Thu, 25 Mar 1999 02:41:49 GMT
From: rheinman@my-dejanews.com
Subject: regular expression
Message-Id: <7dc7pb$c43$1@nnrp1.dejanews.com>

Very new to Perl, and several hours on CPAN, this group, etc hasn't turned up
an answer to what is certainly a simple problem.

The following perl program is trying to read a file and replace occurences of
'brown' with 'red':

#! /opt/perl5/bin/perl -w
use diagnostics;
$value = "initialize";
open(FH, "< input.file") || die "cannot open input file: $!";
open(HH, "> output.file") || die "cannot open output file: $!";
$inline = <FH>;
while (defined($inline = <FH>)){
   $value = s/brown/red/g;
   select HH; # and write record
   print "$value \n";
}

produces the following errors:

Use of uninitialized value at ./perlit line 8, <FH> chunk 2 (#1)
(W) An undefined value was used as if it were already defined.  It was
interpreted as a "" or a 0, but maybe it was a mistake.  To suppress this
warning assign an initial value to your variables.

Use of uninitialized value at ./perlit line 8, <FH> chunk 3 (#1)
Use of uninitialized value at ./perlit line 8, <FH> chunk 4 (#1)
Use of uninitialized value at ./perlit line 8, <FH> chunk 5 (#1)


What I need to do eventually is to be able to do multiline replacements in a
file, ie:

this is sentence one
and this is the next sentence
of this paragraph

would become just:

of this paragraph


Thanks in advance for any help.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 25 Mar 1999 03:47:59 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: regular expression
Message-Id: <7dcbnn$4mr$1@birch.prod.itd.earthlink.net>

rheinman@my-dejanews.com wrote:
>Very new to Perl, and several hours on CPAN, this group, etc hasn't turned up
>an answer to what is certainly a simple problem.
>
>The following perl program is trying to read a file and replace occurences of
>'brown' with 'red':
>
>#! /opt/perl5/bin/perl -w
>use diagnostics;
>$value = "initialize";
>open(FH, "< input.file") || die "cannot open input file: $!";
>open(HH, "> output.file") || die "cannot open output file: $!";

print HH map { s/brown/red/g } <FH>;

or 

while (defined(<FH>)) {
        s/brown/red/g;
        print HH;
}




Bob Trieger
sowmaster@juicepigs.com       



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

Date: Thu, 25 Mar 1999 04:56:03 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: regular expression
Message-Id: <36F9C3DB.8F6F4974@home.com>

[posted & mailed]

Bob Trieger wrote:
> 
> while (defined(<FH>)) {
         ^^^^^^^
This is never necessary, not even in 5004.  It can always be written as

    while (<FH>) {
 .

In 5004 (but not 5003 or 5005) you must do this

    while( defined($line = <FH>) ) {

to silence warnings produced by

    while( $line = <FH> ) {
 
if you want to use that construct.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 25 Mar 1999 02:00:24 GMT
From: Kenneth Rose <kenrose@home.com>
Subject: Standard Deviation
Message-Id: <36F998A5.A7889D7A@home.com>

Hi all,

I was recently in a programming competition (today actually...we placed
first too...yay!).  Anyways, one of the problems was, given a list of
numbers in a file, to print out the standard deviation of the numbers
(they told us how to do this).  Off the top of my head, you had to find
the mean of the numbers, then find the sum of the squares of the
difference between the mean and each number in the list.  After all
that, divide the sum by the mean, and then take the square root of that
result! Oy! It took about 30 minutes to code.  But, I was thinking about
it afterwards, and I remembered the Perl libraries.  Sure enough, I
found stat.pl, which had standard deviation.  The only problem is, for
the life of me, I can't figure out how to use it.

Here's what I have:

require 'stat.pl';
@ary = stat(foo);
$st_dev = @ary[$ST_DEV];

OK, WTF is foo? I see this everywhere!
Anyways, let's say that I have the following.

@nums = (3, 2, 4, 1);


Actually, I don't care how long the list is.  How do I find the standard
deviation of @nums (using the stat.pl file)?

Thanks to anyone who can help.

/<en


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

Date: Thu, 25 Mar 1999 00:54:33 GMT
From: jatgal@my-dejanews.com
Subject: String manipulation
Message-Id: <7dc1g5$6ro$1@nnrp1.dejanews.com>

Hi guys,	I 'm trying to manipulate following string 
user1,user@domain.com user2,user2@domain.com user3,user3@domain.com ...so on
 ..

What I need to do is categorize it as following
             Name        Email
             user1        user@domain.com
             user2         user2@domain.com
             user3         user3@domain.com

right now I'm using while loop and split function to get Name and email ..
however I'm not being able to manipulate the space as a next line or next
element of array. Please help me out with this, your help would be appreciated
:)

Thanks in advance
jatgirl@yahoo.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 25 Mar 1999 00:59:31 GMT
From: jatgal@my-dejanews.com
Subject: String manipulation
Message-Id: <7dc1pe$774$1@nnrp1.dejanews.com>

Hi guys
    I'm trying to manipulate following string
user1, user1@domain.com use2,user2@domain.com user3,user3@domain.com ..so on..

what I need to do is break the string as following
             Name                Email
             user1               user1@domain.com
              user2               user2@domain.com
          so on ...

I got the part where I can split the Name and Email, however I'm having
trouble in manipulating space as a sign of next element in an array.. any
idea how that can be done? or am I doing it wrong?

Thanks
Jatgal

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 25 Mar 1999 03:36:34 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: String manipulation
Message-Id: <7dcb2a$37v$1@birch.prod.itd.earthlink.net>

In article <7dc1pe$774$1@nnrp1.dejanews.com>, jatgal@my-dejanews.com wrote:
>Hi guys
>    I'm trying to manipulate following string
>user1, user1@domain.com use2,user2@domain.com user3,user3@domain.com ..so on..
>
>what I need to do is break the string as following
>             Name                Email
>             user1               user1@domain.com
>              user2               user2@domain.com
>          so on ...
>
>I got the part where I can split the Name and Email, however I'm having
>trouble in manipulating space as a sign of next element in an array.. any
>idea how that can be done? or am I doing it wrong?

Split your input line into an array at the spaces.
Then split each element of the array into key and value of a hash at the 
commas.

This is how I'd do it, but I'm sure you will get varying examples:

#!/usr/bin/perl -w
use strict;
my $var = q(user1, user1@domain.com use2,user2@domain.com 
user3,user3@domain.com);
my @array = split /\s+/, $var;
my %hash = map { split /,/ } @array;
print map { "$_\t$hash{$_}\n" } keys %hash;


Good luck

Bob Trieger
sowmaster@juicepigs.com       



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

Date: Wed, 24 Mar 1999 23:44:45 -0300
From: "Alan" <alan@empresa.com>
Subject: Re: Web Mail
Message-Id: <7dc80f$9ih$1@srv4-poa.nutecnet.com.br>

Michael,

> Does anyone have Perl script for making Web mail under FreeBSD? Or where
to
> find it?

There are many options at the webmail category at www.cgi-resources.com .

BTW, I think you should post questions like this to a cgi newsgroup instead
of perl-misc.

Alan Pogrebinschi




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

Date: Wed, 24 Mar 1999 22:15:21 -0600
From: Barry Wegman <bwegman@HiWAAY.net>
Subject: Re: What isn't getting reset?
Message-Id: <0efaZYnd#GA.202@pet.hiwaay.net>

Oops!!!  When I originally posed my question, I was extracting
what I thought were the relevant lines of code, but I didn't
actually test it.  It turns out that I overlooked the critical
line of code that was actually causing the anomaly!  Sorry!!!!
This (below) should make more sense, but my question still stands.

$s = "This is a test of the American Broadcasting Service.";
$s =~ /([tT]\S{1,})/g;  ## NOTE: Global match, but not an array context.
@matches = ($s =~ /([tT]\S{1,})/g);
print "Matched: ", join(", ", @matches), "\n";
@matches = ($s =~ /([tT]\S{1,})/g);
print "Matched: ", join(", ", @matches), "\n";

O.K., I think that's it, and the output is:

Matched: test, the, ting
Matched: This, test, the, ting

Something doesn't get reset prior to using the first array context,
otherwise the two lines of output would be identical -- because the
code that produces them is identical.

As I say, I'm a newbie, so forgive what may be a stupid question,
but what isn't being reset and how can I reset it?


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

Date: 25 Mar 1999 04:51:19 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: What isn't getting reset?
Message-Id: <slrn7fjg67.ihl.sholden@pgrad.cs.usyd.edu.au>

On Wed, 24 Mar 1999 22:15:21 -0600, Barry Wegman <bwegman@HiWAAY.net> wrote:
>Oops!!!  When I originally posed my question, I was extracting
>what I thought were the relevant lines of code, but I didn't
>actually test it.  It turns out that I overlooked the critical
>line of code that was actually causing the anomaly!  Sorry!!!!
>This (below) should make more sense, but my question still stands.
>
>$s = "This is a test of the American Broadcasting Service.";
>$s =~ /([tT]\S{1,})/g;  ## NOTE: Global match, but not an array context.
>@matches = ($s =~ /([tT]\S{1,})/g);
>print "Matched: ", join(", ", @matches), "\n";
>@matches = ($s =~ /([tT]\S{1,})/g);
>print "Matched: ", join(", ", @matches), "\n";
>
>O.K., I think that's it, and the output is:
>
>Matched: test, the, ting
>Matched: This, test, the, ting
>
>Something doesn't get reset prior to using the first array context,
>otherwise the two lines of output would be identical -- because the
>code that produces them is identical.

perldoc perlop :
m/PATTERN/cgimosx
 ...
               In scalar context, each execution of m//g finds
               the next match, returning TRUE if it matches, and
               FALSE if there is no further match.  The position
               after the last match can be read or set using the
               pos() function; see the pos entry in the perlfunc
               manpage.   A failed match normally resets the
               search position to the beginning of the string,
               but you can avoid that by adding the /c modifier
               (e.g. m//gc).  Modifying the target string also
               resets the search position.


It doesn't specifically say (that I can see anyway - although I didn't
look very hard) what happens when using /g in a scalar and then a list
context. But it would appear that the list context just starts where the
scalar context left off (which is what another scalar context use would
do). This makes sense to me, but I couldn't find a specific statement of
it in the docs.

-- 
Sam

You can write Perl programs that resemble sed, or awk, or C, or Lisp, or
Python. This is Officially Okay in Perl culture.
	--Larry Wall


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

Date: Wed, 24 Mar 1999 20:00:24 -0700
From: Rodney Clang <rclang@rclangtos.lewan.com>
Subject: What to use for X gui?
Message-Id: <922330897.672771372@news-2.csn.org>

Is there anyone doing X apps in Perl out there? I am attempting Tk and all
looks OK so far, ...  but I keep seeing references to PerlQT and Perl
XForms and have no clue (obviously). My users are Linux workstations with 
KDE as desktop. That's primarily why I'm interested in the benefits of
PerlQT.   I make nothing out of the FAQ or anything else as far as reasons,
features, and what-to-use-where when writing X applications.

What is being used???

Thanks
Rod



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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5221
**************************************

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