[8307] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1924 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 18 17:17:17 1998

Date: Wed, 18 Feb 98 14:00:28 -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, 18 Feb 1998     Volume: 8 Number: 1924

Today's topics:
    Re: .rc file parser, anyone? (Andy Wardley)
        books or anything <Chatjack@earthling.net>
    Re: books or anything <dboorstein@shopcfn.com>
        Displaying Integers <olm@mail1.csun.edu>
    Re: Displaying Integers <SNIPhsommer@micro.ti.comSNIP>
    Re: Eval subroutines left afterwards: BUG or FEATURE? (Taylor Gautier)
    Re: HTTP header control references (Cliff High)
    Re: internet:clearing user login data and forcing relog (Jonathan Feinberg)
        keypressed <internet@reimer.ch>
    Re: Killfile Triage (Bart Lateur)
    Re: Killfile Triage <spt@cstr.ed.ac.uk>
    Re: Newbie question:  script directory <SNIPhsommer@micro.ti.comSNIP>
    Re: Newbie question:  script directory <jobrien@world.std.com>
    Re: parameters (Jonathan Feinberg)
        Perl vsm@rocketmail.com
    Re: Q: scalar @{[/$f/g]} <*@qz.to>
    Re: Q: scalar @{[/$f/g]} <boys@aspentech.com>
        Regexp question/problem... <sgermain@nortel.ca>
    Re: Regexp question/problem... (Jonathan Feinberg)
    Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/ (Fritz Knack)
    Re: RFC about ``Matt's Script Archive'' (O'Shaughnessy Evans)
    Re: RFC about ``Matt's Script Archive'' <jdporter@min.net>
    Re: s/$x/$y/e question <ldanna@hotmail.com>
    Re: sourcing csh scripts from within perl uri@sysarch.com
    Re: split on ':', but not '\:' (Jeffrey R. Drumm)
    Re: split on ':', but not '\:' <justinb@cray.com>
    Re: split on ':', but not '\:' (Jonathan Feinberg)
        ts: Remove files in a PERL sript tsatan@hotmail.com
        ts: ts: Remove files in a PERL sript tsatan@hotmail.com
    Re: Unlink and rmdir <rra@stanford.edu>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 18 Feb 1998 17:52:35 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: .rc file parser, anyone?
Message-Id: <EoL5no.4A5@cre.canon.co.uk>


Tom Christiansen  <tchrist@mox.perl.com> wrote:
>Who's been editing my root-owned files?  This is no different than
>their editing /etc/rc.local, you know.  Shall we get rid of that, too?

Nope.  Which is why I made the point:

>:that only trusted people have access to his '/etc/keepalive.conf' and
>:as such, the contents are 'safe'.  This isn't the case if a perl script
>:is parsing "$ENV{ HOME }/.fooapprc".

>Yes it is the same case.  He's running it, as him, and I am parsing his
>startup file.  

My mistake.  Let me re-phrase.

This isn't the case where you might be parsing a user-generated file 
(such as "$ENV{ HOME }/.fooapprc") and you want to limit or regulate
what can be done in that config file.  It might be that your application
is running setuid, for example, or you simply have stupid users who need
to be protected from themselves.  Alternatively, you might like to 
perform some parse-time checking on the variable values (because we 
all make tyops, right?) or define some default values.  Perhaps you would
just like to be a bit more tolerant about the syntax you can put in 
your config file without generating run-time errors.

Perhaps I'm just being defensive because I'm one of the authors of those 
'ineffably complex "solutions"' on CPAN, but when I'm writing a largish
application that has a few dozen different options which I'd like to have 
in a config file, an environment variable or specified on the config line, 
I'd rather plug in a module and have it do the magic for me.  Other times
I don't.

As I've already said, Tom's solution is far simpler and in many ways better.
If that works for you then use it.  If it doesn't then use something else.

Luckily, you have the choice.

