[23295] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5515 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 17 09:05:57 2003

Date: Wed, 17 Sep 2003 06:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 17 Sep 2003     Volume: 10 Number: 5515

Today's topics:
    Re: A newBie Query <thens@NOSPAMti.com>
    Re: backtracking in regular expression matching <ccwork@hotmail.com>
    Re: boston perl classes with damian conway (Chris Marshall)
    Re: boston perl classes with damian conway <dave@dave.org.uk>
    Re: c.l.p.announce MIA (was:  boston perl classes with  <graham.drabble@lineone.net>
        CGItemp-file and windows <mijn_postbak@msn.com>
    Re: CGItemp-file and windows <noreply@gunnar.cc>
    Re: CGItemp-file and windows <mijn_postbak@msn.com>
        current path <jochen.friedmann2@de.bosch.com>
    Re: current path <ak+usenet@freeshell.org>
    Re: current path <thens@NOSPAMti.com>
    Re: illegal seek news@roaima.freeserve.co.uk
    Re: kill command in a perl script <raisin@delete-this-trash.mts.net>
    Re: locatime() (Tom)
        opening a file whose letter case is unknown  <dostein@cisco.com>
    Re: opening a file whose letter case is unknown (Sam Holden)
    Re: opening a file whose letter case is unknown <kasp@epatra.com>
    Re: opening a file whose letter case is unknown <dostein@cisco.com>
    Re: opening a file whose letter case is unknown (Anno Siegel)
    Re: opening a file whose letter case is unknown <kurzhalsflasche@yahoo.co.uk>
    Re: Pattern Matching in file with invisible char (M Pires)
        pipe open question <dave.nospam@ntlworld.com>
    Re: pipe open question <no.name@eidosnet.co.uk>
    Re: pipe open question (Anno Siegel)
        Spreadsheet::WriteExcel, Excel formula won't calculate (Sven Jungnickel)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 17 Sep 2003 13:55:59 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: A newBie Query
Message-Id: <20030917135559.37faeda6.thens@NOSPAMti.com>

On Wed, 17 Sep 2003 12:25:26 +0530
"Naren" <narendranath.ts@in.bosch.com> wrote:

# Hello grp,
#         I am searching for a perfect match of a string in a line and want to
# replace all occurances of the string with a new string and also want a count
# of the replacements
# 
# What I mean by a perfect match is that it should not be a substring of any
# other string,should be independent.
# 
# $a is my string to be searched
# $cnt = ($line =~ s/$a\w+/$tobereplaceed)

  $cnt = ( $line =~ s/\b$a\b/$tobereplaced/g  )
                      ^^  ^^               ^^

  \b - asserts for a word boundary
   g - to repeat the search and replace globally for the string.

  Also, you might run into some problems when $a has some meta
characters like +, ?, (, ). Use Quotemeta to transform them. 

  perldoc perlre for more details.


Regards,
Thens.
 


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

Date: Wed, 17 Sep 2003 18:55:43 +0800
From: "ccwork" <ccwork@hotmail.com>
Subject: Re: backtracking in regular expression matching
Message-Id: <bk9egs$513$1@www.csis.hku.hk>

Hi,
    But how to interpret the 500 lines output? Any website recommended?
    Thanks.
"Thens" <thens@NOSPAMti.com>
???????:20030916174054.5c20a7b0.thens@NOSPAMti.com...
> On 16 Sep 2003 03:14:01 -0700
> ccwork@hotmail.com (ccwork) wrote:
>
>    You can use the 're' module to throw some more debug information to
> you.
>
> use re qw /debug/;
>   -- or --
> use re qw /debugcolor/;  # same with colored output
>
> see perldoc re for more details.
>
> Regards,
> Thens.
>




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

Date: 17 Sep 2003 00:14:18 -0700
From: c_j_marshall@hotmail.com (Chris Marshall)
Subject: Re: boston perl classes with damian conway
Message-Id: <cb9c7b76.0309162314.1ab4f4b@posting.google.com>

"Dave Cross" <dave@dave.org.uk> wrote in message news:<pan.2003.09.16.16.21.51.377384@dave.org.uk>...
> On Tue, 16 Sep 2003 04:58:06 -0700, Chris Marshall wrote:
> 
> > Uri Guttman <uri@stemsystems.com> wrote in message news:<x7llsp2w17.fsf@mail.sysarch.com>...
> >>
> >> damian conway will be teaching these classes in boston:
> > 
> > Any chance he'll ever come to London ?
> 
> He's been to London at least twice in the last couple of years.
> 

okay...any chance he'll come to London again ?


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

Date: Wed, 17 Sep 2003 08:23:23 +0100
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: boston perl classes with damian conway
Message-Id: <pan.2003.09.17.07.23.20.419889@dave.org.uk>

On Wed, 17 Sep 2003 00:14:18 -0700, Chris Marshall wrote:

> "Dave Cross" <dave@dave.org.uk> wrote in message news:<pan.2003.09.16.16.21.51.377384@dave.org.uk>...
>> On Tue, 16 Sep 2003 04:58:06 -0700, Chris Marshall wrote:
>> 
>> > Uri Guttman <uri@stemsystems.com> wrote in message news:<x7llsp2w17.fsf@mail.sysarch.com>...
>> >>
>> >> damian conway will be teaching these classes in boston:
>> > 
>> > Any chance he'll ever come to London ?
>> 
>> He's been to London at least twice in the last couple of years.
> 
> okay...any chance he'll come to London again ?

There's every chance. You might like to sign up to the London Perl Mongers
mailing list (see <http://london.pm.org/>) as they will almosrt certainly
be the first people to know.

Dave...

-- 
  Brian: Oh screw Maximilian!
  Sally: I do.
  Brian: So do I.



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

Date: Wed, 17 Sep 2003 10:43:53 +0100
From: Graham Drabble <graham.drabble@lineone.net>
Subject: Re: c.l.p.announce MIA (was:  boston perl classes with damian conway)
Message-Id: <Xns93F96D2A576B5grahamdrabblelineone@ID-77355.user.dfncis.de>

On 17 Sep 2003 merlyn@stonehenge.com (Randal L. Schwartz) wrote in
news:adcbd38a01b4db448df4471da6214835@news.teranews.com: 

>>>>>> "Graham" == Graham Drabble <graham.drabble@lineone.net>
>>>>>> writes: 
> 
> Graham> I might be able to take it on if someone will vounteer to
> be co- Graham> moderator. If it happens as I think it will then
> all you need to be Graham> able to do to become a moderator is
> send and receive e-mail, it isn't Graham> hard. If someone can
> send me the moderators address it will save me Graham> looking it
> up! 
> 
> No, you need to be able to *post* to a moderated newsgroup with
> the right magic to get it out.

I'm aware of that normally. Brian Edmonds (brian@gweep.ca) runs a mod 
bot that does most of that part for you. You simply have to 
communicate with it via e-mail commands.

> I was unaware that my chosen usenet posting host has been blocking
> all such attempts, legitimate or not, for a long time.  I'm in
> search of a posting host that will let me inject moderated
> articles.  Once I find that, I can again resume CLPA postings.

news.individual.net (was news.cis.dfn.de) will allow it if you ask on 
signup (free). You could also talk to newsguy.com, they will 
sometimes do complimentary accounts for this sort of thing. 
Alternatively if you got hold of Brian I'm sure you would be able to 
use his modbot.

-- 
Graham Drabble
If you're interested in what goes on in other groups or want to find 
an interesting group to read then check news.groups.reviews for what 
others have to say or contribute a review for others to read.


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

Date: Wed, 17 Sep 2003 13:42:10 +0200
From: "Arjen" <mijn_postbak@msn.com>
Subject: CGItemp-file and windows
Message-Id: <3f684d22$0$140$e4fe514c@dreader5.news.xs4all.nl>

Hi,

When uploading a file on a windows-server a CGItemp-file is created. This
file is not deleted after the upload.
Is there a way that this file will be deleted after upload ?
In which directorie is this file normally saved (and can I change the
directory) ?
Is it possible to know what the filename of this CGItemp-file is exactly
when a file is uploaded, so I can delete this file myself (within Perl).
Because now for every upload suchg a file is created, so I can not delete
all CGItemp-files after upload (maybe someone is uploading another file on
that moment and then I will delete that CGItemp-file also...)

Hope this explains what my problem is ;-)

Thx,

Arjen




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

Date: Wed, 17 Sep 2003 14:39:19 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGItemp-file and windows
Message-Id: <bk9kvj$pfu9u$1@ID-184292.news.uni-berlin.de>

Arjen wrote:
> When uploading a file on a windows-server a CGItemp-file is
> created. This file is not deleted after the upload.
> Is there a way that this file will be deleted after upload ?
> In which directorie is this file normally saved (and can I change
> the directory) ?
> Is it possible to know what the filename of this CGItemp-file is
> exactly when a file is uploaded, so I can delete this file myself
> (within Perl). Because now for every upload suchg a file is
> created, so I can not delete all CGItemp-files after upload (maybe
> someone is uploading another file on that moment and then I will
> delete that CGItemp-file also...)
> 
> Hope this explains what my problem is ;-)

