[18274] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 442 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 8 03:06:00 2001

Date: Thu, 8 Mar 2001 00:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984038713-v10-i442@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 8 Mar 2001     Volume: 10 Number: 442

Today's topics:
    Re: (Linux beginner) How to de-install and re-install P <godoy@conectiva.com>
        alarm() syntax <ritter@sonic.net.invalid>
    Re: alarm() syntax (Rafael Garcia-Suarez)
    Re: ASP in Perl <parrot0123@yahoo.ca>
    Re: Backreferencing in ()*-like patterns (Ilya Zakharevich)
    Re: Bug in "perldoc -f our" (was: use strict (vars, etc <cadet@alum.mit.edu>
        eval "..." security problem <cadet@alum.mit.edu>
    Re: eval "..." security problem (Gwyn Judd)
    Re: eval "..." security problem <joe+usenet@sunstarsys.com>
    Re: flock and close   with  empty read strangeness <groovyt@erols.com>
    Re: flock and close with empty read strangeness <groovyt@erols.com>
        grep question <jlarson@linuxmail.org>
    Re: grep question <wyzelli@yahoo.com>
    Re: grep question <jlarson@linuxmail.org>
    Re: How to convert morse to ascii using perl? <djberg96@hotmail.com>
    Re: How to convert morse to ascii using perl? (Logan Shaw)
    Re: How to convert morse to ascii using perl? <uri@sysarch.com>
    Re: How to convert morse to ascii using perl? (Logan Shaw)
    Re: if($array1[1]  eq $string1) DOESN'T WORK?? (Gwyn Judd)
    Re: if($array1[1]  eq $string1) DOESN'T WORK?? (cRYOFAN)
    Re: if($array1[1]  eq $string1) DOESN'T WORK?? <wyzelli@yahoo.com>
    Re: if($array1[1]  eq $string1) DOESN'T WORK?? <uri@sysarch.com>
    Re: Inside a Scalar <bwalton@rochester.rr.com>
    Re: Perl CGI.pm RESET problem <idontreadthis56@hotmail.com>
    Re: Regex to quote XML attributes? (Rafael Garcia-Suarez)
    Re: Regexp matching between <tags> content </tags> <cdh@ala.net>
    Re: RFC: FAQ3 update -- Using less memory <bbense+comp.lang.perl.misc.Mar.07.01@telemark.stanford.edu>
    Re: Small perl sort question (Jay Tilton)
    Re: Small perl sort question <bwalton@rochester.rr.com>
    Re: Uploading a file <idontreadthis56@hotmail.com>
        What information can I get from a GLOB reference? <johnlin@chttl.com.tw>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 08 Mar 2001 00:25:28 -0300
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: (Linux beginner) How to de-install and re-install Perl on Linux
Message-Id: <kpitllndqv.fsf@dagon.conectiva>

On Wed, 7 Mar 2001, mgjv@tradingpost.com.au wrote:
> 	Garry Heaton <garry@heaton6.freeserve.co.uk> wrote:
>> I'm new to Linux/Unix and want to remove the default Perl
>> installation, then re-install from source code because I read
>> somewhere that the Perl libraries on some Linux distributions are
>> incomplete. How do I remove and re-install?
> 
> It's better to leave the original installed, otherwise all other
> packages managed by rpm will start whinging that you don't have perl
> installed (and that includes bind, for crying out loud!).

bind??? It seems like a packaging bug to me:

[godoy@wintermute godoy]$ rpm -q --requires bind
chkconfig  
/bin/sh  
ld-linux.so.2  
libc.so.6  
libc.so.6(GLIBC_2.0)  
libc.so.6(GLIBC_2.1)  
[godoy@wintermute godoy]$ rpm -q bind           
bind-8.2.3-4cl
[godoy@wintermute godoy]$ 

-- 
Godoy. <godoy@conectiva.com>

Departamento de Publicações       Conectiva S.A.
Publishing Department             Conectiva Inc.

"Ser poeta não é minha ambição, é minha maneira de estar sozinho"
				- Fernando Pessoa


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

Date: Thu, 08 Mar 2001 05:57:40 GMT
From: Walter Greenwood <ritter@sonic.net.invalid>
Subject: alarm() syntax
Message-Id: <obFp6.112$fk.7213@typhoon.sonic.net>


I am new to perl and am having difficulty adding an alarm to this webmonitor
script. I would like to have it restart apache and coldfusion if it detects 
a hung server. When I test the script with perl -d, it hangs at "head(URL)". 
I tried to modify the alarm example to timeout after 60secs and then run the 
resurrect subroutine. 
Can this be accomplished using the alarm function?
Thanks for any insight,
Walter


http://stein.cshl.org/~lstein/talks/perl/perl98.html
http://www.cpan.org/doc/FMTEYEWTK/IPC/signals.html

#!/usr/local/bin/perl
# script: webmonitor

use LWP::Simple;
use constant URL       => 'http://192.168.1.85/BigLoop.cfm';
use constant APACHECTL => '/usr/local/apache/bin/apachectl';
use constant CSTOP     => '/usr/local/coldfusion/bin/stop';
use constant CSTART     => '/usr/local/coldfusion/bin/start';
$MAIL                  =  '/usr/lib/sendmail';
$MAIL_FLAGS            =  '-t -oi';
$WEBMASTER             =  'wg';
$SERVER                 = 'appsdev';

eval {
     local $SIG{ALRM} = sub { die "alarm clock restart" };
                        alarm 60;
                        head(URL) || resurrect();
                        alarm 0;
    };
if ($@ and $@ !~ /alarm clock restart/) { die }; 

#head(URL) || resurrect();
 
sub resurrect {
     open (STDOUT,"| $MAIL $MAIL_FLAGS") || die "mail: $!";
     select STDOUT; $| = 1;
     open (STDERR,">&STDOUT");
 
     my $date = localtime();
     print <<END;
To: $WEBMASTER
From: The Web Server Monitor <nobody>
Subject: The web server is down
 
The Web server $SERVER at $date doesn't appear to be responding.
Attempting to restart apache and coldfusion.
 
END
        ;
 
        system CSTOP;
        system CSTART;
        system APACHECTL,'graceful';

print <<END;
 
END
     close STDERR;
     close STDOUT;
}


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

Date: Thu, 08 Mar 2001 07:55:46 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: alarm() syntax
Message-Id: <slrn9aeenm.up4.rgarciasuarez@rafael.kazibao.net>

Walter Greenwood wrote in comp.lang.perl.misc:
> 
> I am new to perl and am having difficulty adding an alarm to this webmonitor
> script. I would like to have it restart apache and coldfusion if it detects 
> a hung server. When I test the script with perl -d, it hangs at "head(URL)". 
> I tried to modify the alarm example to timeout after 60secs and then run the 
> resurrect subroutine. 
[...]
> # script: webmonitor
> 
> use LWP::Simple;

 ... or, instead of using alarm, you could replace LWP::Simple by
LWP::UserAgent : you can specify a timeout value for LWP::UserAgent.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 08 Mar 2001 04:17:06 GMT
From: "Parrot" <parrot0123@yahoo.ca>
Subject: Re: ASP in Perl
Message-Id: <6JDp6.394404$JT5.12320619@news20.bellglobal.com>

Hernux <hernux@etherac.com.ar> wrote in message
news:986lm4$38k$1@taliesin.netcom.net.uk...
> Is there a way to simulate an ASP Session Object in Perl....
>

I'm pretty sure that anything you can put in an HTML web page you can put
into a Perl CGI script.  You'd call it in exactly the same way... or am I
missing the intent of your question?




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

Date: 8 Mar 2001 06:02:27 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Backreferencing in ()*-like patterns
Message-Id: <98779j$4ce$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@foad.org>],
who wrote in article <slrn9ada49.q1s.abigail@tsathoggua.rlyeh.net>:
> It would be nice if you could get all the submatches instead of just
> the last one (when working with modifiers).

Yes, I outlined the possible syntax and semantic in one of my (few)
messages to perl6-whatever.

Ilya


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

Date: Thu, 08 Mar 2001 03:38:34 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: Re: Bug in "perldoc -f our" (was: use strict (vars, etc.))
Message-Id: <m3ofvdl7nx.fsf@alum.mit.edu>

nobull@mail.com writes:

> Spot the deliberate mistake?

I don't know for sure, but the *point* of my question was that our()
doesn't get involved with bindings; it only declares variables to be
dynamic extent.

The best way to state what I wanted is in Common Lisp:

(defun f (x)
  (let ((y (* x x)))
    (declare (special y))
    (g)))

(defun g ()
  (declare (special y))
  (format t "The value of y is ~d~&" y))

(g)

==> The value of y is 9

NIL

I thought initially that local() was what I wanted, and so it would
look like this:

use strict 'vars';

sub f {
 my $x = shift();
 local $y = $x * $x;
 g();
}

sub g {
 our $y;
 print "the value of y is ", $y, "\n";
}

but that didn't work.  But it has to do with what I consider poor
semantics on local() -- even when using

use strict 'vars';

--dave


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

Date: Thu, 08 Mar 2001 03:20:49 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: eval "..." security problem
Message-Id: <m3itlls9br.fsf@alum.mit.edu>

Hi,

Before I go into this problem, I'd like to first mention a few things.
First is that I am not natively a Perl programmer, but a Common Lisp
programmer, and the problem I'm posing here is one which I've dealt
with in Common Lisp, and for which i've been able to create an
amazingly elegant, mostly simple solution that I think works for the
vast majority of cases, providing a near-complete subset of Common
Lisp without compromising the running application, regardless of the
arbitrary code evaluated.  In other words, if an attacker could run
arbitrary code in that environment, then the best he could is to write
something that hogged up the CPU immensly, i.e. denial-of-service
attacks, etc.  I'll discuss the CL-based solution after I describe the 
problem a bit better.

The problem is program extensibility.  If you're writing an
application in Perl, or in any language that's expressive --
especially one with an interpretive nature to it, with constructs like 
eval() -- you might consider that the ultimate provision for extension 
would stem from allowing the user to write native application code
(e.g. in Perl for a Perl application, Common Lisp for a CL
application, etc. for Python).  It might work as follows:

  Create an environment (a package, some bindings, methods, data
  structures, etc.) and then evaluate an (almost) arbitrary expression
  in that context, get back a value, and use it in your application.

I have an application in which I would like such an ability, and in
which I'd like to have the user enter in an arbitrary Perl expression
to be evaluated to compute something.  I do, of course, realize that
there are ways of doing this by defining another language, grammar,
etc.  But there's already Perl, and Perl has eval(), and this will
simplify passing data around, creating an environment, subroutines,
etc.

I'd like it if I could execute this code in such a way so as to deny
access to many of Perl's features, functions, globals, etc.

In Common Lisp, I did this by creating a new package (which I called a 
`safe package'), which imported only those symbols from the primary CL 
package that I'd allow usage on.  Before executing *any* code, I'd
make absolutely sure that the code didn't contain or refer to *any*
symbols except that ones I gave it access to.  In addition, I
discluded the symbols from the CL package which might allow someone to 
mess with the packaging system.

Unfortunately, Perl is much hairier even that Common Lisp, and while
Common Lisp source code is data, allowing me to traverse it easily
with a code-walker, I don't know if the same is true for Perl.  I'd
appreciate it dearly if someone could tell me how to secure foreign
code (as much as humanly possible) to prevent at least a large portion 
of possible attacks.

I do have a couple of ideas (I didn't want to just ask without showing 
that I'd at least thought a bit about it).

I think one possible key to this will be similar to the CL solution:
to create a special package, using just the symbols from other
packages that I'm advertizing.  Then, for globals that I *really* want 
accessible in this eval form, I'll temporarily use a tie() somewhere
that prevents users from doing certain things.  Also, it might be
possible to walk through the code using a Perl parser that comes with
Perl itself, and just walk the parse tree.  Unfortunately, I have not
been able even to find such a parser on CPAN, which comes ready to
parse Perl code.

feedback very much appreciated.

dave


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

Date: Thu, 08 Mar 2001 03:42:28 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: eval "..." security problem
Message-Id: <slrn9ae07n.2un.tjla@thislove.dyndns.org>

I was shocked! How could David Bakhash <cadet@alum.mit.edu>
say such a terrible thing:

>  Create an environment (a package, some bindings, methods, data
>  structures, etc.) and then evaluate an (almost) arbitrary expression
>  in that context, get back a value, and use it in your application.

You might want to check out the Safe module.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I have just signed legislation that will outlaw Russia forever;
we begin bombing in 5 minutes.
		-- Ronald Reagan, weekly radio address, 11 August 1984


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

Date: 07 Mar 2001 22:44:13 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: eval "..." security problem
Message-Id: <adDp6.3691$L67.81955@news1.atl>

David Bakhash <cadet@alum.mit.edu> writes:

[...]

>   Create an environment (a package, some bindings, methods, data
>   structures, etc.) and then evaluate an (almost) arbitrary expression
>   in that context, get back a value, and use it in your application.

[...]

> I'd like it if I could execute this code in such a way so as to deny
> access to many of Perl's features, functions, globals, etc.

[...]

> In Common Lisp, I did this by creating a new package (which I called a 
> `safe package'), which imported only those symbols from the primary CL 
   ^^^^^^^^^^^^
> package that I'd allow usage on.  Before executing *any* code, I'd
> make absolutely sure that the code didn't contain or refer to *any*
> symbols except that ones I gave it access to.  In addition, I
> discluded the symbols from the CL package which might allow someone to 
> mess with the packaging system.

[...]

> I'd appreciate it dearly if someone could tell me how to secure foreign
> code (as much as humanly possible) to prevent at least a large portion 
> of possible attacks.

[...]

> I think one possible key to this will be similar to the CL solution:
> to create a special package, using just the symbols from other
> packages that I'm advertizing.  

[...]

  % man Safe

-- 
Joe Schaefer       "We all agree that your theory is crazy, but is it crazy
                                           enough?"
                                               -- Niels Bohr


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

Date: Thu, 08 Mar 2001 02:18:43 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <groovyt-35904B.02184308032001@virt-reader.news.rcn.net>

In article <983kal$2eh$1@orpheus.gellyfish.com>,
 Jonathan Stowe <gellyfish@gellyfish.com> wrote:

> 
> Perhaps you should have made it clear what you meant then :
> 
>  "IMHO   any function  that messes with a file (in any way)
>   should never mess with that file unless there is a lock."
>                                                                
> Makes it sound very much like you believe all file access requires a lock.
> 
> /J\


but i did make it clear.   That statement was in the context of the thread
which you disregarded.

Why in the world  would you assume I was talking about 
closed non share systems when every post leading up to that
was about shared systems and flock and race conditions.
i mean even the subject tittle has flock in it.

if you were talking about unix would you except someone to come and say
"you are wrong because STUDLY OS 1.0 does not do that"

I hope not


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

Date: Thu, 08 Mar 2001 02:35:26 -0500
From: ZepHead <groovyt@erols.com>
Subject: Re: flock and close with empty read strangeness
Message-Id: <groovyt-FAA751.02352608032001@virt-reader.news.rcn.net>

In article <1epunbr.u347udbvtpeN%kpreid@attglobal.net>,
 kpreid@attglobal.net (Kevin Reid) wrote:

> Hrm. This is weirder than I thought. On Mac OS, a truncate() immediately
> after a print() will not function, but it will if any seek() is done
> before the truncate(), even if that seek() doesn't change the position.
> 
> On Darwin (a.k.a. Mac OS X), it works as I'd expect ideally: truncation
> moves the file position.


Mac 9.1 is older perl builds .
IIRC 9.1  is 5.004    and  osx ,    be right back..... 
(ok I just look at 4k73 build of os x   ---   5.6)


The mac perl IDE for osx is well on the way
so you should dump the old 9.1 stuff when it comes out
and now that os x has gone golden master the wait will not
be long at all , just two weeks    ; )


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

Date: Wed, 7 Mar 2001 21:51:00 -0600
From: "Jason Larson" <jlarson@linuxmail.org>
Subject: grep question
Message-Id: <tadvuf566tvs93@corp.supernews.com>

I am new to perl scripting.  I am writing a script to grep a file for IP
addys.  Im using something like this
after opening the file and declaring an array.  print grep /\d/, @lines;

greps the file fine but I would prefer 2 things:
1) only grabs the IP and not the whole line
2) only the first instance of the IP

