[23110] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5331 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 18:05:47 2003

Date: Thu, 7 Aug 2003 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 7 Aug 2003     Volume: 10 Number: 5331

Today's topics:
        Any way to stop a kill? <mdudley@execonn.com>
    Re: Any way to stop a kill? <someone@somewhere.nl>
    Re: Any way to stop a kill? <mdudley@execonn.com>
    Re: Anyone build the Berkeley DBXML library for AS and  (Claus)
        DBI suddenly not working... <jim.bloggs@eudoramail.com>
    Re: extract from html <brian_helterline@hp.com>
    Re: Final "Flocking" Script <flavell@mail.cern.ch>
    Re: Final "Flocking" Script <flavell@mail.cern.ch>
        grep <anders@XXX.redakula.net>
    Re: grep <grazz@pobox.com>
    Re: grep <mpapec@yahoo.com>
    Re: grep <ndronen@io.frii.com>
    Re: grep <trammell+usenet@hypersloth.invalid>
    Re: grep <pinyaj@rpi.edu>
        help needed making unicode entities <jidanni@jidanni.org>
        help with regular expression (the dude)
    Re: help with regular expression <noreply@gunnar.cc>
    Re: nested HTML parsing (Tad McClellan)
    Re: Perl Math Syntax (remove the obvious)
    Re: Perl Math Syntax <krahnj@acm.org>
    Re: Replace a word if its not in an html tag (Tad McClellan)
    Re: Replace a word if its not in an html tag <pinyaj@rpi.edu>
    Re: sort question (Tad McClellan)
        Tie::Extrahash - functional ? (K. L. Estes)
    Re: Tie::Extrahash - functional ? <grazz@pobox.com>
    Re: very simple question <minceme@start.no>
    Re: What do you think of my first "JAPH"? <spamblock@junkmail.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 07 Aug 2003 17:01:33 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: Any way to stop a kill?
Message-Id: <3F32BE2C.48694D68@execonn.com>

After a customer orders something, emails get sent to me and the
customer by a perl script.  Lately the server has been loaded more
heavily than normal, and the sendmail is taking a while to complete and
for control to return back to perl.  Unfortunatly some customers are
either browsing elsewhere, or hitting stop while the sendmail is sending
the email, and a kill is generated which kills the emails to me and the
customer.

Is there any way to keep the process from being killed before the emails
are sent out?  This is a rather serious problem for me right now.

Thanks,

Marshall



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

Date: Thu, 7 Aug 2003 23:42:02 +0200
From: "Stefan" <someone@somewhere.nl>
Subject: Re: Any way to stop a kill?
Message-Id: <3f32c702$0$31062$e4fe514c@dreader4.news.xs4all.nl>

"Marshall Dudley" <mdudley@execonn.com> schreef in bericht
news:3F32BE2C.48694D68@execonn.com...
> After a customer orders something, emails get sent to me and the
> customer by a perl script.  Lately the server has been loaded more
> heavily than normal, and the sendmail is taking a while to complete and
> for control to return back to perl.  Unfortunatly some customers are
> either browsing elsewhere, or hitting stop while the sendmail is sending
> the email, and a kill is generated which kills the emails to me and the
> customer.
>
> Is there any way to keep the process from being killed before the emails
> are sent out?  This is a rather serious problem for me right now.
>
> Thanks,
>
> Marshall


This seems more like a design-issue to me. Would it be a problem to do some
queueing yourself ?  As in ... just write a would-be email to a file and let
a different mailer-daemon do the actual sending. This way, your customer
gets a quick response and you're sure the email is on its way.

BTW, you could try to catch / ignore signals by using $SIG{}  -  for example
$SIG{EXIT}.  See  "man signal" for a description, and/or search
www.perldoc.com for the details.

Bye,
Stefan





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

Date: Thu, 07 Aug 2003 17:34:34 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: Re: Any way to stop a kill?
Message-Id: <3F32C5E9.24509202@execonn.com>

That's not a bad idea, then use a 1 minute cron to send the emails.

Thanks,

Marshall

Stefan wrote:

> "Marshall Dudley" <mdudley@execonn.com> schreef in bericht
> news:3F32BE2C.48694D68@execonn.com...
> > After a customer orders something, emails get sent to me and the
> > customer by a perl script.  Lately the server has been loaded more
> > heavily than normal, and the sendmail is taking a while to complete and
> > for control to return back to perl.  Unfortunatly some customers are
> > either browsing elsewhere, or hitting stop while the sendmail is sending
> > the email, and a kill is generated which kills the emails to me and the
> > customer.
> >
> > Is there any way to keep the process from being killed before the emails
> > are sent out?  This is a rather serious problem for me right now.
> >
> > Thanks,
> >
> > Marshall
>
> This seems more like a design-issue to me. Would it be a problem to do some
> queueing yourself ?  As in ... just write a would-be email to a file and let
> a different mailer-daemon do the actual sending. This way, your customer
> gets a quick response and you're sure the email is on its way.
>
> BTW, you could try to catch / ignore signals by using $SIG{}  -  for example
> $SIG{EXIT}.  See  "man signal" for a description, and/or search
> www.perldoc.com for the details.
>
> Bye,
> Stefan



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

Date: 7 Aug 2003 14:30:58 -0700
From: clausd90@hotmail.com (Claus)
Subject: Re: Anyone build the Berkeley DBXML library for AS and Windows?
Message-Id: <a50d9d5c.0308071330.195d8734@posting.google.com>

"Bob X" <bobx@linuxmail.org> wrote in message news:<30kXa.9686$gi.4821527@news2.news.adelphia.net>...
> According to the docs that is not the case. It has to be built with the same
> compiler Perl was. Since I use ActiveState that means VC++.
> 

You're absolutely right - and it doesn't build out of the box with
ActiveState perls (5.6.* OR 5.8.*). I haven't seen any binaries so I'm
working on the build instead.

There seems to be some problems with some generic method names that
are being expanded as macros. I haven't been able to build dbxml on mu
linux box either so I couldn't tell you if it's just the perl module
that's broken in general.

Claus


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

Date: Thu, 7 Aug 2003 19:35:13 +0100
From: "doofus" <jim.bloggs@eudoramail.com>
Subject: DBI suddenly not working...
Message-Id: <bgu654$qngd8$1@ID-150435.news.uni-berlin.de>

HELP!

If I put the line 'use DBI' anywhere in my program it gives up and
produces no out put. So, for example, the prog

 print "jkl";
 use DBI;

stops and has a think for about a half second and then exits silently.
It is evidently loading DBI and then totally going nuts.

Furthermore, if I copy the DBI.pm from c:\perl\site\lib into current
dir, and then rename the original in the libraries, the above script
works fine.

Isn't that really weird?

I think my Win2k box has been high on something mind altering for about
a couple of months now.

But I have this requirement to do a really urgent database job and now I
really need my MySQL connectivity to code and test in perl/MySQL.

I know there's probably not much I can do, but if anybody happens to
know windows and has a sense of what it could be, please help.

This system was happily interacting with MySQL about a couple of months
ago. Don't know what's happened.

Thanks for any reply.

best,

doofus

**************************************************************

PS. Here's some output. Don't know if it will help. Sorry.

C:\scripts\trial>perl -e "print 99; use DBI";
jkl99
C:\scripts\trial>perl -e "print 99; use DBI";

C:\scripts\trial>perl -e "print 99; use DBI";
jkl99
C:\scripts\trial>perl -e "print 99; use DBI";

C:\scripts\trial>perl -v

This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2002, Larry Wall

Binary build 806 provided by ActiveState Corp.
http://www.ActiveState.com
Built 00:45:44 Mar 31 2003


Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.


C:\scripts\trial>




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

Date: Thu, 7 Aug 2003 13:38:04 -0700
From: "Brian Helterline" <brian_helterline@hp.com>
Subject: Re: extract from html
Message-Id: <3f32be8f$1@usenet01.boi.hp.com>


"Lydia Shawn" <apfeloma@hotmail.com> wrote in message
news:1240b4dc.0308051647.685dde59@posting.google.com...
> hi,
> how can i extract the number between text1 and text2 in input.html
> only the first time it occurs ignoring the rest?
> preferably input.html would be a URL that stops downloading once a
> match has occured, that would save a lot of bandwidth..
> i guess html::parser would provide an option to work with a file while
> it's downloading (?)