Vaguely. Have you considered showing us some code?

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



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

Date: Wed, 17 Sep 2003 15:00:25 +0200
From: "Arjen" <mijn_postbak@msn.com>
Subject: Re: CGItemp-file and windows
Message-Id: <3f685aea$0$90745$e4fe514c@dreader7.news.xs4all.nl>

The code I use for this upload is:

open(ATT,">$upload_dir/$filename");
binmode ATT;
$buffer = "";
while (read($file_to_upload, $buffer, 1024)) {
    print ATT $buffer;
}
close ATT;




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

Date: Wed, 17 Sep 2003 14:18:28 +0200
From: "Jochen Friedmann" <jochen.friedmann2@de.bosch.com>
Subject: current path
Message-Id: <bk9jel$nic$1@ns2.fe.internet.bosch.com>

Hello together,

how can I find the current path my Perlscript is started ?

Jochen




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

Date: Wed, 17 Sep 2003 12:27:50 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: current path
Message-Id: <slrnbmgkq3.cru.ak+usenet@vinland.freeshell.org>

In article <bk9jel$nic$1@ns2.fe.internet.bosch.com>, Jochen Friedmann wrote:
> how can I find the current path my Perlscript is started ?

See the documentation for the FindBin module.


-- 
Andreas Kähäri


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