any help would be great.





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

Date: Thu, 8 Mar 2001 14:10:05 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: grep question
Message-Id: <0TDp6.9$0r2.6267@vic.nntp.telstra.net>

"Jason Larson" <jlarson@linuxmail.org> wrote in message
news:tadvuf566tvs93@corp.supernews.com...
> I am new to perl scripting.  I am writing a script to grep a file for
IP
> addys.  Im using something like this
> after opening the file and declaring an array.  print grep /\d/,
@lines;
>
> greps the file fine but I would prefer 2 things:
> 1) only grabs the IP and not the whole line
> 2) only the first instance of the IP
>
> any help would be great.
>

You could try:
for (@lines){
    print "$1\n" if m/(\d+\.\d+\.\d+\.\d+)/; # alternative IP regexes
left to debate
}

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";






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

Date: Wed, 7 Mar 2001 22:58:51 -0600
From: "Jason Larson" <jlarson@linuxmail.org>
Subject: Re: grep question
Message-Id: <tae3tijjvdce03@corp.supernews.com>

worked perfect.


"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:0TDp6.9$0r2.6267@vic.nntp.telstra.net...
> "Jason Larson" <jlarson@linuxmail.org> wrote in message
> news:tadvuf566tvs93@corp.supernews.com...
> > I am new to perl scripting.  I am writing a script to grep a file for
> IP
> > addys.  Im using something like this
> > after opening the file and declaring an array.  print grep /\d/,
> @lines;
> >
> > greps the file fine but I would prefer 2 things:
> > 1) only grabs the IP and not the whole line
> > 2) only the first instance of the IP
> >
> > any help would be great.
> >
>
> You could try:
> for (@lines){
>     print "$1\n" if m/(\d+\.\d+\.\d+\.\d+)/; # alternative IP regexes
> left to debate
> }
>
> Wyzelli
> --
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
> it around');
> for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
>
>
>
>




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

