[17890] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 50 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 12 14:10:43 2001

Date: Fri, 12 Jan 2001 11:10:17 -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: <979326616-v10-i50@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 12 Jan 2001     Volume: 10 Number: 50

Today's topics:
    Re: left op of && and || only in scalar context ? (Mark Jason Dominus)
    Re: left op of && and || only in scalar context ? nobull@mail.com
    Re: Michelle, this is great! nobull@mail.com
    Re: name of var $_ is pointing to? (Anno Siegel)
    Re: name of var $_ is pointing to? (Mark Jason Dominus)
        Need help with 5.6.0 <a565a87@my-deja.com>
    Re: Parsing the URL for Hidden variables <timallen449@my-deja.com>
    Re: Perl crashes on exit <alan.pettigrew@fox-europe.com>
    Re: Perl crashes on exit <alan@nospam.com>
    Re: Perl idioms for converting string into list of char <ren.maddox@tivoli.com>
        Putting text in an image? <eric.kort@vai.org>
    Re: Putting text in an image? <bart.lateur@skynet.be>
        regex puzzler <richard.bragg.bsc@ntl.remove.com>
    Re: regex puzzler <ren.maddox@tivoli.com>
    Re: regex puzzler (Richard J. Rauenzahn)
    Re: sed (unix) <Per-fredrik.Pollnow@epk.ericsson.se>
    Re: Shall use a reference instead? <joe+usenet@sunstarsys.com>
    Re: socket send to client problem (Garry Williams)
    Re: socket send to client problem <mischief@velma.motion.net>
    Re: system() method won't change directories! <mischief@velma.motion.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Jan 2001 16:25:30 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: left op of && and || only in scalar context ?
Message-Id: <3a5f2ffa.4e79$7f@news.op.net>

In article <93kgam$jb3$3@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>As you say, it makes no sense.

It makes sense to me.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 12 Jan 2001 18:16:03 +0000
From: nobull@mail.com
Subject: Re: left op of && and || only in scalar context ?
Message-Id: <u9d7dsiql8.fsf@wcl-l.bham.ac.uk>

"Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk> writes:

> <nobull@mail.com> wrote in message news:u9g0iqj7qn.fsf@wcl-l.bham.ac.uk...

> > do {
> >   my $expr1 = EXPR1; # Scalar context
> >   if ( $expr1 ) { # Boolean context
> >     $expr1;
> >   } else {
> >     EXPR2; # Inherits context
> >   }
> > }

> However, I should really have phrased the question
> differently, cos I wan't  to know why this is considered
> a feature, rather than a bug.

Because it's documented :-).

> It seems to me that if I write:
>
> @a = @b || @c;
> 
> either both sides should be evaluated in scalar context
> or both in list.

But if EXPR1 is evaluated in a list context there's no way of knowing
if EXPR1 would have been true in a scalar context.

> Maybe there's a problem with having to reevaluate the same
> expression in two different contexts ?

Yes - expressions can have side effects.  Consider: 

@a = foo() || bar();

I think having foo() called twice would be a considered a bug and not
a feature.  (Even if it were documented!).

The alternative would be to have EXPR2 evaluated in a scalar context.
I must admit this is what my intuition would have said.  But it's not
the way it is, and the way it is is the way it's documented so I'm not
gonna loose any sleep over this one.

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


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

Date: 12 Jan 2001 18:06:31 +0000
From: nobull@mail.com
Subject: Re: Michelle, this is great!
Message-Id: <u9hf34ir14.fsf@wcl-l.bham.ac.uk>

Nomen Nescio <nobody@dizum.com> writes:

> <script language="JavaScript">

Javascript techniques are off-topic here.

> function MM_openBrWindow(theURL,winName,features) { //v2.0
>   window.open(theURL,winName,features);
> }

> <body bgcolor="#FFFFFF" onLoad="MM_openBrWindow

Anyhow I can't see what's so great about putting a window.open in the
BODY's onLoad method - it's not exactly rocket science.

[ Sorry - couldn't resist ]

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


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

Date: 12 Jan 2001 16:14:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: name of var $_ is pointing to?
Message-Id: <93naga$mpi$2@mamenchi.zrz.TU-Berlin.DE>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote in comp.lang.perl.misc:
>Phil R Lawrence wrote in comp.lang.perl.misc:
>> How can I get the name of the var/glob/inner_thingee that $_ is currently
>> referencing?
>> 
>> Something like this would be cool:
>> 
>> foreach ($boo, $baz, $bif) {
>>     # Do something to change $_
>>     print LOG $_->true_name, ": $_\n";
>> }
>> 
>> resulting in:
>> 
>> ___my.log_______
>> boo: changed_boo
>> baz: changed_baz
>> bif: changed_bif
>
>So, reformulating your problem : you want to know to what thingy is
>aliased the loop variable in a foreach loop. Note that this thingy
>hasn't necessarily a name.
>
>If you really want to, you can use reference comparisons :
>
>  my ($a,$b,$c) = qw/A B C/;
>  foreach ($a,$b,$c) {
>    print "a: $a\n" if \$_ eq \$a;
>    print "b: $b\n" if \$_ eq \$b;
>    print "c: $c\n" if \$_ eq \$c;
>  }
>
>but, as you see, this is not very convenient.

Not only not very convenient, but it won't work (that is, identify
the variable we're dealing with) when some of the variables have the
same value.

>I don't know what your original problem is, but I suggest to use a hash.

Taken by itself, this sentence is rather humorous.  But, in a way,
it hits the nail on the head.  What the OP wants is to get at the
names of variables as data (he wants to print them).  While it is
possible in Perl, via the dreaded symrefs, to access a variable
whose name is known as a string, this is usually a bad idea.

When you want a name-value association where both names and values
are data, Perl provides hashes to do that.  Just put your values
in a hash whose keys are the (former) variable names.  Then the
update process could look like this (untested):

  while ( my ( $name, $value) = each %hash ) {
    my $new_value;
    # process, assign $new_value if update necessary
    if ( defined $new_value ) {
      print LOG "$name updated from $hash{ $name} to $new_value\n";
      $hash{ $name} = $new_value;
    }

This way you have access to names and values with no contortions.

Anno



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

Date: Fri, 12 Jan 2001 16:20:04 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: name of var $_ is pointing to?
Message-Id: <3a5f2eb4.4e5a$aa@news.op.net>

In article <93na5b$mpi$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>I don't know what your original problem is, but I suggest to use a hash.
>
>Taken by itself, this sentence is rather humorous.  

I laughed also.  I nominate it as the Perl Motto for the New Century.

>But, in a way, it hits the nail on the head.

It certainly does!

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 12 Jan 2001 17:34:20 GMT
From: Rob <a565a87@my-deja.com>
Subject: Need help with 5.6.0
Message-Id: <93nf6s$mv1$1@nnrp1.deja.com>

I'm compiling 5.6.0 using MSVC 6.0 nmake.  After a few minutes, when it
comes time for the build to link, I get this:

     cd .. && miniperl minimod.pl > lib\ExtUtils\Miniperl.pm
     The system cannot find the path specified.
     NMAKE : fatal error U1077: 'cd' : return code '0x1'
     Stop.

I have never been able to proceed beyond this point.  If I try to fudge
by manually adding the path that the makefile wants to see, then
something else pertaining to miniperl.pm just gets thrown in my face
that the linker can't deal with.  This should be relatively automatic,
shouldn't it?  The makefile should somehow have created that path for
me already but hasn't?  Should it?  What am I missing?

I'm brand new at perl, and I've never compiled it before.  (I'm only
doing it because the Active State perl doesn't work with mod_perl,
which I'd like to learn to use.)  Any advice?

Thank you for any information that you can provide about this.
-Rob


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 12 Jan 2001 16:36:47 GMT
From: tim allen <timallen449@my-deja.com>
Subject: Re: Parsing the URL for Hidden variables
Message-Id: <93nbqt$jnj$1@nnrp1.deja.com>

In article <3A5F16E4.3FFDA799@chartermi.net>,
  seppy@chartermi.net wrote:
> I'm trying to modify a pre-existing script that provides a guestbook
> to users.  The only thing I need to do is set it up to pass a hidden
> variable so the proper users guestbook is used.
> ... how I can parse out the hidden variables from the URL.
Hi Brian.  Try using the CGI module:
#/usr/bin/perl -w
use strict;
use CGI qw(:standard escapeHTML);

# get the user name (assumes a form element named USER_NAME
# careful, the form element name is case sensitive
my $user_name = param('USER_NAME');

# print header, start HTML page, etc.
print header(), start_html("simple form handler");

# clean up the user_name (I assume user name has to
# start with letter)
$user_name =~ s/^[^A-Za-z]*?([A-Za-z]\w+)\W*$/\1/;
print "<h1>USER_NAME = $user_name</h1>";

#match the first letter of the user_name
$user_name =~ m/^[^A-Za-z]*?([A-Za-z]).*$/;
my $first_letter = $1;
print "<p>$user_name starts with $first_letter</p>";
print end_html();

> How does the cgi get the info from the URL?
If you use the CGI module, you don't have to worry about how perl gets
form values-- param() reads either GET or POST.

> Also how would I take the variable that is passed, lets call it
> username and strip it to one character.
See the code I've included above.  Good luck! -tim


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 12 Jan 2001 10:09:20 GMT
From: Alan Pettigrew <alan.pettigrew@fox-europe.com>
Subject: Re: Perl crashes on exit
Message-Id: <VA.00000006.00331724@fox-europe.com>

In article <%Km76.2338$J%.246944@news.flash.net>,  wrote:
> From: blah@blah.blah.invalid
> Subject: Re: Perl crashes on exit
> Newsgroups: comp.lang.perl.misc
> Date: Thu, 11 Jan 2001 18:15:23 GMT
> 
 ..
> Are you checking for errors?
>  $dbh = DBI->connect(...)             or die $DBI::errstr;
>  $sth = $dbh->prepare(qq{SELECT ...}) or die $DBI::errstr;
>  $sth->execute                        or die $DBI::errstr;
>
Yes, I am checking for errors.  Also, the text of the SQL doesn't seem to matter, 
any valid SELECT seems to cause the crash.
The libwin32 (0.15.1), DBI (1.14) and DBD::ODBC (0.28) packages are up to date, 
according to PPM.

I would guess that a destructor is failing, but which one is the problem.

Alan



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

Date: Fri, 12 Jan 2001 12:36:03 GMT
From: Alan Pettigrew <alan@nospam.com>
Subject: Re: Perl crashes on exit
Message-Id: <VA.00000007.00b96ca2@fox-europe.com>

Further investigation seems to point to the basename function.

If I use:
   my @suff = ('.xml','.csv','.ini');
   $work = basename($file, @suff);
then the program crashes on exit.
If instead I use:
   $work = basename($file, '.xml');
   $work = basename($work, '.csv');
   $work = basename($work, '.ini');
then there is no crash.

Is the syntax of the basename wrong, or is there some bug?
The book says basename (fullname [, suffixlist]).

Is this merely moving where fields occur in memory, and masking the 
crash, or can I assume this is a workaround?

Alan
alan dot pettigrew at fox-europe dot com if you want the real address




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

Date: 12 Jan 2001 10:05:49 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Perl idioms for converting string into list of characters...
Message-Id: <m3u27492n6.fsf@dhcp11-177.support.tivoli.com>

Paul Laub <mr_joesixpack@yahoo.com> writes:

> I can't believe no one has mentioned using unpack. Here are two
> ways, though they may be too obscure to count as an "idiom".
> 
> map { chr $_ } unpack 'c*', $string

Yeah, I would say that this one wouldn't be an idiom -- it's kind of
cumbersome, and appears to be appreciably slower than the split and
match methods.

> unpack 'a' x length($string), $string

This one, on the other hand, is, in my opinion, very close to perfect.
If there were only some way to avoid calling length, I would
definitely prefer this over the others.  Not too surprisingly, it
appears to be significantly faster than any of the other methods.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 12 Jan 2001 11:30:31 -0500
From: "Eric" <eric.kort@vai.org>
Subject: Putting text in an image?
Message-Id: <93nb9c$1udb$1@msunews.cl.msu.edu>

Is there a perl module to help with placing text on an image?  For example,
I am writing a program to generate a histogram of an image (thus creating a
tiff), and I would like to be able to put numbers on the x axis scale.  Must
I draw the numbers pixel by pixel, or is there a simpler way?

Thanks,
Eric




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

Date: Fri, 12 Jan 2001 17:39:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Putting text in an image?
Message-Id: <j4gu5tcifmk7n8te4613tpsa8er9n5vudg@4ax.com>

Eric wrote:

>Is there a perl module to help with placing text on an image?  For example,
>I am writing a program to generate a histogram of an image (thus creating a
>tiff), and I would like to be able to put numbers on the x axis scale.  Must
>I draw the numbers pixel by pixel, or is there a simpler way?

Yes you must. I'm kidding, but the basic idea is correct: putting text
on an image is a graphical process. So one of the graphics manipulation
modules should be used. Look into GD and Image::Magick as the best
candidates, but the mere fact that you want to process a TIFF file might
be a serious stumbleblock. There are also some modules aimed at creating
histograms, I think GifGraph and PngGraph (sp?). These make use of GD
underneath. Check CPAN (<search.cpan.org>) for info and optional
download.

-- 
	Bart.


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

Date: Fri, 12 Jan 2001 17:36:23 +0000
From: Richard J Bragg <richard.bragg.bsc@ntl.remove.com>
Subject: regex puzzler
Message-Id: <3A5F4096.F9F05D73@ntl.remove.com>

I am trying to be very lazy and have another way to do this but what I
am looking for is something on the lines of

$_ = some_input;
/regex(.*)/;
print "$+\n";     # or something

rule is that if input contains ": " (colonspace) then I want what
follows the ": " else
I want the whole string.

e.g.
hello: world  ---> world
hello world   ---> hello world

TIA



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

Date: 12 Jan 2001 11:56:17 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: regex puzzler
Message-Id: <m3puhs8xj2.fsf@dhcp11-177.support.tivoli.com>

Richard J Bragg <richard.bragg.bsc@ntl.remove.com> writes:

> rule is that if input contains ": " (colonspace) then I want what
> follows the ": " else
> I want the whole string.

/.*: (.*)|(.*)/;

You can also through an s modifier on there to keep the trailing
newline if desired.  Also, this will match the *last* colon.  Add a ?
before the colon to have it match the first colon instead.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 12 Jan 2001 18:35:38 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: regex puzzler
Message-Id: <979324535.934406@hpvablab.cup.hp.com>

richard.bragg.bsc@ntl.remove.com writes:
>I am trying to be very lazy and have another way to do this but what I
>am looking for is something on the lines of
>
>$_ = some_input;
>/regex(.*)/;
>print "$+\n";     # or something
>
>rule is that if input contains ": " (colonspace) then I want what
>follows the ": " else
>I want the whole string.
>
>e.g.
>hello: world  ---> world
>hello world   ---> hello world

How about this:

my @data = <DATA>;

for(@data) { /^(.*?: )?(.*)/ && print "$2\n"; }

# or... nongreedy, depending on how you want "hello: cruel: world"
# to work out...

for(@data) { /^(.*: )?(.*)/ && print "$2\n"; }

__DATA__
hello: world
hello world
hello: cruel: world

$ perl5 -Mstrict -w ./foo
world
hello world
cruel: world
world
hello world
world


Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: Fri, 12 Jan 2001 17:03:46 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: Re: sed (unix)
Message-Id: <93n9ko$5be$1@newstoo.ericsson.se>

Thanks...
 It workt :=)

"Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
news:slrn95u10a.ho.rgarciasuarez@rafael.kazibao.net...
> Per- Fredrik Pollnow wrote in comp.lang.perl.misc:
> > Hi,
> > (OS/UNIX)
> > I was wondering, how do I do this in perl:
> >
> > sed -e '/^gunde:/s/\*LK\*/tada/' < shadow >shadow.new
>
> There's a program that comes with Perl that translates sed scripts to
> perl. Its name is s2p.
>
> But, if you want a Perl one-liner :
>
>   perl -pe '/^gunde:/&&s/\*LK\*/tada/' < shadow > shadow.new
>
> The difference is in only three characters.
>
> --
> # Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/




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

Date: 12 Jan 2001 12:09:18 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Shall use a reference instead?
Message-Id: <m3ely84s01.fsf@mumonkan.sunstarsys.com>

mjd@plover.com (Mark Jason Dominus) writes:

> In article <3tC76.841$LZ1.52075@bgtnsc05-news.ops.worldnet.att.net>,
> Michael Mayo <michael-a-mayo@worldnet.att.net> wrote:
> >"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
> >news:979294357.25187@itz.pp.sci.fi...
> >> No, not really.  The blessed thingy is the object, period.
> >
> >Yes, but you can't call any of the object's methods without using 
> >the reference.  
   ^^^
> But if you have the object, you can always make a reference to it.
                                                  ^
IMHO, that is the key point.  A single object can have many 
references to it, but they'll all point to the same object.  
Saying "the reference" is saying it wrong- every variable in 
perl can be de-referenced, and once a variable/object no 
longer has any references to it, it is "processed" by the 
garbage collector.

It may seem like pure semantics, but conceptually distinguishing 
referent (_the_ object) from reference (_a_ scalar) is IMHO the 
correct view. When you "bless a reference", you really "bless the 
reference's value" (the thingy)

>         bless \@a => 'Foo';
>         (\@a)->Method();

        my $ref = \@a;          # value is the location of the object 
        my $another_ref = $ref; # references the same object

Both of the above are Foo- object references (they "have methods", 
too), even though I didn't bless them.  They both refer to the 
_same_ object, though.

HTH
-- 
Joe Schaefer


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

Date: Fri, 12 Jan 2001 16:14:48 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: socket send to client problem
Message-Id: <Y3G76.56$Uz4.2116@eagle.america.net>

On Thu, 11 Jan 2001 20:29:33 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "GW" == Garry Williams <garry@zvolve.com> writes:
>
>  GW> On 11 Jan 2001 09:52:19 GMT, Anno Siegel
>  GW> <anno4000@lublin.zrz.tu-berlin.de> wrote:
>  >> 
>  >> Have you tried to check with select() (four-argument form)?  It should
>  >> tell you if a handle is ready to accept data.
>
>  GW> Won't help.  
>
>  GW> As Uri has pointed out before in this group, the socket is available
>  GW> only by finding out if it can be *read*.  Besides, even a reliable
>  GW> check will lead to a race condition.  Bad design.  An easy fix would
>  GW> be to handle the "program crashes out" condition -- whatever that
>  GW> means.  Or maybe the OP should just fork.  
>
>i am confused by the OP's problem and your comments. to test whether a
>socket got connected (especially using an async connect), you test for
>writeability, you don't have to write anything to it. to test for a
>socket closing on you, you test for readability and if you read 0 bytes,
>it closed. this assumes non-blocking reads which you should always use
>on sockets.

The latter is what I was referring to.  The OP complained about
writing to a closed socket.  The select() won't show this even if that
were a reasonable approach.  I should have said a non-zero return from
a non-blocking read is the way to know a socket is not closed.  

But the original question is wrong.  Checking before writing creates a
race condition.  

-- 
Garry Williams


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

Date: Fri, 12 Jan 2001 17:06:04 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: socket send to client problem
Message-Id: <t5uebsr20qk90a@corp.supernews.com>

Garry Williams <garry@zvolve.com> wrote:
> On Thu, 11 Jan 2001 20:29:33 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>>> "GW" == Garry Williams <garry@zvolve.com> writes:
>>
>>  GW> On 11 Jan 2001 09:52:19 GMT, Anno Siegel
>>  GW> <anno4000@lublin.zrz.tu-berlin.de> wrote:

[snip]

> The latter is what I was referring to.  The OP complained about
> writing to a closed socket.  The select() won't show this even if that
> were a reasonable approach.  I should have said a non-zero return from
> a non-blocking read is the way to know a socket is not closed.  

I always use blocking sockets and select. I test for the socket being
open, then write to it. I then recover from any errors that may pop up.
This is, of course, assuming I haven't forked off multiple servers. I
prefer to fork, but a whole lot of memory can be taken up forking in
Perl. Threads could be a better solution once I trust them enough for
production.

> But the original question is wrong.  Checking before writing creates a
> race condition.

A race condition and then an error recovery is still better than relying
on error recovery more often, isn't it? I write error recovery into my
software, but I try to cause as few error conditions as possible.

Chris

-- 
Christopher E. Stith

"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



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

Date: Fri, 12 Jan 2001 16:49:12 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: system() method won't change directories!
Message-Id: <t5udc8768r5t68@corp.supernews.com>

2obvious@my-deja.com wrote:
> In article <3a5d0d94$1@news.microsoft.com>,
>   "J?rgen Exner" <juex@deja.com> wrote:
>> <2obvious@my-deja.com> wrote in message news:93is6t$pi3
> $1@nnrp1.deja.com...


Disclaimer: Since this is a response to a Perl question on Windows,
            all references to 'perldoc -f foo' mean to look at the
            documentation for function 'foo', probably installed
            in the HTML documentation with ActiveState's ActivePerl.


[snip discussion of wanting to change directories.]

>> > cd "c:\Program Files\Application"
>> > Application /file="c:\WINDOWS\Desktop\File.txt"
>> [...]

Why not use chdir()? perldoc -f chdir


>> > So what can I do?  Is there a way to invoke more than one line in a
>> > system() call?  Any different/better suggestions?  Please help me
> out.

perldoc -f chdir

Your program actually does change directories when you do it from a shell.
It's just that a child (the program you run from the system() call)
can't change the environment of its parent (your program), so you end
up changing the directory for the duration of a call to 'cd'!


[snip discussion about changing directory and running external 
program on same command line. ]

>> Can't you simply use an absolute path to call the application:
>>     system 'c:/Program Files/Application/Application
>> /file="c:\WINDOWS\Desktop\File.txt"'
>>
>> jue

> Yes, I can, and thanks to you, I have.  Unfortunately, I can't insert a
> scalar in the middle of the command line.  But now my script does work
> (which is more than it did before), and beggars can't choose.

You can still put in a scalar. Use double quotes instead of single quotes.
Single quotes don't interpolate variables, which is why you are having
this problem. Of course, if you use double quotes, you'll either have to
use escaped backslashes (which is ugly), or switch to forward slashes
for your directory separators.

If you call an external program via the full path name, you run the
program but still aren't in the directory with it, so relative paths
from that program won't work.

I'd still prefer to use Perl's chdir() statement. That's what it's
there for. perldoc -f chdir

> Everyone in this newsgroup who helped me, a thousand thanks!

Hopefully this will help even more. :)

Chris

-- 
Christopher E. Stith

Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.



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

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


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