Date: Wed, 17 Sep 2003 18:00:08 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: current path
Message-Id: <20030917180008.3542de41.thens@NOSPAMti.com>

"Jochen Friedmann" <jochen.friedmann2@de.bosch.com> wrote:

# how can I find the current path my Perlscript is started ?

  I dont know what you meant by the current path. 

  If it is the current directory, you can get the current working
directory like this 

  use Cwd;
  my $dir = cwd();

   You can get the full path to the script name from the variable $0 and
then if you do a basename on it you can get the path to the directory
where the script is present. 

example :
script : /home/abc/scripts.pl 

#!/usr/bin/perl 

use strict;
use warnings;
use File::Basename;
my $dir =  File::basename($0);

-- 
Thens.





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

Date: Wed, 17 Sep 2003 08:45:06 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: illegal seek
Message-Id: <21gl31-gtt.ln1@news.roaima.co.uk>

Alan J. Flavell <flavell@mail.cern.ch> wrote:
> Well, for the moment I second Chris's proposal, since, as you imply,
> a more thoroughgoing answer may be too much to ask for.

So where do we go from here? Do you simply send your text as a patch to
the doc maintainers? Or does it need a consensus?

Cheers,
Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Wed, 17 Sep 2003 08:04:34 -0500
From: Barry Kimelman <raisin@delete-this-trash.mts.net>
Subject: Re: kill command in a perl script
Message-Id: <MPG.19d217da64c93363989686@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <257137ea.0309150913.11f08d49@posting.google.com>, 
skang@leaguedata.com says...
> I just started learning Perl and I am trying to do followings;
> 
> ps -ef | grep java >pidfile
> In pidfile, there are 3 PIDs for weblogic processes.
> 
>     root  1769  1758   TS   0  0 17:55:26 vt02    44:38
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms512m
> -Xmx512m -Dweb
>     root 27464 27453   TS  29  0 09:15:55 vt04    91:55
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms1024m
> -Xmx1024m -Dw
>     root 27533 27522   TS  49  0 09:21:45 vt03     2:35
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms32m
> -Xmx200m -Dwebl
> 
> What I want is get the largest PID which is 27533 in this case, and
> then
> kill -3 the PID.
> 
> So I made a simple one for this:
> 
> #!/usr/bin/perl 
> #
> #            This is a test script to get wls managed server pid
> #
> #
> open(JAVAPIDS,"pidfile") or die "can't open input file:$!\n";
> $pidcnt=0;
> while($line=<JAVAPIDS>) {
> #   ($user,$pid1,$pid2,$it4,$it5,$it6,$it7,$it8,$it9,$it10,$it11,$it12,$it13,$it14,$it15)=split("
> ",$line);
>    ($user,$pid1)=split(" ",$line);
>    $pidfile{$pid1}=$pid1;
>    $pid_comp[$pidcnt]=$pidfile{$pid1};
> #   print "pid$pidcnt : $pid_comp[$pidcnt] \n";
>    if ($pidcnt gt 0) {  
>        if ($pid_comp[0] < $pid_comp[$pidcnt]) {
>              $pid_comp[0] = $pid_comp[$pidcnt];
>       }
>    }
>    $pidcnt++;
> 
> }
> print "pidcnt : $pidcnt \n";
> print "Largest PID for java is : $pid_comp[0] \n";   
> 
> ------------------------------------------
> 
> Q1) How do I do 'kill -3 $pid_comp[0] in this script?
> Q2) Is there any way that I can do the followings:


Perl has a "kill" function. For more details do the following :

perldoc -f kill


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

Date: 17 Sep 2003 04:19:47 -0700
From: tom@ztml.com (Tom)
Subject: Re: locatime()
Message-Id: <59b4279a.0309170319.d188a7e@posting.google.com>

"Sam" <samj@austarmetro.com.au> wrote in message news:<3f678512$1@news.comindico.com.au>...
> hello
> I have a date array, I need to identify those dates which are Saturdays and
> Sundays. I think part of my problem is that I don't know how to search the
> documentations that came with perl5.6 in my Linux box. so I you could give
> some direction on how to do that tasks I am grateful
> 
> thanks

Reference book such as Programming Perl is a good alternate source of
getting the type of information that you're looking for. For instance,
if you look up localtime() you would see an example of getting the day
of the week from the function like this:

$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];

Although books are not cheap, but they may include information that
might be valuable and they are portable and require no AC or battery
to operate.

Tom
ztml.com


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

Date: Wed, 17 Sep 2003 12:49:19 +0300
From: Doron Stein <dostein@cisco.com>
Subject: opening a file whose letter case is unknown 
Message-Id: <1063792099.938089@sj-nntpcache-5>

  Say we have a file named "ABC" , yet A B and C can be upper or lower 
case each ( 8 combinations ).

how can one neatly open this file without preprocessing a directory 
content ?

i would have wanted something like


open(FILE, "ABC / ignore_case " )

  Thanks in advance

     Doron.



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

Date: 17 Sep 2003 10:06:41 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: opening a file whose letter case is unknown
Message-Id: <slrnbmgchh.c3n.sholden@flexal.cs.usyd.edu.au>

On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:
>   Say we have a file named "ABC" , yet A B and C can be upper or lower 
> case each ( 8 combinations ).
> 
> how can one neatly open this file without preprocessing a directory 
> content ?
> 
> i would have wanted something like
> 
> 
> open(FILE, "ABC / ignore_case " )

my $file = glob('[Aa][Bb][Cc]');
die "No file matching [Aa][Bb][Cc]" unless defined $file;
open(FILE, $file) or die "Unable to open $file: $!";

Of course that will just read all the filenames in the directory and find
the matches, and is probably inefficient since it will keep searching
after finding a match...

-- 
Sam Holden



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

Date: Wed, 17 Sep 2003 15:37:22 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: opening a file whose letter case is unknown
Message-Id: <bk9bp4$vc$1@newsreader.mailgate.org>

"Doron Stein" <dostein@cisco.com> wrote in message
news:1063792099.938089@sj-nntpcache-5...
> how can one neatly open this file without preprocessing a directory
> content ?
>
> i would have wanted something like
> open(FILE, "ABC / ignore_case " )

On an OS like Windows, all filenames (upper case or lower case) are treated
alike.
So,
    open(FILE, 'ABC.txt');
is same as
    open(FILE, 'abc.txt');

I don't know how you can achieve the same for Unix-like systems.
-- 
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Wed, 17 Sep 2003 13:50:11 +0300
From: Doron Stein <dostein@cisco.com>
Subject: Re: opening a file whose letter case is unknown
Message-Id: <3F683C63.5020507@cisco.com>

  Thanks sam fro the idea ,

  and say the file name is a variable , how can i imitate the '[Aa][Bb][Cc]'

    Doron.

Sam Holden wrote:
> On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:
> 
>>  Say we have a file named "ABC" , yet A B and C can be upper or lower 
>>case each ( 8 combinations ).
>>
>>how can one neatly open this file without preprocessing a directory 
>>content ?
>>
>>i would have wanted something like
>>
>>
>>open(FILE, "ABC / ignore_case " )
> 
> 
> my $file = glob('[Aa][Bb][Cc]');
> die "No file matching [Aa][Bb][Cc]" unless defined $file;
> open(FILE, $file) or die "Unable to open $file: $!";
> 
> Of course that will just read all the filenames in the directory and find
> the matches, and is probably inefficient since it will keep searching
> after finding a match...
> 



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