Date: Thu, 08 Mar 2001 04:52:52 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: How to convert morse to ascii using perl?
Message-Id: <EeEp6.311$ya.36150@typhoon.mn.mediaone.net>

"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:878zmi5sbm.fsf@limey.hpcc.uh.edu...
> >> On Wed, 07 Mar 2001 00:31:55 GMT,
> >> "Andy" <ckzchang02@home.com> said:
>
> > I am new to perl and am learning how to convert a morse
> > code to acsii.  Any suggestions where to look to get
> > started?
>
> Go to http://search.cpan.org/ and search for an obvious
> string...

But, if you just want to learn as an academic exercise, I recommend
using a hash.  I played with this for a bit.  I did something like.

%morse_hash = ( a => '.-', b => '-...', etc);

Then I parsed the string I wanted translated one character
at a time, and replaced the key with the value (or vice-versa),
dealing with spacing, etc.

Speedy?  Probably not.  But for short sentences it should be
plenty fast.

Now, if you can figure out how to call a MIDI sequence based
on the value (so you could hear the dits & dahs), *that* would
be cool. :)

Regards,

Dan




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

Date: 7 Mar 2001 23:24:08 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to convert morse to ascii using perl?
Message-Id: <98751o$siv$1@boomer.cs.utexas.edu>

