Mark M. Hoffman on 25 Jun 2009 10:09:22 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] question re: perl diamond operator


Hi:

* Edmond Rodriguez <erodrig_97@yahoo.com> [2009-06-25 09:57:24 -0700]:
> 
> If you put in two files that don't exist you get two error messages.
> 
> If you put in one file that does not exist followed by one that does, it
> still processes the one that does exist.  Is it designed to be fail safe for
> this invocation?
> 
> 
> $ ./example.pl foo foo2
> Can't open foo: No such file or directory at ./example.pl line 3.
> this is foo line 1this is foo line 2
> 
> $ echo $?
> 0

Yeah good question... it's funny because the motivation for <> in perl seems
to be to copy the way standard UNIX utils work.  E.g. 

	$ cat file1 file2

... will throw an error about non-existent file1, then proceed to cat the
contents of file2.  The perl diamond operator does the same.  However, cat
still returns a non-zero exit code in this case.  I couldn't find a way to
"test" the diamond operator to easily duplicate this behavior.

But anyway... see my other message for a method that works for me.

> ----- Original Message ----
> > From: Mark M. Hoffman <mhoffman@lightlink.com>
> > To: plug@lists.phillylinux.org
> > Sent: Thursday, June 25, 2009 12:24:20 PM
> > Subject: [PLUG] question re: perl diamond operator
> > 
> > Hi all:
> > 
> > Given the following trivial script:
> > 
> > >> #! /usr/bin/perl -w
> > >> 
> > >> while (<>) {
> > >>     chomp;
> > >>     print $_;
> > >> }
> > 
> >     $ ./example.pl foo
> >     Can't open foo: No such file or directory at ./example.pl line 3.
> > 
> > So far so good; the file foo really does not exist.
> > 
> >     $ echo $?
> >     0
> > 
> > Really?  I want the exit status to be non-zero here.  I've looked through the
> > perl documentation; I can't see any way to get the diamond operator to do what
> > I want in this case.  I would appreciate any suggestions from perl experts.

Thanks & regards,

-- 
Mark M. Hoffman
mhoffman@lightlink.com

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug