[9423] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3018 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 30 14:07:33 1998

Date: Tue, 30 Jun 98 10:52:00 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 30 Jun 1998     Volume: 8 Number: 3018

Today's topics:
    Re: problems with script (M.J.T. Guy)
    Re: problems with script (Bob Trieger)
    Re: problems with script <jdf@pobox.com>
    Re: problems with script <quednauf@nortel.co.uk>
    Re: problems with script (Bob Trieger)
    Re: problems with script <rra@stanford.edu>
    Re: problems with script (Craig Berry)
    Re: problems with script <quednauf@nortel.co.uk>
    Re: problems with script <tchrist@mox.perl.com>
    Re: problems with script <tchrist@mox.perl.com>
    Re: problems with script (Craig Berry)
    Re: problems with script (brian d foy)
    Re: problems with script (Craig Berry)
    Re: problems with script <tchrist@mox.perl.com>
    Re: problems with script <tchrist@mox.perl.com>
    Re: problems with script (brian d foy)
    Re: problems with script (Abigail)
    Re: problems with script (Abigail)
    Re: problems with script <tchrist@mox.perl.com>
    Re: problems with script <upsetter@ziplink.net>
    Re: problems with script <rra@stanford.edu>
    Re: problems with script (Craig Berry)
    Re: problems with script (Abigail)
    Re: problems with script (Matt Knecht)
    Re: Q: Can I run Perl program regularly? (Gary M. Greenberg)
    Re: Q: Can I run Perl program regularly? <gwynne@utkux.utk.edu>
        Q: Make write pass result to a function? (Brian Lavender)
    Re: Q: Make write pass result to a function? <rra@stanford.edu>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 29 Jun 1998 12:49:43 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: problems with script
Message-Id: <6n82h7$pto$1@pegasus.csx.cam.ac.uk>

In article <Ev1rqt.5sM@csc.liv.ac.uk>, I.J. Garlick <ijg@csc.liv.ac.uk> wrote:
>"Daniel J Adams" <dj_adams@earthlink.net> writes:
>> 
>> open (GETCOUNT,"<$fileserv/numero.dat");
>                  ^^^^^^^^^^^^^^^^^^^^^ 
>What do you think this is trying to do? I think it is trying to open the
>file stored in $fileserv/numero.dat (or something, I am not sure about the
>.dat, but my gut feeling is it will create problems)
>try:
>	
>	open (GETCOUNT,"<".$fileserv."/numero.dat");

That's a lot of nonsense.   The two forms will do exactly the same thing.
And most Perl programmers would regard the first form as stylistically
preferable.


Mike Guy


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

Date: Mon, 29 Jun 1998 13:16:42 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: problems with script
Message-Id: <6n847j$mgg$1@strato.ultra.net>

mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
-> In article <Ev1rqt.5sM@csc.liv.ac.uk>, I.J. Garlick <ijg@csc.liv.ac.uk>
->  wrote:
-> >"Daniel J Adams" <dj_adams@earthlink.net> writes:
-> >> 
-> >> open (GETCOUNT,"<$fileserv/numero.dat");
-> >                  ^^^^^^^^^^^^^^^^^^^^^ 
-> >What do you think this is trying to do? I think it is trying to open the
-> >file stored in $fileserv/numero.dat (or something, I am not sure about the
-> >.dat, but my gut feeling is it will create problems)
-> >try:
-> >       
-> >       open (GETCOUNT,"<".$fileserv."/numero.dat");
-> 
-> That's a lot of nonsense.   The two forms will do exactly the same thing.
-> And most Perl programmers would regard the first form as stylistically
-> preferable.

The first is better than the silly shit of the second, but neither is checking 
the status of the open and when reading a file the `<' is just a wasted 
keystroke.



Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
  and let the jerk that answers know that his
  toll free number was sent as spam. "


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

Date: 29 Jun 1998 09:57:18 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: problems with script
Message-Id: <ogvc6ysx.fsf@mailhost.panix.com>

sowmaster@juicepigs.com (Bob Trieger) writes:

> when reading a file the `<' is just a wasted keystroke.

On the contrary: since programs are meant to be human-readable, it's
good to be explicit about file modes.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: Mon, 29 Jun 1998 14:32:41 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: problems with script
Message-Id: <35979779.AEA3B97E@nortel.co.uk>

Bob Trieger wrote:

> ...and when reading a file the `<' is just a wasted keystroke.

Don't think so. When having quite a few files open, it is a good way to clarify
where you're reading from, writing to, appending at, etc.

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 29 Jun 1998 15:37:48 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: problems with script
Message-Id: <6n8cg5$ms7$1@ligarius.ultra.net>

[ posted and mailed ]

"F.Quednau" <quednauf@nortel.co.uk> wrote:
-> Bob Trieger wrote:
-> 
-> > ...and when reading a file the `<' is just a wasted keystroke.
-> 
-> Don't think so. When having quite a few files open, it is a good way to
->  clarify
-> where you're reading from, writing to, appending at, etc.

I find that it is even easier to differentiate when the files you are writing 
or appending to are the only ones with a `>' or `>>'. That way, any open 
without is a read.

It's definately just a question of personal preference. perlstyle doesn't 
mention it or I missed it there.

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
  and let the jerk that answers know that his
  toll free number was sent as spam. "


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

Date: 29 Jun 1998 08:44:22 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: problems with script
Message-Id: <m3g1gomcvd.fsf@windlord.Stanford.EDU>

Bob Trieger <sowmaster@juicepigs.com> writes:

> The first is better than the silly shit of the second, but neither is
> checking the status of the open and when reading a file the `<' is just
> a wasted keystroke.

Actually, it's not, in a somewhat surprising way.  From man perlfunc:

            The filename that is passed to open will have leading and
            trailing whitespace deleted. To open a file with arbitrary weird
            characters in it, it's necessary to protect any leading and
            trailing whitespace thusly:

                $file =~ s#^(\s)#./$1#;
                open(FOO, "< $file\0");

If your filename happens to begin with "|", ">", or some other similar
character, you *need* the "<" to prevent Perl from doing magic on the
open.

-- 
#!/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: 29 Jun 1998 15:40:10 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: problems with script
Message-Id: <6n8cgr$ljp$1@marina.cinenet.net>

Bob Trieger (sowmaster@juicepigs.com) wrote:
[snip]
: when reading a file the `<' is just a wasted keystroke.

It's certainly 'wasted' in the sense that it adds nothing to the semantics
of the operation.  However, in my own code I tend to include the redundant
'<' anyway, for two reasons.  First, it clearly documents that the
intention is to read the file; when eyeball-parsing code, little hints
like this can make all the difference.  This is similar to the practice of
using superfluous parens to group subexpressions in ways that precedence
would make happen anyway; the Perl parser doesn't need the help, but human
readers (including me six months from now) might.

Second, I'm compulsive about orthogonality.  Which means I probably
shouldn't be using Perl at all, but hey, I manage. :-)

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Mon, 29 Jun 1998 16:56:12 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: problems with script
Message-Id: <3597B91C.2A7AE075@nortel.co.uk>

Bob Trieger wrote:
> 
> [ posted and mailed ]
> 
> "F.Quednau" <quednauf@nortel.co.uk> wrote:
> -> Bob Trieger wrote:

> -> > ...and when reading a file the `<' is just a wasted keystroke.

[snip - my comment]
> 
[snip - Bob's comment]
> 
> It's definately just a question of personal preference. perlstyle doesn't
                                     ^^^^^^^^^^^^^^^^^^^
> mention it or I missed it there.

Cheers, much better than the 'wasted keystroke' :)

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 29 Jun 1998 16:30:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with script
Message-Id: <6n8fed$24p$4@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    "F.Quednau" <quednauf@nortel.co.uk> writes:
:> It's definately just a question of personal preference. perlstyle doesn't
:                                     ^^^^^^^^^^^^^^^^^^^
:Cheers, much better than the 'wasted keystroke' :)

It's somewhat more that that.  Ever try to open a file name ">fred"
for reading?

--tom
-- 
    "Have the appropriate amount of fun." --Larry Wall


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

Date: 29 Jun 1998 17:07:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with script
Message-Id: <6n8hl3$5bu$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    cberry@cinenet.net (Craig Berry) writes:
:It's certainly 'wasted' in the sense that it adds nothing to the semantics
:of the operation.  

That's not strictly true.   

--tom
-- 
Hackers should be judged by their hacking, not bogus criteria such as degrees,
age, race or position.  -- From _Hackers_ heroes of the computer revolution --


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

Date: 29 Jun 1998 17:42:45 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: problems with script
Message-Id: <6n8jml$1d9$1@marina.cinenet.net>

Tom Christiansen (tchrist@mox.perl.com) wrote:
:  [courtesy cc of this posting sent to cited author via email]
: 
: In comp.lang.perl.misc, 
:     cberry@cinenet.net (Craig Berry) writes:
: :It's certainly 'wasted' in the sense that it adds nothing to the semantics
: :of the operation.  
: 
: That's not strictly true.   

OK, 'wasted' modulo weird filenames with initial [<>+] chars.  But my
point was that it's worth putting in (IMO) even if the semantics are
identical with or without it.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Mon, 29 Jun 1998 14:13:07 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: problems with script
Message-Id: <comdog-ya02408000R2906981413070001@news.panix.com>
Keywords: from just another new york perl hacker

In article <6n8fed$24p$4@csnews.cs.colorado.edu>, tchrist@mox.perl.com (Tom Christiansen) posted:

> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, 
>    "F.Quednau" <quednauf@nortel.co.uk> writes:
>:> It's definately just a question of personal preference. perlstyle doesn't
>:                                     ^^^^^^^^^^^^^^^^^^^
>:Cheers, much better than the 'wasted keystroke' :)
>
>It's somewhat more that that.  Ever try to open a file name ">fred"
>for reading?

not until after you posted, but one can:

   #!/usr/bin/perl
   open(I, "< >fred") or die $!;
   while(<I>) {print}
   __END__

not that i would ever want to do such a silly thing outside of
some sort of obfuscation scheme :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>


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

Date: 29 Jun 1998 18:28:18 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: problems with script
Message-Id: <6n8mc2$1d9$5@marina.cinenet.net>

brian d foy (comdog@computerdog.com) wrote:
: In article <6n8fed$24p$4@csnews.cs.colorado.edu>, tchrist@mox.perl.com (Tom Christiansen) posted:
: >It's somewhat more that that.  Ever try to open a file name ">fred"
: >for reading?
: 
: not until after you posted, but one can:
: 
:    #!/usr/bin/perl
:    open(I, "< >fred") or die $!;
:    while(<I>) {print}
:    __END__
: 
: not that i would ever want to do such a silly thing outside of
: some sort of obfuscation scheme :)

It can be important if (e.g.) you're getting the filename from the user:

  print "Enter file name:";
  chomp(my $name = <>);

  open FOO, $name or die $!;

This will cause you grief if the user types '>myfile' -- or even
'<myfile'.  (Users who actually do that should be shot, of course, but
that's a separate issue.)

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 29 Jun 1998 18:52:04 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with script
Message-Id: <6n8nok$cqf$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    cberry@cinenet.net (Craig Berry) writes:
:It can be important if (e.g.) you're getting the filename from the user:
:
:  print "Enter file name:";
:  chomp(my $name = <>);
:
:  open FOO, $name or die $!;
:
:This will cause you grief if the user types '>myfile' -- or even
:'<myfile'.  (Users who actually do that should be shot, of course, but
:that's a separate issue.)

I represent that remark.

In perlfunc.pod (super latest)


    The filename passed to open will have leading and trailing whitespace
    deleted, and the normal redirection chararacters honored.  This
    property, known as "magic open", can often be used to good effect.
    A user could specify a filename of "rsh cat file |", or you could
    change certain filenames as needed:

	$filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
	open(FH, $filename) or die "Can't open $filename: $!";

    However, to open a file with arbitrary weird characters in it,
    it's necessary to protect any leading and trailing whitespace:

	$file =~ s#^(\s)#./$1#;
	open(FOO, "< $file\0");


In perlipc.pod (super latest)

    If one can be sure that a particular program is a Perl script that
    is expecting filenames in @ARGV, the clever programmer can write
    something like this:

	% program f1 "cmd1|" - f2 "cmd2|" f3 < tmpfile

    and irrespective of which shell it's called from, the Perl program
    will read from the file F<f1>, the process F<cmd1>, standard input
    (F<tmpfile> in this case), the F<f2> file, the F<cmd2> command,
    and finally the F<f3> file.  Pretty nifty, eh?

--tom
-- 
It's all magic.  :-)    --Larry Wall in <7282@jpl-devvax.JPL.NASA.GOV>


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

Date: 29 Jun 1998 17:56:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with script
Message-Id: <6n8kgi$9uk$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    cberry@cinenet.net (Craig Berry) writes:
:But my
:point was that it's worth putting in (IMO) even if the semantics are
:identical with or without it.

I'm in general agreement there.  But magic open is a buddy of mine.

--tom
-- 
	    Blood and flood are not like food,
	    Nor is mould like should and would.


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

Date: Mon, 29 Jun 1998 16:36:14 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: problems with script
Message-Id: <comdog-ya02408000R2906981636140001@news.panix.com>
Keywords: from just another new york perl hacker

In article <6n8mc2$1d9$5@marina.cinenet.net>, cberry@cinenet.net (Craig Berry) posted:

>brian d foy (comdog@computerdog.com) wrote:

>: In article <6n8fed$24p$4@csnews.cs.colorado.edu>, tchrist@mox.perl.com (Tom Christiansen) posted:

>: >It's somewhat more that that.  Ever try to open a file name ">fred"
>: >for reading?

>:    #!/usr/bin/perl
>:    open(I, "< >fred") or die $!;

>It can be important if (e.g.) you're getting the filename from the user:
>
>  print "Enter file name:";
>  chomp(my $name = <>);

of course, we're checking filenames to make sure that they are
sensible, right?

for instance,

   $filename = 'rm -rf / |';

is not really a Good Thing :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>


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

Date: 29 Jun 1998 21:21:27 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: problems with script
Message-Id: <6n90gn$nk0$1@client3.news.psi.net>

Russ Allbery (rra@stanford.edu) wrote on MDCCLXIII September MCMXCIII in
<URL: news:m3g1gomcvd.fsf@windlord.Stanford.EDU>:
++ Bob Trieger <sowmaster@juicepigs.com> writes:
++ 
++ > The first is better than the silly shit of the second, but neither is
++ > checking the status of the open and when reading a file the `<' is just
++ > a wasted keystroke.
++ 
++ Actually, it's not, in a somewhat surprising way.  From man perlfunc:
++ 
++             The filename that is passed to open will have leading and
++             trailing whitespace deleted. To open a file with arbitrary weird
++             characters in it, it's necessary to protect any leading and
++             trailing whitespace thusly:
++ 
++                 $file =~ s#^(\s)#./$1#;
++                 open(FOO, "< $file\0");
++ 
++ If your filename happens to begin with "|", ">", or some other similar
++ character, you *need* the "<" to prevent Perl from doing magic on the
++ open.