In article <EeEp6.311$ya.36150@typhoon.mn.mediaone.net>,
Daniel Berger <djberg96@hotmail.com> wrote:
>But, if you just want to learn as an academic exercise, I recommend
>using a hash.  I played with this for a bit.  I did something like.
>
>%morse_hash = ( a => '.-', b => '-...', etc);
>
>Then I parsed the string I wanted translated one character
>at a time, and replaced the key with the value (or vice-versa),
>dealing with spacing, etc.
>
>Speedy?  Probably not.  But for short sentences it should be
>plenty fast.

And if you want it to be fast, you can do this:

	$morse = join (" ", @morse_hash{ split (//, $ascii) } );

If you want to go the other way, just do this:

	@backwards{ values %morse_hash } = keys %morse_hash;
	$ascii = join ("", @backwards{ split (/\s+/, $morse) } );

Isn't Perl fun?

  - Logan
-- 
my  your   his  her   our   their   *its*
I'm you're he's she's we're they're *it's*


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

Date: Thu, 08 Mar 2001 05:29:40 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to convert morse to ascii using perl?
Message-Id: <x7vgpkde0q.fsf@home.sysarch.com>

>>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:

  LS> If you want to go the other way, just do this:

  LS> 	@backwards{ values %morse_hash } = keys %morse_hash;

since morse code is 1-1 in both directions, you could just do this:

	%backwards = reverse %morse_hash ;

  LS> Isn't Perl fun?

yes, isn't it?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 8 Mar 2001 00:15:17 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: How to convert morse to ascii using perl?
Message-Id: <98781l$t25$1@boomer.cs.utexas.edu>

In article <x7vgpkde0q.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>>>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:
>
>  LS> 	@backwards{ values %morse_hash } = keys %morse_hash;
>
>since morse code is 1-1 in both directions, you could just do this:
>
>	%backwards = reverse %morse_hash ;

Hey, good point.  That's a better way of taking the inverse of a 1-1
function that happens to be represented by a hash.  My way could be a
little weird if keys %morse_hash is shorter than values %morse_hash, so
the "reverse" way is better even when it's not 1-1.

print @{ { reverse qw { . / a .- c -.-. e . h .... j .---
k -.- l .-.. n -. o --- p .--.  r .-. s ... t - u ..- , --..--
} } } { qw { .--- ..- ... - / .- -.  --- - .... . .-. / .--.
 . .-. .-.. / .... .- -.-.  -.- . .-. --..-- } }, "\n";

  - Logan
-- 
my  your   his  her   our   their   *its*
I'm you're he's she's we're they're *it's*


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

Date: Thu, 08 Mar 2001 03:44:10 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: if($array1[1]  eq $string1) DOESN'T WORK??
Message-Id: <slrn9ae0as.2un.tjla@thislove.dyndns.org>

I was shocked! How could Peter Sundstrom <peter.sundstrom-eds@eds.com>
say such a terrible thing:

>Your problem is more than likely related to your data.  As you don't provide
>any input, it is not possible to say where the exact problem is.

I'd say his problem is more likely related to his syntax. But that's
just me.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)

"Your pants will freeze before you reach the first marker!" --Deck Officer

"The Empire Strikes Back (tm)", "Pants" Style


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

Date: Thu, 08 Mar 2001 04:10:26 GMT
From: cryofan@mylinuxisp.com (cRYOFAN)
Subject: Re: if($array1[1]  eq $string1) DOESN'T WORK??
Message-Id: <3aa705eb.42660188@news3.mylinuxisp.com>

On 08 Mar 2001 00:06:49 +0000, nobull@mail.com wrote:

>Wannabe Perl Guru <donotreply@interbulletin.bogus> writes:
>
>> But when I use this statement:
>> 
>>   if($array1[1]  eq $string1) 
>>       print "yes";
>> 
>> Then Perl throws up!
>> Why can't I do this this Perl?
>
>Beause the syntax of the if staement in Perl is:
>
>if (EXPR) BLOCK
>
>That's _block_ not _statement_.  
>
>> What alternatives are there to the above statement??
>
>Valid Perl syntax.
>

OK, thanks everyone. I guess I just figured that since Perl is based
on C that I could put a single statement after the if statement with
brackets. 




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

Date: Thu, 8 Mar 2001 13:58:23 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: if($array1[1]  eq $string1) DOESN'T WORK??
Message-Id: <cJDp6.8$0r2.6286@vic.nntp.telstra.net>

"cRYOFAN" <cryofan@mylinuxisp.com> wrote in message
news:3aa705eb.42660188@news3.mylinuxisp.com...
>
> OK, thanks everyone. I guess I just figured that since Perl is based
> on C that I could put a single statement after the if statement with
> brackets.
>

print 'yes' if ($array1[1]  eq $string1) ;

or

if ($array1[1]  eq $string1) {print 'yes'};

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";






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

Date: Thu, 08 Mar 2001 05:20:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: if($array1[1]  eq $string1) DOESN'T WORK??
Message-Id: <x7y9ugdeg6.fsf@home.sysarch.com>

>>>>> "c" == cRYOFAN  <cryofan@mylinuxisp.com> writes:

  >> 
  >> Valid Perl syntax.
  >> 

  c> OK, thanks everyone. I guess I just figured that since Perl is
  c> based on C that I could put a single statement after the if
  c> statement with brackets.

why did you have that notion? perl has so many differences from c. it
stole stuff from c but is not a clone of it. c++ or java are much more
like c than perl.

next time get a good book (ask here and don't buy any ol' crap you find
on the shelf) and read it and the perl docs. learn the basic syntax
first.

and requiring braces after conditional statements is a major improvement
over c that we all should hank larry for. no more dangling statements
and visually unparsable nested messes.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 08 Mar 2001 02:55:12 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Inside a Scalar
Message-Id: <3AA6F588.4B76B5AA@rochester.rr.com>

Uri Guttman wrote:
> 
> >>>>> "BW" == Bob Walton <bwalton@rochester.rr.com> writes:
> 
>   BW> Hernux wrote:
>   >>
>   >> I need to know if the value of a Scalar is a string or an Integer
>   >>
>   >> thanx
>   BW>    print $Scalar=~/-?\d+/?'integer':'string';
> 
> will that work for 'a3b'? you need to anchor that regex at both ends.

Oops, I did that in my test program, and neglected to paste the final
copy into my note.  Sorry.

> 
> uri
> 
> --
> Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
> The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net  ----------  http://www.northernlight.com
-- 
Bob Walton


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

Date: Thu, 08 Mar 2001 02:00:27 -0600
From: Keep it to Usenet please <idontreadthis56@hotmail.com>
Subject: Re: Perl CGI.pm RESET problem
Message-Id: <idontreadthis56-1247DD.02002708032001@newsrump.sjc.telocity.net>

In article <3AA6707A.31723D8E@stomp.stomp.tokyo>,
 "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:

> Keep it to Usenet please wrote:
> 
> > Godzilla! wrote:
>  
> > > > I just didn't want to have to use a JS onClick event handler. 
> > > > Why?
> 
> > > Because Java totally sucks.
>  
> > This is a semi-pitnick, but Java and INScript (the language 
> > formerly known as Javascript) have about as much in common as 
> > butter and butterflies.
> 
> 
> This is related to this thread in what way, related in what way to 
> a concept which would be considered intelligent per a reasonable 
> person's perspective?

Because Buck commented that he didn't want to resort to INScript and 
you replied that Java totally sucks.  My comment is 100% relevant to 
your comment.

On the other hand, since Java and INScript (which Buck referred to as 
Javascript) have nothing in common, your reply was the one that's 
completely unrelated.  The dialog could have gone:

Buck:       I just didn't want to have to use a JS onClick event 
            handler. Why?

Godzilla!:  Because ice cream has no bones!

and the relevance of your reply would not have been improved or 
worsened.  To the ill-informed, the mis-informed and those that choose 
to be ignorant, the mere use of "JAVA" might have made your irrelevant 
reply **seem** related, but that perception does nothing to change the 
FACT that they are completely unrelated and that you (Select one or 
more of the following):

1) Didn't know what you were talking about.

2) Made an honest mistake, but reacted like a three-year-old 
   when you were corrected.