Here's an example using App::Config to define a couple of basic options
that can then be specified in a config file or on the command line:

    #!/usr/bin/perl -w

    use strict;
    use App::Config;

    my $CFGFILE = '.myapprc';
    my $ac = App::Config->new();   # always use OO calling convention

    $ac->define('verbose', {           
        CMDARG => '-v',               
    });

    $ac->define('homedir', {
        CMDARG   => '-h',                 # '-h' on command line
        ARGCOUNT => 1,                    # '-h <dir>' or 'homedir = <dir>'
        ALIAS    => [ 'home', 'root' ],   # also known as...
        EXPAND   => 1,                    # do tilde expansion '~uid/...'
        DEFAULT  => '/',
    });

    $ac->cfg_file($CFGFILE) if -r $CFGFILE;
    $ac->cmd_line(\@ARGV);

    print "Homedir: ", $ac->homedir(), "\n",
          "Verbose: ", $ac->verbose() ? "ON" : "OFF", "\n";


There's always more than one way to do it.  Choose whichever suits you best.



A

--
Andy Wardley <abw@kfs.org> http://www.kfs.org/~abw    
Signature lost in transit.  We apologise for any inconvenience caused.


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

Date: Wed, 18 Feb 1998 10:20:43 +1100
From: "ChatJack" <Chatjack@earthling.net>
Subject: books or anything
Message-Id: <6cd5sr$r3n$1@arachne.labyrinth.net.au>

Howdy ppl,

I'm interested in learning perl..can anyone recomment some books? or any
site to visit for any details in this subject..

Thanking all in advance.!

Best Regards
Joe




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

Date: Wed, 18 Feb 1998 12:12:10 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: books or anything
Message-Id: <34EB166A.970F76C3@shopcfn.com>

georg@cyberjunkie.com wrote:
> 
> In article <6cd5sr$r3n$1@arachne.labyrinth.net.au>,
>   "ChatJack" <Chatjack@earthling.net> wrote:
> > I'm interested in learning perl..can anyone recomment some books? or any
> > site to visit for any details in this subject..
> 
> Hi Joe,
> the book you are looking for is titled "Teach yourself Perl in 21 days".
> It's ISBN is 0-672-30586-0 by SAMS Publishing. It costs $29.99 and you can
> order it at 1-800-428-5331.
> It's a very detailed book and easy to understand. Very good to get into the
> stuff. If you now C you won't even need 21 days...

let's see: i'm on my 1134th day of teaching myself perl, and still
don't know it. maybe i'm a slow learner. ;)

maybe i'm using the wrong book. it's called "programming perl" 
(isbn: 1565921496) and it's by perl's creator and two of its most
dedicated supporters and teachers. ahhh, what do they know?

seriously though, you will find a wealth of information at:

http://www.perl.com

including book reviews.

-- 
dan boorstein <dboorstein@shopcfn.com>


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

Date: Wed, 18 Feb 1998 09:28:53 -0800
From: Ovanes Manucharyan <olm@mail1.csun.edu>
Subject: Displaying Integers
Message-Id: <34EB1A55.FA18EBE3@mail1.csun.edu>

I have a quick question.  How can I force an integer to print with 2
digits, instead of one.
Lets say I have numbers 0, 1, 3, 14..    How can I make them print  00,
01, 03, 14

Any reference would be appreciated.

--
----------------------------------------------------
Ovanes Manucharyan   olm@csun.edu
    California State University, Northridge
----------------------------------------------------




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

Date: Wed, 18 Feb 1998 13:04:20 -0600
From: Holly Sommer <SNIPhsommer@micro.ti.comSNIP>
Subject: Re: Displaying Integers
Message-Id: <34EB30B4.4EFDF8FE@micro.ti.comSNIP>

Ovanes Manucharyan wrote:

: I have a quick question.  How can I force an integer to print with 2
: digits, instead of one.
: Lets say I have numbers 0, 1, 3, 14..    How can I make them print  
: 00, 01, 03, 14

if ($number < 10) {
   print "0$number";
} else {
   print $number;
}

This works if you KNOW the number isn't a string with a 0 in front
of it... if it is a string with a zero, just change the if statement:

if ($number < 10 && $number !~ /^0/ )

-Holly


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

Date: 18 Feb 1998 21:00:00 GMT
From: tgautier@monazite.geoworks.com (Taylor Gautier)
Subject: Re: Eval subroutines left afterwards: BUG or FEATURE?
Message-Id: <6cfi4g$104$1@news>

Jonathan Feinberg (jdf@pobox.com) wrote:
: The *very first words* of the perldoc entry for the eval builtin are 

: "EXPR is parsed and executed as if it were a little Perl program. It is 
: executed in the context of the current Perl program, so that any variable 
: settings or subroutine and format definitions remain afterwards."

Thanks.  I must have read that definition a thousand times and somehow
missed those important words.  

The second part of my question remains unanswered, it seems that maybe it
warrants a new thread.  If I don't see any new responses for a while, I'll
repost the second part of my article as a new thread.

tg
_________________________________________________________________________
Taylor Scott Gautier                                tgautier@geoworks.com


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

Date: 18 Feb 98 19:36:46 GMT
From: chigh@vallier.com (Cliff High)
Subject: Re: HTTP header control references
Message-Id: <34eb384e.0@poobah.olywa.net>

see hethmon's book on http at
http://www.manning.com/hethmon/311.html



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

Date: Wed, 18 Feb 1998 10:19:37 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: internet:clearing user login data and forcing relogin?
Message-Id: <MPG.f54c6169b2e64e09896f8@news.concentric.net>

  [courtesy cc of this posting sent to cited author via email]

heidi.housten@edt.ericsson.data said...
: I am trying to figure out how I can force a relogin if a user returns
: after a certain period of inactivity.
[snipola]

"Parse" is a big word these days.  In fact, it was one of the topics of 
William Safire's last NY Times Magazine column.  So I'd just like to say that, 
no matter how diligently I parse your post, I can't find a shred of relevance 
to the Perl language.  Perhaps this handy list of slightly-more-relevant 
resources will provide you with some measure of help:

[This list courtesy of Tom Christiansen.]
    The CGI Newsgroup (NOT THIS ONE):
   comp.infosystems.www.authoring.cgi

    CPAN's Web-related modules in Perl:
   http://www.perl.com/CPAN/modules/by-
category/15_World_Wide_Web_HTML_HTTP_CGI/

    The Idiot's Guide to solving Perl/CGI problems 
        http://www.perl.com/perl/faq/idiots-guide.html

    Perl FAQs
        http://www.perl.com/CPAN/doc/FAQs/

    Perl Manpages (old)
        http://www.perl.com/CPAN/doc/manual/html/

    CGI FAQ
        http://www.webthing.com/page.cgi/cgifaq

    WWW Security FAQ
        www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html

    Web FAQ
        http://www.boutell.com/faq/

    HTTP Spec
        http://www.w3.org/pub/WWW/Protocols/HTTP/

    HTML Spec
        http://www.w3.org/pub/WWW/MarkUp/

    CGI Spec
        http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

-- 
#!/usr/bin/perl -w -- Just another Perl hacker,
 (open 0),$_=<0>,s,.*-+ ,,,chop;for(split?@*?){($$_++or$}=$_,y,
 y \,y,<STDIN>,,eval"sub $_ {print'$}'}"),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg    jdf@pobox.com    Sunny Brooklyn, NY


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

Date: Wed, 18 Feb 1998 20:31:56 +0100
From: "Patrick.Husi" <internet@reimer.ch>
Subject: keypressed
Message-Id: <34EB372C.884D0D24@reimer.ch>

Hi

Is there a function in perl like keypressed in pascal, to check if the
user has pressed any key?

Patrick



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

Date: Wed, 18 Feb 1998 16:49:03 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Killfile Triage
Message-Id: <34eb0c11.1243611@news.tornado.be>

Richard Caley <spt@cstr.ed.ac.uk> wrote:

>About half the spam I recieve has a subject starting Re:. They
>presumably read your faq.

Did you know that over 95% of the spam I receive, does not include my
e-mail address, neither in the "To:" nor in the "cc:" field?

That allows for pretty simple spam filtering. Just look for your e-mail
address in the recipient fields, and if you can't find it, it's spam.

HTH,
Bart.


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

Date: 18 Feb 1998 17:35:21 +0000
From: Richard Caley <spt@cstr.ed.ac.uk>
Subject: Re: Killfile Triage
Message-Id: <eyhra50q0iu.fsf@liddell.cstr.ed.ac.uk>