Date: 17 Sep 2003 11:11:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: opening a file whose letter case is unknown
Message-Id: <bk9fg7$9m9$1@mamenchi.zrz.TU-Berlin.DE>

Doron Stein  <dostein@cisco.com> wrote in comp.lang.perl.misc:
>   Thanks sam fro the idea ,
> 
>   and say the file name is a variable , how can i imitate the '[Aa][Bb][Cc]'
> 
>     Doron.

Please don't top-post, it's rude.

(my $pat = $name) =~ s/([[:alpha:]])/[\u$1\l$1]/g;

> Sam Holden wrote:
> > On Wed, 17 Sep 2003 12:49:19 +0300, Doron Stein <dostein@cisco.com> wrote:

[TOFU snipped]

Anno



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

Date: Wed, 17 Sep 2003 13:22:28 +0200
From: Dominik Seelow <kurzhalsflasche@yahoo.co.uk>
Subject: Re: opening a file whose letter case is unknown
Message-Id: <bk9g2v$r2njq$1@uni-berlin.de>

>   Say we have a file named "ABC" , yet A B and C can be upper or lower 
> case each ( 8 combinations ).
> 
> how can one neatly open this file without preprocessing a directory 
> content ?
> 
> i would have wanted something like
> 
> 
> open(FILE, "ABC / ignore_case " )
> 
>   Thanks in advance
> 
>      Doron.
> 
Hello Doron,

as you will have to care for the directory's content anyway, I suggest
to use grep and readdir:

opendir (DIR,'.') || die ($!);
my $filename='voId.txt';
open (FILE, ((grep /$filename/i,readdir DIR)[0])) || die ($!);

This will open the first file found.

HTH,
Dominik



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

Date: 17 Sep 2003 01:54:08 -0700
From: MIGUEL.PIRES@PORTUGALMAIL.PT (M Pires)
Subject: Re: Pattern Matching in file with invisible char
Message-Id: <6efa7ec7.0309170054.2e5e27e@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbmectb.4jq.tadmc@magna.augustmail.com>...

> > Is there a way around this?
> 
> 
>    perldoc -f binmode

Thank you very much! For reference the OS is W2K but your tip worked
like a charm. It's frustrating when the answer was in front of you all
along...!


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

Date: Wed, 17 Sep 2003 12:54:10 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: pipe open question
Message-Id: <qnirfnivyyragyjbeyqpbz.hldaya2.pminews@text.news.ntlworld.com>

I am having trouble getting to grips with piped opens - notably in
catching a failure. I have looked through my perl books and done a
google search but am not getting very far.

open FOO, "| bar" or die $!;
print "something";

if bar does not exist then the script stops with the die message
"something" is not printed. But if we have

open FOO, "|bar a_string_with_shell_metas" or die $!;
print "something";

then a fork gets involved to spawn a shell and the expected errors
occur - and the script says "something"  and keeps on going.

I found an article that implied you could use a test like:

my $pid =    open FOO, "|bar a_string_with_shell_metas";
if ( defined $pid)............

But that does not seem to work as I assume the pid is that of the
shell, that worked, rather than the failed bar.

So how can I *always* find out if the open failed, wether or not there
are metas in the string? Given that I see two types of failure - bar
does not exist, it does but failed to start for some other reason. 

TIA


Regards

Dave Saville

NB switch saville for nospam in address




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

Date: Wed, 17 Sep 2003 12:48:03 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: pipe open question
Message-Id: <bk9l63$43g$1@titan.btinternet.com>

You could place it in and eval block like so

eval {
    ...
    your code in here;
   ...
}

then just check $@ at the end of block to see if i encountered an error
during it's block.

Remeber with perl, there's always more than one way to do it.  So i''m not
saying this is the best way, but it's one way of doing it


D Borland
d (place a dot here) borland (an at-sign here) ntlword (and another dot
here) com


