[18168] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 336 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 22 14:11:39 2001

Date: Thu, 22 Feb 2001 11:10:18 -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: <982869018-v10-i336@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Feb 2001     Volume: 10 Number: 336

Today's topics:
        perl-mode in emacs: nested sub's <ivo.welchnospam@yale.edu>
    Re: perl-mode in emacs: nested sub's <graham@cs.man.ac.uk>
    Re: perl-mode in emacs: nested sub's (Anno Siegel)
    Re: perl-mode in emacs: nested sub's (Kai =?iso-8859-1?q?Gro=DFjohann?=)
    Re: perl-mode in emacs: nested sub's <fw@deneb.enyo.de>
    Re: perl-mode in emacs: nested sub's (Anno Siegel)
    Re: POST and / <flavell@mail.cern.ch>
    Re: POST and / <mischief@velma.motion.net>
        Problem with Sockets <corni99@nibbles.de>
    Re: Quickest way to convert all keys in a hash from upp <ren@tivoli.com>
    Re: Regexp to match Web urls? <godzilla@stomp.stomp.tokyo>
        Remote Printer configuration: for (AIX, SUNOS lp, lpr e (Walter Tautz [MFCF])
    Re: Ripping apart a scalar - Important! <jonni@ifm.liu.se>
    Re: run in background and see the results in log file nobull@mail.com
    Re: Storing an array as Attribute of object. nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Feb 2001 11:10:18 -0500
From: ivo welch <ivo.welchnospam@yale.edu>
Subject: perl-mode in emacs: nested sub's
Message-Id: <3A9539EA.96139FF6@yale.edu>

emacs 20.7.1 (standard distribution on redhat 7.0).  Problem Example:

{
    print "something\n";
    sub printnothing {
        print "hi\n";
    }
print "end\n";
}

The 'print "end\n";' statement is misindented, as are all statements
thereafter.  Is there a better or fixed emacs perl-mode somewhere
available?

/iaw
--




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

Date: 22 Feb 2001 16:22:48 +0000
From: Graham Gough <graham@cs.man.ac.uk>
Subject: Re: perl-mode in emacs: nested sub's
Message-Id: <ttlwvaielgn.fsf@sphere.cs.man.ac.uk>

Cperl-mode indents your code as

{
 print "something\n";
 sub printnothing {
   print "hi\n";
 }
 print "end\n";
}

Is this what you want?

Graham


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

Date: 22 Feb 2001 16:36:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl-mode in emacs: nested sub's
Message-Id: <973f79$ev3$4@mamenchi.zrz.TU-Berlin.DE>

According to ivo welch  <ivo.welchnospam@yale.edu>:
> emacs 20.7.1 (standard distribution on redhat 7.0).  Problem Example:
> 
> {
>     print "something\n";
>     sub printnothing {
>         print "hi\n";
>     }
> print "end\n";
> }
> 
> The 'print "end\n";' statement is misindented, as are all statements
> thereafter.  Is there a better or fixed emacs perl-mode somewhere
> available?

Yes.  Switch it off.

You know what they say: Only Perl can parse perl.  This is true, if
only because there is no language specification besides Perl.  What
good is a syntax checker you can't trust when you need it?

Anno


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

Date: 22 Feb 2001 18:00:50 +0100
From: Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai =?iso-8859-1?q?Gro=DFjohann?=)
Subject: Re: perl-mode in emacs: nested sub's
Message-Id: <vaf3dd6abzx.fsf@lucy.cs.uni-dortmund.de>

On 22 Feb 2001, Anno Siegel wrote:

> You know what they say: Only Perl can parse perl.  This is true, if
> only because there is no language specification besides Perl.  What
> good is a syntax checker you can't trust when you need it?

CPerl is much better at it.

kai
-- 
Be indiscrete.  Do it continuously.


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

Date: 22 Feb 2001 18:40:26 +0100
From: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: perl-mode in emacs: nested sub's
Message-Id: <877l2iobud.fsf@deneb.enyo.de>

ivo welch <ivo.welchnospam@yale.edu> writes:

> emacs 20.7.1 (standard distribution on redhat 7.0).  Problem Example:
> 
> {
>     print "something\n";
>     sub printnothing {
>         print "hi\n";
>     }
> print "end\n";
> }

This won't help you with your particular problem, but...:

AFAIK, there are no nested functions in Perl (i.e. printnothing is
not local to the given block). 'my sub' is not implemented as of Perl
5.6.0.


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

Date: 22 Feb 2001 18:00:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl-mode in emacs: nested sub's
Message-Id: <973k45$ncv$2@mamenchi.zrz.TU-Berlin.DE>