In article <34eb0c11.1243611@news.tornado.be>, Bart Lateur (bl) writes:

bl> Did you know that over 95% of the spam I receive, does not include my
bl> e-mail address, neither in the "To:" nor in the "cc:" field?

Did you know that a significant proportion of the legitimate mail I
recieve does not contain my address in the To: or Cc: fields?

bl> That allows for pretty simple spam filtering. 

And for dropping lots of legitimate mail on the floor.

[This is well off subject here and I'm regretting pointing out the
 flaw in the original idea, perhaps we should give it up?]

-- 
Mail me as rjc not spt@cstr.ed.ac.uk		_O_
						 |<



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

Date: Wed, 18 Feb 1998 13:06:00 -0600
From: Holly Sommer <SNIPhsommer@micro.ti.comSNIP>
Subject: Re: Newbie question:  script directory
Message-Id: <34EB3118.295C4B0F@micro.ti.comSNIP>

John O'Brien wrote:

: How do I find out what directory my perl script is executing in?


The Cwd command (Current working directory). Or, in *IX, a line like:
$mydir = `pwd`; will capture the path to the current dir.

-Holly


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

Date: Wed, 18 Feb 1998 15:00:27 -0800
From: John O'Brien <jobrien@world.std.com>
Subject: Re: Newbie question:  script directory
Message-Id: <34EB680B.49BF@world.std.com>

Holly Sommer wrote:
> 
> John O'Brien wrote:
> 
> : How do I find out what directory my perl script is executing in?
> 
> The Cwd command (Current working directory). Or, in *IX, a line like:
> $mydir = `pwd`; will capture the path to the current dir.
> 
> -Holly
Almost.  If the script is an executable someplace on my $PATH, I want
to know the directory it is executing out of, not the current directory.

John


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

Date: Wed, 18 Feb 1998 10:30:19 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: parameters
Message-Id: <MPG.f54c893a68abe639896fb@news.concentric.net>

  [courtesy cc of this posting sent to cited author via email]

dan.albertsson@swipnet.se said...
: -How do I receive two list in @_ when I send, for instance:
: calculate(@ListX, @ListY);

perldoc perlref
perldoc perlsub

: -How do I receive one list and one ordinary variable, for instance:
: calculate(@ListX, $ItemY);

see above

: -It seems that local does not work when using strict, why?

You need to qualify your variables with the full package name.  For example, 
within main, you may say

     local $::foo;

or 
     local $main::foo;

But perhaps you want lexically scoped variables, anyway.  Again, see perlsub, 
in the section "Private Variables via my()."  Also perldoc -f my.
      
: -Is it not possible to mix sending @lists and ordinary $variables to a
: function.

Once you've learned about references and sub prototypes, this will all become 
clear.  Good luck, and I hope this helps.

-- 
#!/usr/bin/perl -w -- Just another Perl hacker,
 (open 0),$_=<0>,s,.*-+ ,,,chop;for(split?@*?){($$_++or$}=$_,y,
 y \,y,<STDIN>,,eval"sub $_ {print'$}'}"),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg    jdf@pobox.com    Sunny Brooklyn, NY


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

Date: Wed, 18 Feb 1998 11:40:36 -0600
From: vsm@rocketmail.com
To: harishkn@kcsl.com
Subject: Perl
Message-Id: <6cf6ek$icv$1@nnrp1.dejanews.com>

Hi:
I am posting this for a friend. He is trying to access sql server thru
ODBC/perl and his perl code does not see the DSN of SQL server.

Here's the description of the problem.

-----
SQL SERVER

I have setup SQL Server in our NT Machine (Compaq Server).
ODBC has been configured with MS SQL driver.

Sample program was written in VB and also in VC to test the ODBC Connectivity.
Both the programs ran successfully.
I could view the tables and fields from this program.

PERL script was written to check the DSN. The DSN using MS Access is working
fine but the DSN using SQL Server did not work.
So I tried to display all the DSNs in the server through PERL script.
The DSNs using SQL drivers were not displayed but all other DSNs using MS
Access, FoxPro, Dbase etc were displayed.
------

Any help/pointer is appreciated.

Thanks,

Murali V. Srinivasan

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 18 Feb 1998 00:00:44 GMT
From: Eli the Bearded <*@qz.to>
Subject: Re: Q: scalar @{[/$f/g]}
Message-Id: <qz$9802171828@qz.little-neck.ny.us>

Robert S. Kissel <kissel@kissel.spicerack.ibm.com> wrote:
> While the expression
>         scalar @{[/$foo/g]}
> will evaluate to the number of times $foo matched in $_
 ...
> I'm overlooking something far simpler to return the number of matches of
> an expression, $foo, in the default search space, $_.

	$a = scalar @{[/$foo/g]};
	$b = @{[/$foo/g]};
	$c = s/($foo)/$1/g
	$d = split /$foo/ -1 # not pretty, not recommended, but works

Doubtless other people can come up with others.

Elijah
------
have fun


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

Date: Wed, 18 Feb 1998 17:44:54 +0000
From: Ian Boys <boys@aspentech.com>
Subject: Re: Q: scalar @{[/$f/g]}
Message-Id: <34EB1E16.2F1C@aspentech.com>

I wrote:
> 
> 
> $e=()=/$foo/g      Assigns the list to the scalar $e.  A list assigned
                                                         ^^^^^^^^^^^^^^^
>                    in a scalar context returns the number of elements
>                    in the list.
> 

I appear to have been wrong.  It seems the above assertion is correct
if changed to "A list assignment in a scalar context..." but not 
necessarily otherwise.

I guess this is why we need Perl gurus posting in this group.

Please don't let them be driven away...  :-(

Ian


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

Date: Wed, 18 Feb 1998 11:43:27 -0500
From: "Sylvain St.Germain" <sgermain@nortel.ca>
Subject: Regexp question/problem...
Message-Id: <34EB0FAE.D0210137@nortel.ca>

Hi,

How would you match a string in the following format:

AWord.AWord.AWord.add.ini

Why this does nod work?
$_ = $Line;
if (/(.*\.){2,}\.add\.ini/) {
    push ...
elsif ...

}


Many Thanks,
Sylvain.



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

Date: Wed, 18 Feb 1998 14:06:34 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Regexp question/problem...
Message-Id: <MPG.f54fb4696e98ed69896fe@news.concentric.net>

  [courtesy cc of this posting sent to cited author via email]

sgermain@nortel.ca said...

: AWord.AWord.AWord.add.ini
: 
: Why this does nod work?
: $_ = $Line;
: if (/(.*\.){2,}\.add\.ini/) {

Because you're matching the dot before 'add' in the parenthesized expression, 
and because you're not capturing the entire string before \.add\.ini.  So, a 
working regex for the job might be:

   /((.*\.){2,})add\.ini/

and much more efficient would be

   /^((?:[^.]*\.){2,})add\.ini$/

but is there any reason you can't use the simpler expression below, which has 
the benefit of not capturing the dot before 'add'?

   /^(.+)\.add\.ini$/

-- 
#!/usr/bin/perl -w -- Just another Perl hacker,
 (open 0),$_=<0>,s,.*-+ ,,,chop;for(split?@*?){($$_++or$}=$_,y,
 y \,y,<STDIN>,,eval"sub $_ {print'$}'}"),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg    jdf@pobox.com    Sunny Brooklyn, NY


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

Date: Tue, 17 Feb 1998 13:52:39 GMT
From: fritz.knack@nospam.POPULUS.net (Fritz Knack)
Subject: Re: regexp: /^[800|888]/ vs. /^8[0{2}|8{2}]/
Message-Id: <34ed94ba.3594399@cnews.newsguy.com>

On Sat, 14 Feb 1998 01:29:29 GMT, Eric Bohlman <ebohlman@netcom.com>
wrote:

>Fritz Knack <fritz.knack@nospam.POPULUS.net> wrote:
>: For a report I've written, I'm trying to determine if a given phone
>: number is an 800-class number, i.e., it begins with 800 or 888.
>
>You've already received several explanations of how you were using 
>character classes incorrectly, and have received suggestions on how to 
>write your regex properly.  May I suggest another one?
>
>if ($phone =~ /^8([02-9])\1/)...
>
>This will match 800, 822, 833, 844, 855, 866, 877, 888, and 899.  All 
>these area codes are designated for toll-free numbers (though 800 and 888 
>are the only ones currently in use).  If you account for them now, you 
>won't have to rewrite your script when a new one is added (which is 
>expected to happen pretty soon).

Thanks for the expanded list.

I'm still a little foggy on some of this stuff. If I understand
correctly, the \1 in /^8([02-9])\1/ says "look for another copy of
what's in the parentheses", which must be a single digit between 0 and
9 inclusive, except for the digit 1. Now, if I use the non-remembering
parens, I get the same result with /^(?:8[02-9]{2})/ which (I think)
says "grab an 8 followed by 2 of the same digits between 0 and 9
inclusive except for the digit 1". Right?

Fritz


-------------------------
Sorry 'bout the nospam in the From field. You know how those 'bots are.


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

Date: 18 Feb 1998 19:06:23 GMT
From: shaug@gromit.callamer.com (O'Shaughnessy Evans)
Subject: Re: RFC about ``Matt's Script Archive''
Message-Id: <6cfbff$5vj$1@ha1.rdc1.occa.home.com>

In article <6cdm10$l7v@fridge.shore.net>,
Nathan V. Patwardhan <nvp@shore.net> wrote:
>Steve Palincsar (palincss@nicom.com) wrote:
>
>: OK, I've seen this kicked around a bit.  Who, besides the
>: renowned author of the Aubrey/Maturin series, Patrick
>: O'Brian, of course, might "PoB" be?
>
>PoB = Prisoner of Bill (Gates).  I believe that this phrase was coined
>by Tom Christiansen.

Ah.  I was wondering about that too, but now that sounds familiar.
I was just assuming it meant "Pool old Bastard", which I suppose could
be equally as applicable.

    - shaug
-- 
- O'Shaughnessy Evans
- http://www.callamerica.net/shaug/


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

Date: Wed, 18 Feb 1998 08:37:12 -0500
From: John Porter <jdporter@min.net>
Subject: Re: RFC about ``Matt's Script Archive''
Message-Id: <34EAE408.60BF@min.net>

ssmieja@execpc.com wrote:
> 
> Probably taking this in a direction that I will regret but here goes.
> 
> I feel that there is an underlying current of hatred at old Perl 4 code by
> those who believe only in the OO model of Perl 5.  Everyone screams rewrite
> but moving from a process orientation to an OO one ain't easy.

You seem to be under the delusion that the only significant difference
between 5 and 4 is the addition of objects.  What about references,
for god's sake?

If you "code in perl4", then you don't even get the power of 
arbitrarily nested data structures (or "true multidimensional arrays").
But the list goes on and on. . .

John Porter


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

Date: Wed, 18 Feb 1998 15:36:53 -0500
From: Larry D'Anna <ldanna@hotmail.com>
Subject: Re: s/$x/$y/e question
Message-Id: <34EB4665.2A47C69B@hotmail.com>

Dave Winters wrote:
> 
> Hi,
> 
>     I'm having a little trouble with regular expression substitution.
> I'd like to use a variable as the replacement string.  I'd also like
> this variable to contain references ($1, $2, etc.) to the match.
> 
>   I've attached a simple example.  I thought the /e modifier would cause
> 
> the $replace to get "eval-ed" and the $1, $2 to get substituted
> properly.
> Any idea what I'm doing wrong?

$a = '([^ ]*) ([^ ]*)';
$b = '$1 - $2';
$_ = "foo bar";
s/$a/'"' . $b . '"'/ee;
print;

this will print C< foo - bar >
the first time it is evaluated the rhs will become C< "$1 - $2" >
when that is evaluated it will become C< foo - bar >		   	
 
> $adr = 'dwinters';
> $adr .= '@';
> $adr .= 'juniper.net';
> 

Fix your header.  If you don't want spam get a decent mail
client or put up with it.

-- 
Larry D'Anna                              ldanna@hotmail.com 
		 "eschew obfuscation"
Democracy is the worst system of government. 
Except for all the others
               -Winston Churchill


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

Date: 18 Feb 1998 12:43:31 -0500
From: uri@sysarch.com
Subject: Re: sourcing csh scripts from within perl
Message-Id: <x7u39wrepo.fsf@sysarch.com>

"J Robert Ray" <robert@visionart.com> writes:

> Is it possible to "source" a csh script from within a perl program?  I have
> a script that sets environment variables, and would like to execute the
> script then access the environment variables.

try wrapping your csh script with another that calls it and then prints
out the ENV with printenv or env. then your perl script can set its ENV,
execute with `` (backticks) the wrapper csh with the target csh as its
argument and process the printed ENV.

you can save using the wrapper if the target csh doe the ENV printing.

otherwise there is no way in general of a child process setting the
parent's ENV, perl csh or any other thing. in unix ENV is a parent to
child method. the child must do some sort of print to get values back to
the parent.

uri


-- 
Uri Guttman		        SYStems ARCHitecture and Software Engineering
uri@sysarch.com			                         Have Perl, Will Hack
http://www.sysarch.com		                        "Your Web Specialist"
(617) 643-7504 x*2  FAX: (617) 643-2710    These ARE the opinions of Sysarch!


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

Date: Wed, 18 Feb 1998 19:17:04 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: split on ':', but not '\:'
Message-Id: <34eb314d.435089695@news.mmc.org>

[courtesy copy cc'ed to the original poster]

On 18 Feb 1998 10:48:28 -0600, Justin Banks <justinb@cray.com> wrote:

>Hello -
>	I'm trying to split a line on colons, except where the colon is 
>backslashified, and I can't seem to make it happen. I've tried replacing
>the sequence '\:' before the split, like so :
>
>$line = "one:two:three\:here:four";
>$line =~ s/\\(?=:)/BACKSLASH/g;
>print "$line\n";
>
>But that doesn't work.
>
>I've also tried things like this (this won't compile, even though the 
>backslash is escaped) :
>
>$line = "one:two:three\:here:four";
>@stuff = split '(?:(?!\\).*|.*?):', $line;  
>
>And this:
>
>$line = "one:two:three\:here:four";
>@stuff = split '(?:(?!\\:)|:)', $line;
>
>
>Any pointers? Thanks.
>
>-justinb

Well, one problem in the above is that you've double-quoted your sample string,
$line. This means the backslash gets interpolated into the string, and
effectively disappears.  Anyway . . . this seems to work:

$line = 'one:two:three\:here:four';
@stuff = split /\b[^\\]?\b:\b/, $line;

The regex matches on a word boundary followed optionally by anything NOT a
backslash, then a colon,then another word boundary.  If I:

print join "\n",@stuff,"\n";

I get:

one
two
three\:here
four

Is that what you were hoping for?

PS. critiques welcome (but I know I'll get them even if I say they're not ;-))