3) Just spewed a totally irrelevant comment.

4) Knew the difference, but wanted to perpetuate the confusion, 
   intentionally mislead Buck, etc..

-- 
Help!  I'm being held in a .sig factory.


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

Date: Thu, 08 Mar 2001 07:48:05 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Regex to quote XML attributes?
Message-Id: <slrn9aee9a.up4.rgarciasuarez@rafael.kazibao.net>

Jesse Sheidlower wrote in comp.lang.perl.misc:
> I have a lot of data in a flavor of SGML that I need to convert
> to XML so I can process it with XML::Parser. Most of the 
> discrepancies are trivial, and I've been able to deal with them
> (for instance, the original uses "." instead of ";" as the
> terminator for entity references, so I used "s/(&\w+)./\1;/g;").

Wrong. This should be :
  s/(&\w+)\./$1;/g
Note the additional backslash. For the replacement of \1 by $1, see
"Warning on \1 vs $1" in perlre.

> But I'm having some trouble with the attributes; the original
> doesn't ever quote them, so a tag could be:
> <e date=2001 changed=no id=2938223>, and I need this to be
> <e date="2001" changed="no" id="2938223"> or XML::Parser chokes
> on it.
> 
> I've tried a few different things, and every one has either 
> missed some attributes or has scattered quotation marks with
> abandon throughout my data. Can someone suggest a solution?