"Dave Saville" <dave.nospam@ntlworld.com> wrote in message
news:qnirfnivyyragyjbeyqpbz.hldaya2.pminews@text.news.ntlworld.com...
> I am having trouble getting to grips with piped opens - notably in
> catching a failure. I have looked through my perl books and done a
> google search but am not getting very far.
>
> open FOO, "| bar" or die $!;
> print "something";
>
> if bar does not exist then the script stops with the die message
> "something" is not printed. But if we have
>
> open FOO, "|bar a_string_with_shell_metas" or die $!;
> print "something";
>
> then a fork gets involved to spawn a shell and the expected errors
> occur - and the script says "something"  and keeps on going.
>
> I found an article that implied you could use a test like:
>
> my $pid =    open FOO, "|bar a_string_with_shell_metas";
> if ( defined $pid)............
>
> But that does not seem to work as I assume the pid is that of the
> shell, that worked, rather than the failed bar.
>
> So how can I *always* find out if the open failed, wether or not there
> are metas in the string? Given that I see two types of failure - bar
> does not exist, it does but failed to start for some other reason.
>
> TIA
>
>
> Regards
>
> Dave Saville
>
> NB switch saville for nospam in address
>
>


---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 9/11/03




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

Date: 17 Sep 2003 12:56:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: pipe open question
Message-Id: <bk9lmi$dfk$1@mamenchi.zrz.TU-Berlin.DE>

Dave Saville <dave.nospam@ntlworld.com> wrote in comp.lang.perl.misc:
> I am having trouble getting to grips with piped opens - notably in
> catching a failure. I have looked through my perl books and done a
> google search but am not getting very far.
> 
> open FOO, "| bar" or die $!;
> print "something";
> 
> if bar does not exist then the script stops with the die message
> "something" is not printed. But if we have
> 
> open FOO, "|bar a_string_with_shell_metas" or die $!;
> print "something";
> 
> then a fork gets involved to spawn a shell and the expected errors
> occur - and the script says "something"  and keeps on going.
> 
> I found an article that implied you could use a test like:
> 
> my $pid =    open FOO, "|bar a_string_with_shell_metas";
> if ( defined $pid)............
> 
> But that does not seem to work as I assume the pid is that of the
> shell, that worked, rather than the failed bar.

Quite so.

> So how can I *always* find out if the open failed, wether or not there
> are metas in the string? Given that I see two types of failure - bar
> does not exist, it does but failed to start for some other reason. 

With a sufficiently recent Perl you can avoid the shell invocation
with this form of open:

   open FOO, '|-',  'bar', '*' or die "$!";

instead of

   open FOO, 'bar *' or die "$!";

The first form will not use a shell, but exec the command "bar" with 
a literal asterisk as an argument.  So, if "bar" isn't found, open()
will fail.  Note that open() still doesn't indicate an error that
happens while "bar" is running, it returns too early to do that.  You
get those errors from close().

If you *want* the shell to run, the failure to find "bar" is such a run-time
error (of the shell) that cannot be picked up by open().  Close the pipe
explicitly and check the return value of close().  If it comes back false,
there was an error in executing the pipe and the return code is in $?.
So with a piped "open" involving a shell, two error checks are needed:

open my FOO, '| bar *' or die "$!";
# try working with FOO.
close FOO or die "command error $?";

In the part commented "try working with FOO", you will often already
notice if something's amiss.  You must be prepared to read unexpected
things from FOO (or, more likely, be unexpectedly unable to read
anything).

In one case, even close() doesn't indicate a failure to find "bar", which
is when the shell runs "bar" in the background, as in "open FOO, 'bar &'".
Here the shell always (well usually) succeeds, because all it does is a
fork.  That the child doesn't find "bar" doesn't concern it.

Anno


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

Date: 17 Sep 2003 04:08:46 -0700
From: Sven.Jungnickel@bmw.de (Sven Jungnickel)
Subject: Spreadsheet::WriteExcel, Excel formula won't calculate
Message-Id: <f1b78cf3.0309170308.c984a1e@posting.google.com>

I'm using the module Spreadsheet::WriteExcel to write an Excel file
from a Perl script which gets its date from a database. Some columns
of the worksheet should contain formulas. In general the writing of
formulas functions. When I open the Excel file the corresponding
columns have been calculated. But in columns where I use the function
SUMIF to calculate a mean value I'm having a problem. The formula is
written to the corresponding cells, but when I open the Excel file the
result is not calculated.

In order to get the result I have to click in the cells formula
editing field and then click onto the worksheet again. Each cell is
formatted as a number. I really don't have a clue what is going wrong
and what can I do against it.

Maybe anyone has encountered the same problem...Any hints are welcome.

Thanks in advance,

Sven


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

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

Ron wrote:

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

(---^


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

 ...
-- 
Bob Walton



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


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


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