-- 
                               Jeffrey R. Drumm, Systems Integration Specialist
                       Maine Medical Center - Medical Information Systems Group
                                                            drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented!" - me


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

Date: 18 Feb 1998 14:25:21 -0600
From: Justin Banks <justinb@cray.com>
Subject: Re: split on ':', but not '\:'
Message-Id: <o8nk9asirta.fsf@ebony.cray.com>


CCd to Michael J Gebis <gebis@albrecht.ecn.purdue.edu> , who wrote :

> print STDOUT "$line\n";
> 
> You don't HAVE the sequence '\:' in your example strings.

Yeah, I realized that just after I posted. In any case, though, it
doesn't really affect what I'm wanting to do. The line I'm splitting
DOES have '\:' in it, I just couldn't figure out how to make the split
work.

> 
> In any case, pick up a copy of the drunken Owls (by Freidl).  To me,
> this looks like a job for regexps, not split.

AFAIK, the 1st arg. to split is a regexp, so it's really 1/2 doz. one
and 6 of the other.

The suggestions I've gotten (some tested and some not) are :

1)

use 5.00455;
split /(?<!\\):/;


2)

s{\\:}{\x00}g;
@lines = map {s{\x00}{:}g; $_} split /:/;
 ------------------------------


3)

@stuff = split /\b[^\\]?\b:\b/, $line;