It's difficult to suggest a good solution without having seen a
problematic excerpt of your SGML file. Are there "a=b" patterns in the
data? Are there tags that span multiple lines? What kind of characters
appear in attribute names and values?

Something like s/(\w=)(\w+)/$1"$2"/g is probably too much simplistic.

Or, you can search the CPAN for a SGML-parser module.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 07 Mar 2001 22:41:36 -0600
From: cdh <cdh@ala.net>
Subject: Re: Regexp matching between <tags> content </tags>
Message-Id: <3AA70D80.A247C327@ala.net>

Toni wrote:

> Hy everybody,
> I am trying hard to find a regexp for a CGI that matches all the
> stuff between my two tags <!-- #myinclude --> and
> <!-- #myincludeEnd --> . The Problem is, that it should really match
> ANYTHING between those two tags, including umlauts like öäüÖÄÜß
> or special characters like ,.-_#<>[]{/)\ and so on.

<snip>

The short answer is to do something like this:

while ($html =~ /<!-- #myinclude -->(.*?)<!-- #myincludeEnd -->/gsi) {
        print "$1\n";
}

If you want something a little more elaborate and (possibly) re-usable:

sub match_between_tags {
        my $html = shift;
        my $start_tag = shift || qr/\w+/;
        my $end_tag = shift;
        my $re;
        if ($end_tag) {
                $re = qr/<($start_tag)(?:\s*.*?)>(.*?)<$end_tag>/is;
        } else {
                $re = qr/<($start_tag)(?:\s*.*?)>(.*?)<\/\1>/is;
        }
        my $c = 0;
        my @matches = grep {defined($_)} map {
                ($c++ % 2) ? $_ : undef;
        } $html =~ /$re/g;
        return @matches;
}