Wouldn't the following work as well?

   $file = "./$file" unless substr $file, 0, 1 eq '/';
   open FOO, $file or die "Eeeps: $!";



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 29 Jun 1998 21:23:13 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: problems with script
Message-Id: <6n90k1$nk0$2@client3.news.psi.net>

Craig Berry (cberry@cinenet.net) wrote on MDCCLXIII September MCMXCIII in
<URL: news:6n8cgr$ljp$1@marina.cinenet.net>:
++ Bob Trieger (sowmaster@juicepigs.com) wrote:
++ [snip]
++ : when reading a file the `<' is just a wasted keystroke.
++ 
++ It's certainly 'wasted' in the sense that it adds nothing to the semantics
++ of the operation.  However, in my own code I tend to include the redundant
++ '<' anyway, for two reasons.  First, it clearly documents that the
++ intention is to read the file; when eyeball-parsing code, little hints
++ like this can make all the difference.  This is similar to the practice of
++ using superfluous parens to group subexpressions in ways that precedence
++ would make happen anyway; the Perl parser doesn't need the help, but human
++ readers (including me six months from now) might.

I dunno. Where does it stop?

   ($foo = (($bar) + (7)));


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 29 Jun 1998 21:08:11 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with script
Message-Id: <6n8vnr$ils$1@csnews.cs.colorado.edu>
Keywords: from just another new york perl hacker

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

In comp.lang.perl.misc, 
    comdog@computerdog.com (brian d foy) writes:
:of course, we're checking filenames to make sure that they are
:sensible, right?  for instance,
:   $filename = 'rm -rf / |';
:is not really a Good Thing :)

Why should you care?  Let the user do as they will.  

--tom
-- 
"When I originally designed Perl 5's OO, I thought about a lot of this
stuff, and chose the explicit object model of Python as being the least
confusing. So far I haven't seen a good reason to change my mind on that."
(Larry Wall, February 1997, on perl5-porters)


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

Date: 29 Jun 1998 21:50:30 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: problems with script
Message-Id: <6n9276$42j@fridge.shore.net>

Abigail <abigail@fnx.com> wrote:
: ++ like this can make all the difference.  This is similar to the practice of
: ++ using superfluous parens to group subexpressions in ways that precedence
: ++ would make happen anyway; the Perl parser doesn't need the help, but human
: ++ readers (including me six months from now) might.

: I dunno. Where does it stop?

:    ($foo = (($bar) + (7)));

When it stops being helpful and starts obfuscating. Duh.

--Art

--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
            http://www.ziplink.net/~upsetter/ska/calendar.html
--------------------------------------------------------------------------


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

Date: 29 Jun 1998 14:57:25 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: problems with script
Message-Id: <m33ecnhnwa.fsf@windlord.Stanford.EDU>

Abigail <abigail@fnx.com> writes:
> Russ Allbery (rra@stanford.edu) wrote:

>> Actually, it's not, in a somewhat surprising way.  From man perlfunc:

>>             The filename that is passed to open will have leading and
>>             trailing whitespace deleted. To open a file with arbitrary
>>             weird characters in it, it's necessary to protect any
>>             leading and trailing whitespace thusly:

>>                 $file =~ s#^(\s)#./$1#;
>>                 open(FOO, "< $file\0");

>> If your filename happens to begin with "|", ">", or some other similar
>> character, you *need* the "<" to prevent Perl from doing magic on the
>> open.

> Wouldn't the following work as well?

>    $file = "./$file" unless substr $file, 0, 1 eq '/';
>    open FOO, $file or die "Eeeps: $!";

This doesn't help against trailing whitespace in the file name, but other
than that yeah, it should.

-- 
#!/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: 29 Jun 1998 22:32:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: problems with script
Message-Id: <6n94l5$ipc$1@marina.cinenet.net>

Abigail (abigail@fnx.com) wrote:
: Craig Berry (cberry@cinenet.net) wrote on MDCCLXIII September MCMXCIII in
: <URL: news:6n8cgr$ljp$1@marina.cinenet.net>:
: ++ This is similar to the practice of
: ++ using superfluous parens to group subexpressions in ways that precedence
: ++ would make happen anyway; the Perl parser doesn't need the help, but human
: ++ readers (including me six months from now) might.
: 
: I dunno. Where does it stop?
: 
:    ($foo = (($bar) + (7)));

Wherever you want it to; this is just a human-readability thing, after
all.  I wouldn't parenthsize

  $x = $y * 4 + 7;

because most of us have multiplication vs. addition precedence hardwired
into our brains at this point.  However,  I might parenthesize e.g.

  $x = 7 + y % 4;

since the relative precedence of + and % doesn't leap off the screen at me
(though I can of course remember it with little effort).

Superfluous parentheses are in the same category with use of whitespace
and placement of curly braces -- meaningless to the parser, potentially
helpful to human readers, and amenable to endless unresolvable religious
wars should folks with differing views start arguing over the issue.  De
gustibus non est disputandum. 

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 30 Jun 1998 03:44:39 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: problems with script
Message-Id: <6n9mv7$qoj$1@client3.news.psi.net>

Russ Allbery (rra@stanford.edu) wrote on MDCCLXIII September MCMXCIII in
<URL: news:m33ecnhnwa.fsf@windlord.Stanford.EDU>:
++ Abigail <abigail@fnx.com> writes:
++ > Russ Allbery (rra@stanford.edu) wrote:
++ 
++ >> Actually, it's not, in a somewhat surprising way.  From man perlfunc:
++ 
++ >>             The filename that is passed to open will have leading and
++ >>             trailing whitespace deleted. To open a file with arbitrary
++ >>             weird characters in it, it's necessary to protect any
++ >>             leading and trailing whitespace thusly:
++ 
++ >>                 $file =~ s#^(\s)#./$1#;
++ >>                 open(FOO, "< $file\0");
++ 
++ >> If your filename happens to begin with "|", ">", or some other similar
++ >> character, you *need* the "<" to prevent Perl from doing magic on the
++ >> open.
++ 
++ > Wouldn't the following work as well?
++ 
++ >    $file = "./$file" unless substr $file, 0, 1 eq '/';
++ >    open FOO, $file or die "Eeeps: $!";
++ 
++ This doesn't help against trailing whitespace in the file name, but other
++ than that yeah, it should.


Actually not, as something can have a trailing '|'; which would
read from a pipe instead of reading from a file with a trailing '|'.



Abigail
-- 
perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'


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

Date: Tue, 30 Jun 1998 15:17:48 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: problems with script
Message-Id: <wk7m1.60$zY.548756@news3.voicenet.com>

Abigail <abigail@fnx.com> wrote:
>I dunno. Where does it stop?
>
>   ($foo = (($bar) + (7)));

Long before that, hopefully!  I can't remember where I read it, but a
very good book about C says something to the effect of: "You need only
remember one rule of precedence.  Multiplication and division come
before addition and subtraction.  Any else, use parentheses."  Of
course, in C you don't have to worry about the precedence of '='.

I think this style is a Good Thing(tm):

if (!((($a < $b) && ($c > $d)) || $f))

Which is probably best split onto seperate lines, but when you're in
80x24 and screen space is precious, you can bend the rules. :)

-- 
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"


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

Date: Sun, 28 Jun 1998 21:55:03 GMT
From: garyg@gator.net (Gary M. Greenberg)
Subject: Re: Q: Can I run Perl program regularly?
Message-Id: <MPG.100084d2f1d8cd54989686@news.gator.net>

In article <358ecba4.0@rapeme.kirov.ru>, dmgl@dmgl.kirov.ru says...
> Dear Sir/Madam
> 
> How can I make a program that can run my Perl program regularly (daily)?

Give it more vitamins.

Cheers,
 
gary         -=-  The C Programmers' Reference  -=-
              http://www.gator.net/~garyg/C/c.html
        -=-  Avenue Programmers' Classes' Requests  -=-
             http://www.gator.net/~garyg/class.htm


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

Date: Sun, 28 Jun 1998 20:28:28 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: Q: Can I run Perl program regularly?
Message-Id: <6n6n91$rsa$1@gaia.ns.utk.edu>

crontab

It's a Unix question.

Bob Gwynne


Gary M. Greenberg wrote in message ...
>In article <358ecba4.0@rapeme.kirov.ru>, dmgl@dmgl.kirov.ru says...
>> Dear Sir/Madam
>>
>> How can I make a program that can run my Perl program regularly (daily)?
>
>Give it more vitamins.
>
>Cheers,
>
>gary         -=-  The C Programmers' Reference  -=-
>              http://www.gator.net/~garyg/C/c.html
>        -=-  Avenue Programmers' Classes' Requests  -=-
>             http://www.gator.net/~garyg/class.htm




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

Date: Sun, 28 Jun 1998 06:28:17 GMT
From: brian@brie.com (Brian Lavender)
Subject: Q: Make write pass result to a function?
Message-Id: <3597df35.40880988@news.jps.net>

I have the following chunk of code which has a format and a write
statement. I want the result of the write passed to the ent function
so it can encode the HTML entities. How do I make this work? Currently
the write sends it straight to STDOUT.

#!/usr/bin/perl

$rep_name = "<b>Bill Baker</b>";
$~ = SAYIT2;
print ent(write); # Write passes the result to STDOUT instead of the
		  # ent function

## return $_[0] encoded for HTML entities
sub ent {
  local $_ = shift;
  $_ =~ s/["<&>"]/"&#".ord($&).";"/ge;  # entity escape
  $_;
}

format SAYIT2 = 

The customer would like 
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
$rep_name
to contact him/her about mortgages and home equity loans.
 .


--------
Brian E. Lavender
http://www.brie.com/brian/

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge. 
                                 --Peter J. Schoenster


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

Date: 28 Jun 1998 00:56:17 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Q: Make write pass result to a function?
Message-Id: <m34sx6yn6m.fsf@windlord.Stanford.EDU>

Brian Lavender <brian@brie.com> writes:

> I have the following chunk of code which has a format and a write
> statement. I want the result of the write passed to the ent function so
> it can encode the HTML entities. How do I make this work? Currently the
> write sends it straight to STDOUT.

Unfortunately, in order to get the output from a format into a variable,
you need to use the low-level formline interface rather than calling write
directly.  It's a bit more complicated; see man perlfunc for details.

In this case, though, any reason not to just use a substr to accomplish
the same thing that your format is doing for you?

-- 
#!/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 3018
**************************************

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