The last being more what I had in mind, the first a little too bleeding 
edge for what I'm doing (although I like it the best), and the middle 
being apparently the most robust.


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

Date: Wed, 18 Feb 1998 14:30:50 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: split on ':', but not '\:'
Message-Id: <MPG.f5500f941b077c49896ff@news.concentric.net>

  [courtesy cc of this posting sent to cited author via email]

justinb@cray.com said...
: $line = "one:two:three\:here:four";
          ^                        ^
Oops.  Those double quotes make your backslash go away, so that $line eq 
"one:two:three:here:four".

I couldn't come up with a regex for split that successfully implements 
"negative lookbehind."  So my solution is to replace '\:' with an ugly marker 
(I use ascii 0), do the split, and replace the marker with a plain colon.

$_ = 'one:two:three\:here:four';
s{\\:}{\x00}g;
@lines = map {s{\x00}{:}g; $_} split /:/;

-- 
#!/usr/bin/perl -w -- Just another Perl hacker,
 (open 0),$_=<0>,s,.*-+ ,,,chop;for(split?@*?){($$_++or$}=$_,y,
 y \,y,<STDIN>,,eval"sub $_ {print'$}'}"),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg    jdf@pobox.com    Sunny Brooklyn, NY


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

Date: 18 Feb 1998 17:21:09 GMT
From: tsatan@hotmail.com
Subject: ts: Remove files in a PERL sript
Message-Id: <6cf5a5$q93$1@orthanc.reference.com>

>From the keyboard of Tom Christiansen <tchrist@mox.perl.com>:
| In comp.lang.perl.misc, PTBS <ptbs@mail.dma.be> writes:
| :Then I want to remove the files from my /temp directory.
| :But how can I do that?
|
| You grep for "Delete" in the perlfunc manpage.  You want the matches

Wrong. Use the unlink function like this:

   unlink "/etc/passwd" or die "cannot unlink: $!";

--tom, the an-tchrist


  -------------------------------------------------------------------- 
  Posted using Reference.COM                  http://WWW.Reference.COM 
  FREE Usenet and Mailing list archive, directory and clipping service 
  -------------------------------------------------------------------- 


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

Date: 18 Feb 1998 21:12:43 GMT
From: tsatan@hotmail.com
Subject: ts: ts: Remove files in a PERL sript
Message-Id: <6cfisb$tok$1@orthanc.reference.com>

>From the keyboard of Tom Christiansen <tchrist@mox.perl.com>:
| In comp.lang.perl.misc, tsatan@hotmail.com writes:
| :Wrong. Use the unlink function like this:
|
| Don't tell people answers that are in the manpages or faqs.

Wrong. You so easily dismiss people who are new to perl.
I don't feel it's proper for you to cut and dry it as you
do. It doesn't help the discussion for you to be so impenetrable.

--tom, the an-tchrist
--
        Tom Satanistsen        tsatan@hotmail.com


  -------------------------------------------------------------------- 
  Posted using Reference.COM                  http://WWW.Reference.COM 
  FREE Usenet and Mailing list archive, directory and clipping service 
  -------------------------------------------------------------------- 


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

Date: 18 Feb 1998 12:24:13 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Unlink and rmdir
Message-Id: <m3sopgwtjm.fsf@windlord.Stanford.EDU>

Kari Marttila <Kari.Marttila.@tietogroup.com> writes:

> There is one problem. Every now and then the script "leaves" certain
> directories (irregular behaviour: not the same directories every time)
> without deleting them. Perl script says that there were no errors,
> though.

Are you sure?  You *are* checking the return value of unlink() and
rmdir(), right?

> If I try to see whats in those directories, NT 4.0 says: "Access is
> denied.".  I have to boot the machine and after that I can see that perl
> script has deleted all files but the directory is there. After booting
> the directory can be deleted manually.

It sounds to me like you're running into some sort of interaction with a
file that another process has open or that can't be removed due to locks
or some similar reason.  I'd be very, very surprised if all of the rmdir
and unlink calls actually succeeded and returned true.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 1924
**************************************

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