my $html = qq{
<!-- #myinclude --><a href="/foobar">
The Problem is, that it should really match
ANYTHING between those two tags, including
umlauts like öäüÖÄÜß.</a><!-- #myincludeEnd -->
};

for (&match_between_tags($html, qr/!-- #myinclude --/i, qr/!-- #myincludeEnd --/)) {
        print "$_\n";
}

The above is quickly thrown together, I can't promise is the best way to do it.
Test carefully.

Cheers,
Chris Hickman





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

Date: 8 Mar 2001 03:37:05 GMT
From: <bbense+comp.lang.perl.misc.Mar.07.01@telemark.stanford.edu> ;
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <986up1$pp5$2@nntp.Stanford.EDU>



In article <3AA56BEC.A7F9F0CD@home.com>,
Michael Carman  <mjcarman@home.com> wrote:
>Michael Carman wrote:
>> 
>> I decided to fix [perlfaq3.17]. In the spirit of the Perl community,
>> I'd appreciate any comments/additions/corrections before I submit this.
>
>
>=item * Clean out the trash
>
>If you have a variable which consumes a large amount of RAM, you may 
>want to explicitly undef() once it's no longer needed. Perl might then 
>return the additional memory back to the OS.
>
>=back

- - Is this true for any OS? I'm pretty sure that memory can be
reused by the process, but I don't know of any OS where it goes
back into the general pool. This distinction may be too fine 
for a FAQ, but it is a commonly faced issue. As far as I know,
pretty much the only way to return memory to the OS is to restart
the process. If there are OS's that do this I'd love to know 
about them. 

- - Booker C. Bense 



Version: 2.6.2

iQCVAwUBOqb+XwD83u1ILnWNAQHEQgP8DJcmhrgBtoHac94n30LZec/AC3pwCzdh
u1XVkAjXT5gwvDVVfe+CEccKuDXvX+AYb6988bqJ1ZaQWM7EyX6ErGz2mCpS1/FD
zfojpsI1k/guiKGmn0fiOI0n2JuIA0f98EWcDIZZXsCIC70FMMhNRUAaFU/90LOU
qCdZCriPP58=
=m/D2
-----END PGP SIGNATURE-----


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

Date: Thu, 08 Mar 2001 02:07:59 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Small perl sort question
Message-Id: <3aa6de31.40355664@news.erols.com>

On 7 Mar 2001 23:31:12 GMT, abigail@foad.org (Abigail) wrote:

>Bryan Coon (bcoon@sequenom.com) wrote on MMDCCXLV September MCMXCIII in
><URL:news:3AA6C113.664B72EC@sequenom.com>:
>__ A small question...
>__ 
>__ With the following array:
>__ my @list = ("5", "8", "15", "X", "7", "Y");
>__ 
>__ my @sorted = sort { $a <=> $b } @list;
>__ 
>__ works like a charm, with the exception that I get complaints that
>__ 'Argument "Y" isn't numeric in sort at.. etc.' .  This is not such a
>__ problem, but is there a generally accepted way to use this sort after a
>__ test for numerics?  This seems simple but I was unable to find such a
>__ test.... It is also not important that the strings are sorted.
>
>One way of doing it would be:
>
>    my @sorted = sort (grep {/^\d+$/} @list), grep {/\D/ || /^$/} @list;

I'd rather blame myself or my perl (ActiveState v5.6.0, build 618,
Win32) than respectfully suggest that Abigail made a mistake, but
something's not right with that.  A different complaint is generated.

  sort (...) interpreted as function at ...