According to Florian Weimer  <fw@deneb.enyo.de>:
> ivo welch <ivo.welchnospam@yale.edu> writes:
> 
> > emacs 20.7.1 (standard distribution on redhat 7.0).  Problem Example:
> > 
> > {
> >     print "something\n";
> >     sub printnothing {
> >         print "hi\n";
> >     }
> > print "end\n";
> > }
> 
> This won't help you with your particular problem, but...:
> 
> AFAIK, there are no nested functions in Perl (i.e. printnothing is
> not local to the given block). 'my sub' is not implemented as of Perl
> 5.6.0.

It isn't local, but it's perfectly legal to have a sub define other subs.
It's sometimes even useful (though rarely with named subs).

Anno


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

Date: Thu, 22 Feb 2001 18:10:28 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: POST and /
Message-Id: <Pine.LNX.4.30.0102221809520.1239-100000@lxplus003.cern.ch>

On 22 Feb 2001, M.I. Planchant wrote:

> I've written a perl script which uses a URL which is submitted
> using POST. The problem im having is that the / in the submitted
> URL are replaced with %2F.

No, that's not the problem: it's only a symptom.

> want to use the following but it won't work. What do I use?

CGI.pm




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

Date: Thu, 22 Feb 2001 19:02:18 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: POST and /
Message-Id: <t9aohqs3t769cf@corp.supernews.com>

Jonas Nilsson <jonni@ifm.liu.se> wrote:
>> You forgot to escape the /
>> use this:
>>
>> $data =~s/\%2F/\//g;
>>

Or, if you only want to deal with slashes but don't want to escape the
slash because of all the slashes and backslashes...

$sat =~ s{%2F}{/}g;

> Or even better
> $data =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

> Which will change all the %XX type strings to its correct character.

That is even better. Better still, use CGI.pm to do the work for you.

Chris

-- 
Christopher E. Stith
It's not the U in UBE that pisses people off. It's the B.
  -- Martien Verbruggen in clp.misc



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

Date: Thu, 22 Feb 2001 19:55:55 +0100
From: Cornelius Siller <corni99@nibbles.de>
Subject: Problem with Sockets
Message-Id: <3A9560BA.3050006@nibbles.de>

Hi!

I've tried to set up a bidirectional socket connection between a server 
and a client, both programs running on the same computer.

I want to send some data from the server to the client at first, like a 
question, and then have the client respond to that question. My problem 
is, the client doesn't stop waiting for data from the server, even when 
the server has sent a newline character.
How do I get the client to realize that the server is done sending?

On the server side I've used the following code:

$proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen(Server, SOMAXCONN) or die "listen: $!";
$SIG{CHLD} = \&REAPER;
$paddr = accept(Client, Server);
$|=1;
print Client "aaaaaaaaaaaaa\n";
$num = <Client>;
Client side:

$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect(SOCK, $paddr) or die "connect: $!";
$line = <SOCK>;
print $line;
$|=1;
print SOCK "blabla\n";


Regards,

Cornelius



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

Date: 22 Feb 2001 11:37:43 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Quickest way to convert all keys in a hash from uppercase to lowercase (or vice-versa)?
Message-Id: <m3zofewrdk.fsf@dhcp11-177.support.tivoli.com>

"Philip Obbard" <pobbard@hotresponse.com> writes:

> Hi all,
> 
> At one point in my code, I wind-up with a hashref containing uppercase key
> names when I eventually need lower case key names, so I do the following
> with my hashref $results:
> 
>  #Put keys in lowercase
>  while(my ($key, $value) = each(%$result)) {
>   $result->{lc($key)} = $value;
>   delete($result->{$key});
>  }
> 
> This works, but I'm wondering: is there a quicker way to do this (and
> wind-up with another hashref, perhaps)?

I doubt it's quicker, but you could use something like:

  @hash{map { lc } @keys} = delete @hash{@keys = keys %hash};

This takes advantage of the fact that delete returns the elements that
were deleted.  For that matter, you could change your loop to use:

  $result->{lc $key} = delete $result->{$key};

But this still goes against the admonition against modifying the hash
while looping over it with each.  I assume you could bypass that by
simply using:

  $result->{lc $_} = delete $result->{$_} for keys %$result;

Actually, I like this method.  My only concern is that "for keys"
*might* be magical (like "for [RANGE]") and would then be susceptible
to the same problem as each.  But I don't think that magic exists.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 22 Feb 2001 09:35:45 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regexp to match Web urls?
Message-Id: <3A954DF1.2AB5D544@stomp.stomp.tokyo>

Abigail wrote:
 
> Eli the Bearded wrote:
> > Clay Shirky  wrote:

> > I need the canonical regexp to match urls beginning with http:// (I
> > don't need to worry about ftp:, telnet: or mailto:, in other words)
> > and though I don't want to roll my own, Google searches of the form

(snipped)

> Here's a better one (it cheats on ldap:// though) (remove the newlines):
 