Take a look at the lwp-download script (in your perl bin directory)
as an example of a program that incrementally downloads a URL.
You can then search the contents for your text1 and text2 and stop if found.

The script uses LWP::UserAgent to do the download.

--
brian




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

Date: Thu, 7 Aug 2003 23:28:38 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Final "Flocking" Script
Message-Id: <Pine.LNX.4.53.0308072320460.13165@lxplus002.cern.ch>

On Wed, Aug 6, ctcgag@hotmail.com inscribed on the eternal scroll:

> > I don't know Tad's motivation, but: it can expose details of the
> > internals of your scripts to an intruder.  The same goes for exposing
> > warnings within the browser window.
>
> In my particular case, all the users of the scripts are inside our
> firewall.

They do say that the most dangerous attackers are those inside the
organisation.  I'm sure that's right in some places, even if that
doesn't accord with my own experience.

> Any of those users could just walk into my office and shove
> an icepick in my ear.  So if they've gone bad and are on the attack, CGI
> scripts are the least of my worries. :)

Some intruders aim to minimise the mess.  A few years back, at the
home campus, we had a hacker into our system for a couple of months
before we became aware of him (and, as far as we could diagnose
afterwards, we only became aware of him as an accident of
investigating a more-obvious attack).



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

Date: Thu, 7 Aug 2003 23:32:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Final "Flocking" Script
Message-Id: <Pine.LNX.4.53.0308072330060.13165@lxplus002.cern.ch>

On Tue, Aug 5, Gunnar Hjalmarsson inscribed on the eternal scroll:

> Alan J. Flavell wrote:

> > Of course, it also gives an unprofessional impression if it happens
> > to a bona fide user. Ideally you should cover all known failure
> > modes at development time, and supply user-friendly responses for
> > them, rather than exposing the end-users to what are _supposed_ to
> > be your internal diagnostics.
>
> I'm distributing a CGI script to largely novise users (mostly on
> shared hosting accounts without access to the error logs...),

I'm afraid you misinterpreted my meaning of the term 'user' here.

Naturally, those who are installing the script should get these kind
of diagnostics until the scripts are working.


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

Date: Thu, 07 Aug 2003 22:56:54 +0200
From: "Anders Bystrup" <anders@XXX.redakula.net>
Subject: grep
Message-Id: <pan.2003.08.07.20.56.53.773599@XXX.redakula.net>

Hi.

I'm trying to make the following work:

$index = 0;
foreach (@mac){
	if (grep /$_/, $legalmacs !~ 0){
	push @violators, join('',@mac[$index]," found on $switch port
@port[$index]\n"
$index++;
}
$index++;
}

The point is that i have a list ($legalmacs) that contains a list of mac
addresses permitted on our network. @mac contains mac addresses actually
found on the network (along with an acompanying @port of the port number
on which the mac was found). I need to check whether a @mac is in the
list $legalmacs - and if not add it and the port to @violators.
When i use the code above i simply get all the macs found...

I probably misunderstood something basic as usual - anyone with an idea to
make it work?

/Anders


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

Date: Thu, 07 Aug 2003 21:33:00 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: grep
Message-Id: <gAzYa.638$014.322@nwrdny02.gnilink.net>

Anders Bystrup <anders@xxx.redakula.net> wrote:
> The point is that i have a list ($legalmacs) that contains a list of mac
> addresses permitted on our network. @mac contains mac addresses actually
> found on the network (along with an acompanying @port of the port number
> on which the mac was found). I need to check whether a @mac is in the
> list $legalmacs - and if not add it and the port to @violators.

I might set it up like this:

    my %ok  = map { $_ => 1 } qw{
        00:00:00:00:00:01
        00:00:00:00:00:03
    };

    my @bad = map {
        my ($mac, $port) = split;
        $ok{$mac} ? () : [$mac,$port];
    } <DATA>;
    
    for (@bad) {
        printf "%s found on port %s\n", @$_;
    }

    __END__
    00:00:00:00:00:01 $port
    00:00:00:00:00:02 $port
    00:00:00:00:00:03 $port
    00:00:00:00:00:04 $port

The main point is: use a hash instead of repeated grepping.

-- 
Steve


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

Date: Thu, 07 Aug 2003 23:31:51 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: grep
Message-Id: <jrg5jvgjhfbhl117bh553thr688bojkcum@4ax.com>

X-Ftn-To: Anders Bystrup 

"Anders Bystrup" <anders@XXX.redakula.net> wrote:
>Hi.
>
>I'm trying to make the following work:
>
>$index = 0;
>foreach (@mac){
>	if (grep /$_/, $legalmacs !~ 0){

I'm curious how does $legalmacs looks, why are you using grep here, and why
you're using regular exp. operator on 0?

>	push @violators, join('',@mac[$index]," found on $switch port
>@port[$index]\n"
>$index++;
>}
>$index++;
>}

Is this your actual code? You have two $index increments.



-- 
Matija


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

Date: 07 Aug 2003 21:36:36 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: grep
Message-Id: <3f32c664$0$191$75868355@news.frii.net>

Anders Bystrup <anders@xxx.redakula.net> wrote:
AB> Hi.

AB> I'm trying to make the following work:

AB> $index = 0;
AB> foreach (@mac){
AB>         if (grep /$_/, $legalmacs !~ 0){

I believe this evaluates to true if $_ is a substring of $legalmacs,
and $legalmacs contains a 0.  That's not what you want.  The second
argument to grep is a LIST, so make $legalmacs an array.  See below.

AB>         push @violators, join('',@mac[$index]," found on $switch port
AB> @port[$index]\n"
AB> $index++;
AB> }
AB> $index++;
AB> }


AB> The point is that i have a list ($legalmacs) that contains a list of mac
AB> addresses permitted on our network. @mac contains mac addresses actually
AB> found on the network (along with an acompanying @port of the port number
AB> on which the mac was found). I need to check whether a @mac is in the
AB> list $legalmacs - and if not add it and the port to @violators.
AB> When i use the code above i simply get all the macs found...

AB> I probably misunderstood something basic as usual - anyone with an idea to
AB> make it work?

Untested, but I think this is closer to what you want.

my @legalmacs = qw(...); # list of legal MAC addresses
my (@macs, @violators);
my %ports; # keyed by MAC address

# Populate @macs with all MAC addresses found on the network.

for my $mac (@macs) {
	unless (grep /\b$mac\b/, @legalmacs) {
		push @violators, $mac; # port number can be retrieved from %ports later
	}
}

Regards,

Nicholas

-- 
"Why shouldn't I top-post?"    http://www.aglami.com/tpfaq.html
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

Date: Thu, 7 Aug 2003 21:35:38 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: grep
Message-Id: <slrnbj5hha.gf3.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Thu, 07 Aug 2003 22:56:54 +0200, Anders Bystrup
<anders@XXX.redakula.net> wrote:
> I'm trying to make the following work:
>  
> $index = 0;
> foreach (@mac){
>  	if (grep /$_/, $legalmacs !~ 0){
>  	push @violators, join('',@mac[$index]," found on $switch port
> @port[$index]\n"
> $index++;
> }
> $index++;
> }
> The point is that i have a list ($legalmacs) that contains a list of
> mac addresses permitted on our network.

$legalmacs looks like a scalar to me.  Maybe you mean @legalmacs?

> @mac contains mac addresses actually found on the network (along with
> an acompanying @port of the port number on which the mac was found). I
> need to check whether a @mac is in the list $legalmacs - and if not
> add it and the port to @violators. When i use the code above i simply
> get all the macs found...
>  
> I probably misunderstood something basic as usual - anyone with an
> idea to make it work?
>  

If you're doing lookups, you probably want a hash instead
of using grep on a list:

(untested)

 my %x = map { $_, 1 } @legalmacs;
 my %p = map { $mac[$_], $port[$_] } 0 .. $#mac;

 my @bad = grep !$x{$_}, @macs;
 for (@bad) { print "bad mac $_ on port $p{$_}\n" }

This breaks if you have more than one port per mac.  In that
case you want something more complicated when constructing %p.



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

Date: Thu, 7 Aug 2003 17:44:50 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Anders Bystrup <anders@redakula.net>
Subject: Re: grep
Message-Id: <Pine.SGI.3.96.1030807172225.511941C-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On Thu, 7 Aug 2003, Anders Bystrup wrote:

>$index = 0;
>foreach (@mac){
>  if (grep /$_/, $legalmacs !~ 0){
>    push @violators, join('',@mac[$index]," found on $switch port
>    @port[$index]\n"
>    $index++;
>  }
>  $index++;
>}

You're missing a ); in there, I think... and why are you incrementing
$index twice?  And @array[$idx] is better written as $array[$idx].  And
you don't need to join with ''... you can just make a regular string.

The bigger problem is that grep() line.  I have no idea what that's trying
to do.

>The point is that i have a list ($legalmacs) that contains a list of mac
>addresses permitted on our network. @mac contains mac addresses actually
>found on the network (along with an acompanying @port of the port number
>on which the mac was found). I need to check whether a @mac is in the
>list $legalmacs - and if not add it and the port to @violators.
>When i use the code above i simply get all the macs found...

You don't have a "list" in $legalmacs, because $legalmacs is a scalar.  So
grep() isn't for you.  I think what you want to do is:

  if ($legalmacs =~ /$_/) { ... }

which looks for $_ in $legalmacs.  You're probably better off using a
hash, though.

I'd need to see more code/examples before I knew how better to help you.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Fri, 08 Aug 2003 05:07:29 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: help needed making unicode entities
Message-Id: <87he4tyy5q.fsf@jidanni.org>

Why does
  use HTML::Entities; use utf8; print HTML::Entities::encode_entities_numeric("\xE7\xA9\x8D");
print
  &#xE7;&#xA9;&#x8D;
i.e. three entities, instead of one?

Must I use locale;?  In any particular way?

Am I to blame?

Those three bytes represent a Chinese character.

Must I explore pack()?

Not only do I wish to convert one unicode character (three bytes), but
also a whole string of them.

$ perl -v
This is perl, v5.8.0

perldoc Encode's "The UTF-8 flag" holds the answer? And that is what?

perldoc perluniintro isn't helping.

All I want to do is
$ echo '[unicode string]'|perl -plwe 'something;'
and get
&#22823;&#21407;&#38596;&#39340;...
Is that to much to ask?


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

Date: 7 Aug 2003 14:14:55 -0700
From: jason@memorycheaper.net (the dude)
Subject: help with regular expression
Message-Id: <339606c5.0308071314.7dde9134@posting.google.com>

im kind of a newbie to regular expressions, and i am stuck.

i need to write one that will search for and display:

the letters "ABA", the text in between, until it finds the next
instance of "ABA" or "000"

So if I had the text
-----------
alsdfjadslfjasf
ABA001 abcdefg hijklmno 
aaaaaa bbbbbb
ABA002
-----------

I would need it to find
----------------------
ABA001 abcdefg hijklmno 
aaaaaa bbbbbb
------------------------

so I could write the result to a database

thanks

the dude


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

Date: Thu, 07 Aug 2003 23:23:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: help with regular expression
Message-Id: <bgufua$s63at$1@ID-184292.news.uni-berlin.de>

the dude wrote:
> im kind of a newbie to regular expressions, and i am stuck.

"Stuck"? Please show us what you have tried. You tried _something_, 
didn't you?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 7 Aug 2003 15:45:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: nested HTML parsing
Message-Id: <slrnbj5ejn.45n.tadmc@magna.augustmail.com>

Ted Zlatanov <tzz@lifelogs.com> wrote:

> invalid HTML.


There really is no such thing.

If it is invalid, then it is not HTML at all, just some angle-brackety text.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 07 Aug 2003 19:46:05 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: Perl Math Syntax
Message-Id: <10yYa.89153$3o3.6152071@bgtnsc05-news.ops.worldnet.att.net>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3F31B5D3.E0C7FE40@acm.org...
| --Rick wrote:
| >
| > "John W. Krahn" <krahnj@acm.org> wrote in message
| > news:3F2F59BD.A1D21C05@acm.org...
| > | \"Dandy\" Randy wrote:
| > | >
| > | > Needs some help getting a ... well ... pretty basic math
script
| > | > working but the solution eludes me .... I have a text file
called
| > | > opened.txt ... it contains the following single line data:
| > | >
| > | > 2000|0|0
| > | >
| > | > What I am looking to do is when the script is run, I would
like
| > | > the second value to increase by 1 .... kind of like this:
| > |
| > | #!/usr/bin/perl -p
| > |
| > | BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
| > | s/|(\d+)|/|@{[$1+1]}|/
| > |
| > | __END__
| >
| > I couldn't figure out how this one was supposed to work, so I
tried it
| > and couldn't really fix it.
| >
<snip>
|
| Sorry, I forgot to backwack the veritcal bars.  :-)
|
| #!/usr/bin/perl -p
|
| BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
| s/\|(\d+)\|/|@{[$1+1]}|/
|
| __END__
|

OK, I'm not so sleepy this time.

I did figure out that the pipe characters needed to be escaped.  What
I was really meaning to ask (and I asked poorly) was this.  I could
not understand the idiom you used to get addition into the replacement
string nor could I make it work (surprise!).  What I got instead was a
printed addition problem.  Could you explain it or point me to the
right place in the documentation?

Thanks again.

--Rick




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

Date: Thu, 07 Aug 2003 20:19:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Math Syntax
Message-Id: <3F32B43C.D47B69B8@acm.org>

--Rick wrote:
> 
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3F31B5D3.E0C7FE40@acm.org...
> |
> | Sorry, I forgot to backwack the veritcal bars.  :-)
> |
> | #!/usr/bin/perl -p
> |
> | BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
> | s/\|(\d+)\|/|@{[$1+1]}|/
> 
> OK, I'm not so sleepy this time.
> 
> I did figure out that the pipe characters needed to be escaped.  What
> I was really meaning to ask (and I asked poorly) was this.  I could
> not understand the idiom you used to get addition into the replacement
> string nor could I make it work (surprise!).  What I got instead was a
> printed addition problem.  Could you explain it or point me to the
> right place in the documentation?

Well, it works fine for me.  :-)

$ perl -le'
$_ = "1234|12|5678";
print;                   
s/\|(\d+)\|/|@{[$1+1]}|/;
print;
'
1234|12|5678
1234|13|5678


The "@{[  ]}" idiom is described in the FAQ:

perldoc -q "How do I expand function calls in a string"



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 7 Aug 2003 15:41:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replace a word if its not in an html tag
Message-Id: <slrnbj5ec7.45n.tadmc@magna.augustmail.com>

JS Bangs <jaspax@u.washington.edu> wrote:
> Tad McClellan sikyal:


>>     s/([^\/|<])\bbody\b/$1/g


> How *does* one assert a negative group of multiple
> characters?


With a "negative look-behind assertion" (perlre.pod):

   /(?<!  <\/?  body )/x


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 7 Aug 2003 17:21:17 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Replace a word if its not in an html tag
Message-Id: <Pine.SGI.3.96.1030807172011.511941B-100000@vcmr-64.server.rpi.edu>

On Thu, 7 Aug 2003, Tad McClellan wrote:

>JS Bangs <jaspax@u.washington.edu> wrote:
>> Tad McClellan sikyal:
>
>
>>>     s/([^\/|<])\bbody\b/$1/g
>
>
>> How *does* one assert a negative group of multiple
>> characters?
>
>
>With a "negative look-behind assertion" (perlre.pod):
>
>   /(?<!  <\/?  body )/x

Last time I checked, variable-width patterns weren't allowed in a
look-behind.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Thu, 7 Aug 2003 15:48:39 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sort question
Message-Id: <slrnbj5ep7.45n.tadmc@magna.augustmail.com>

ZZT <a@b.c> wrote:

> Now I would like to sort in a way that DD and DDD are joined and treated 
> as a 5 digit numeric value,


   perldoc -q sort


> Can you help me a little bit?


Sure.

Show us the code you have so far, and we will help you fix it.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 7 Aug 2003 13:36:06 -0700
From: klestes@nmhs.net (K. L. Estes)
Subject: Tie::Extrahash - functional ?
Message-Id: <5b63b266.0308071236.18227f76@posting.google.com>

Hello,

while trying to figure out how to tie hashes, I messed around with
Tie::Hash and coulnd't get the following code to work :

package NewExtraHash;

    require Tie::Hash;
    @ISA = (Tie::ExtraHash);
    # All methods provided by default, define only those needing
overrides
    # Accessors access the storage in %{$_[0][0]};
    # TIEHANDLE should return an array reference with the first
element being
    # the reference to the actual storage 
    sub DELETE { 
      $_[0][1]->('del', $_[0][0], $_[1]); # Call the report writer
      delete $_[0][0]->{$_[1]};  #  $_[0]->SUPER::DELETE($_[1]) }
      }


package main;

    tie %new_hash, 'NewHash';
    tie %new_std_hash, 'NewStdHash';
    tie %new_extra_hash, 'NewExtraHash';

sub {warn "Doing \U$_[1]\E of $_[2].\n"};  
                                           

This code was meticously stolen from
http://www.perldoc.com/perl5.8.0/lib/Tie/Hash.html and corrected for
stupid syntax mistakes.

Anyone have a clue what I/whoever am doing wrong ?

thanks,
K. L.


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

Date: Thu, 07 Aug 2003 20:44:53 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Tie::Extrahash - functional ?
Message-Id: <9TyYa.492$014.172@nwrdny02.gnilink.net>

K. L. Estes <klestes@nmhs.net> wrote:
> package main;
> 
>     tie %new_hash, 'NewHash';
>     tie %new_std_hash, 'NewStdHash';
>     tie %new_extra_hash, 'NewExtraHash';
> 
> sub {warn "Doing \U$_[1]\E of $_[2].\n"};  
> 
> This code was meticously stolen from
> http://www.perldoc.com/perl5.8.0/lib/Tie/Hash.html and corrected for
> stupid syntax mistakes.

You got a little too eager with that red pencil; the last lines
were correct like this:

     tie %new_extra_hash, 'NewExtraHash',
         sub {warn "Doing \U$_[1]\E of $_[2].\n"};  

Except that it should probably have been "Doing \U$_[0]\E".

-- 
Steve


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

Date: Thu, 7 Aug 2003 19:32:03 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: very simple question
Message-Id: <bgu9fi$7s0$1@troll.powertech.no>

Abigail <abigail@abigail.nl> wrote:
> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote on MMMDCXXVIII September
> &&  phase00@hotmail.com (Monkey Boy) wrote in 
> && > How do I initialise (assign value of 0) to multiple variables without
> && > having to manually specify each one.
> && > 
> && > ie. 
> && > $a = 0;
> && > $b = 0;
> && > $c = 0;
> && > $d = 0; 
> && > ..etc
> &&  
> &&  As with many things in Perl, there are several ways:
> &&  
> &&      $a = $b = $c = $d = 0;
> &&  
> &&      ($a, $b, $c, $d) = (0, 0, 0, 0);
> &&  
> &&      $_ = 0  for $a, $b, $c, $d;
> &&  
> &&  And probably others. 
>
> $$_ = 0 for qw /a b c d/;
>
> eval "\$$_ = 0" for qw /a b c d/;

What about dropping the qw?

$$_ = 0 for a..d;

map $$_ = 0, a..d;

-- 
Vlad


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

Date: Thu, 7 Aug 2003 11:47:43 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: What do you think of my first "JAPH"?
Message-Id: <vj57qjt2d49lf2@corp.supernews.com>

Thank-you to all who offered tips and suggestions on refining my first JAPH.
Here it is in its most recent form:

perl -e '@rt{qw$.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. ---
 .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .-.-.- |
!$}=(A..Z,q$.$,$",$/);print $rt{$_} for split/\s+/,".--- ..- ... - |
 .- -. --- - .... . .-. | .--. . .-. .-.. | .... .- -.-. -.- . .-. .-.-.-
!";'

It's now listed under the Obfuscation section at www.perlmonks.org.

It's been fun, and a learning experience.

I had one suggestion that I only define morse for those letters I use.  The
problem with that is that I like that this code represents a complete alpha
morse translator, not a crippled one.  And also, by enumerating only those
letters I use, I end up doing away with slices, and de-obfuscate the thing.
This seems cleaner and broader to me.

Thanks again,

Dave




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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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