Also, the contents of @sorted end up as (15, 5, 7, 8).

This modification works.
   my @sorted = (
      (sort {$a <=> $b} grep {/^\d+$/} @list),
      (grep {/\D/ || /^$/} @list)
   );

In the spirit of TMTOWTDI, my solution went like this.
  my @sorted = sort 
    { ($a=~/^\d+$/?$a:1000) <=> ($b=~/^\d+$/?$b:1000) }
    @list;

It does the Wrong Thing if the value of any numeric element is 1000 or
more.  Increase '1000' as necessary, or change it to something
enormously negative if you want the string elements at the beginning
of the sort.



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

Date: Thu, 08 Mar 2001 02:09:15 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Small perl sort question
Message-Id: <3AA6EAC3.FD3485FC@rochester.rr.com>

Bryan Coon wrote:
 ...
> With the following array:
> my @list = ("5", "8", "15", "X", "7", "Y");
> 
> my @sorted = sort { $a <=> $b } @list;
> 
> works like a charm, with the exception that I get complaints that
> 'Argument "Y" isn't numeric in sort at.. etc.' .  This is not such a
> problem, but is there a generally accepted way to use this sort after a
> test for numerics?  This seems simple but I was unable to find such a
> test.... It is also not important that the strings are sorted.
 ...
Well, the easiest thing is to just turn off warnings for the sort:

    {
        local $^W=0;
        my @sorted = sort { $a <=> $b ) @list;
    }

If you have a recent version of Perl, you can use:

    no warnings;
    ...
    use warnings;
-- 
Bob Walton


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

Date: Thu, 08 Mar 2001 01:41:35 -0600
From: Keep it to Usenet please <idontreadthis56@hotmail.com>
Subject: Re: Uploading a file
Message-Id: <idontreadthis56-7DA5C8.01413408032001@newsrump.sjc.telocity.net>

In article 
<BOlo6.2933$Ey1.209863@bgtnsc06-news.ops.worldnet.att.net>,
 "Joe Moore" <joemoore@att.net> wrote:

> I know when I'm not wanted <sob> goodbye cruel Perl world </sob>

Well, you:

1)  Provided mis-information -- that's not really a problem, just 
    don't get offended when you're corrected.

2)  Top-posted -- that's bad enough, but you continued to do it
    after being reminded not to.

3)  Quoted the entire message instead of trimming it to the relevant
    parts -- Not quite as bad as top-posting, but you continued to do
    it after being reminded not to.

-- 
Help!  I'm being held in a .sig factory.


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

Date: Thu, 8 Mar 2001 10:20:42 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: What information can I get from a GLOB reference?
Message-Id: <986q7d$kv5@netnews.hinet.net>

Dear all,

What information can I get from a GLOB reference?

open $fh,'>>hello' and print "$fh\n";
opendir $dh,'.' and print "$dh\n";

__END__
GLOB(0x1bef084)
GLOB(0x1bef15c)

Great!!! Auto-vivification.  With the GLOB reference,
can I get some information from it?  For example:

Was it opened by 'open' or 'opendir'?
What file name was opened?
What mode ('>>' or '+<' etc) was applied?


Hmm... GLOB?
Does it mean I should use some *foo{THING} syntax to get them?

print *{$fh}{NAME};

Yeah, I got '$fh'.  What other keys can be used?

print keys %{*{$fh}};

Although it can compile and run, I think it is not what I want.
How can I get the valid keys of *foo{THING} here?

Thank you.

John Lin





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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 442
**************************************


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