> (?:http://(?:(?:  (snipped remaining regex)

Has anyone enjoyed success in repairing this long regex
and having it run? I escaped all right slashes, removed
all \n characters along with removing the leading ( and
the ending ) for an if match statement.


TEST:

$url = "http://la.znet.com/~callgirl";

if ($url =~ /?:http: (remaining regex) /) 
 { print "Match Found"; }


RESULTS:

Error Message:

"/?:http:/: ?+ (more regex) {} follows nothing in regexp at...."


What am I overlooking in trying to run this regex?


Godzilla!


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

Date: 22 Feb 2001 16:47:47 GMT
From: wtautz@math.uwaterloo.ca (Walter Tautz [MFCF])
Subject: Remote Printer configuration: for (AIX, SUNOS lp, lpr etc)
Message-Id: <slrn99aglj.j9b.wtautz@pythagoras.math.uwaterloo.ca>

To clarify I am trying to create a program that can parse a database 
(of yet to be determined type, perhaps just some files with key values listed 
in a text file(s)) that can can generate SUN's printer.conf file or 
AIX qconfig, or lpr's printcap.


Model:

	General meta printer configuration files which include
    stuff like where the main printqueue is located,
    fonts available, etc....

    |
	|
	|
   \/

    generated qconfig, printcap etc


the program would run on a given host and that host could configure what
printers it has access to. ON the server side where the main printqueue
is being managed access control would be managed. I am essentially 

interested in Configuration of Remote printers for clients whether that
client can actually print will be regulated on the server side and it
is NOT the problem I am currently working on.

Has anyone ever dealt with these type of problems and solved them using
perl or some other language?

-walter 


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

Date: Thu, 22 Feb 2001 17:07:19 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Ripping apart a scalar - Important!
Message-Id: <973ddn$hat$1@newsy.ifm.liu.se>

> How would I take a scalar, say from a text field, and attempt to insert
> characters into it.  For example:  I have a phone number field, but I want
> to make sure that the area code has parenthesis around it. Any ideas?

Depends on how your scalar looks. You should check into perldoc perlop and
perldoc perlre. Examples:

$scalar=~s/(\d{2,3}-)/\($1\)/;
Would change the first appearance of two or three digits followed by an - to
include paranthesis
123-123 123 123 => (123)-123 123 123
but also
123 123-123-123 =>123 (123)-123-123

$scalar=~s/\b(\d*)\b/\($1\)/;
Would change the first cluster of digits to include parenthisis:
123-123 123 123 => (123)-123 123 123
1234567 => (1234567)
123 123123 => (123) 123123
123 123-123 => (123) 123-123

Hope this helps
/jN

--
 _____________________     _____________________
|   Jonas Nilsson     |   |                     |
|Linkoping University |   |      Telephone      |
|       IFM           |   |      ---------      |
| Dept. of Chemistry  |   | work: +46-13-285690 |
|  581 83 Linkoping   |   | fax:  +46-13-281399 |
|      Sweden         |   | home: +46-13-130294 |
|_____________________|   |_____________________|




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

Date: 22 Feb 2001 18:23:10 +0000
From: nobull@mail.com
Subject: Re: run in background and see the results in log file
Message-Id: <u9y9uyk25t.fsf@wcl-l.bham.ac.uk>

"John Lin" <johnlin@chttl.com.tw> writes:
> 
> When I run myprogram.pl in background, for example: crontab
> I hope to see those STDERR STDOUT outputs in myprogram.log
> Is there an existing module to use?

> I used tie *STDOUT to redirect STDOUT output.  It works.
> But tie *STDERR fails.

There's no reason to use tie to simply direct a handle to a file, a
simple open() will do.  There's even an example in "perldoc -f open".

> warn and die doesn't seem to be catchable by tie.

tie() will only intercept stuff written via the Perl print() et al.
Actually opening a file will reuse the OS level file-descriptor.

> Another question:
> 
> If a program is shebanged, can it use more modules
> from the command line?  Like this:
> 
> myprogram.pl -MBatch -Mstrict

No.  But you can still run shebanged scripts explicitly:

perl -MBatch -Mstrict myprogram.pl

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 22 Feb 2001 18:24:21 +0000
From: nobull@mail.com
Subject: Re: Storing an array as Attribute of object.
Message-Id: <u9snl6k23u.fsf@wcl-l.bham.ac.uk>

Steve Button <steve@buggeroff.com> writes:

> I can see how that would work, but I'm kind of wanting to push stuff onto the
> array too. I'm sure that I'm being really stupid here but I just can't see how
> to do this. I will also need to access the stuff in the array by element number.

You appear to be asking the syntax for dereferencing array references
in various contexts.  This has nothing to do with whether or not the
reference happens to be stored in an element of a hash that happens to
be blessed.

You should see the perlref manpage.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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