[24015] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6213 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 4 09:05:53 2004

Date: Thu, 4 Mar 2004 06:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 4 Mar 2004     Volume: 10 Number: 6213

Today's topics:
        'require $test;' works? <ravisankars74@hotmail.com>
        alternative ways for writing many if-else <yamini_rajan@nospam.com>
    Re: alternative ways for writing many if-else <nobull@mail.com>
    Re: alternative ways for writing many if-else <nobull@mail.com>
        Can package prefix be avoided? <ravisankars74@hotmail.com>
    Re: Double Jump Box Redirection <mr@sandman.net>
    Re: Double Jump Box Redirection <usenet@morrow.me.uk>
    Re: new to perl <t_lawetta@yahoo.com>
    Re: new to perl <t_lawetta@yahoo.com>
    Re: new to perl <arthur0421@163.com>
    Re: new to perl <usenet@morrow.me.uk>
    Re: new to perl <arthur0421@163.com>
    Re: Perl & Sessions? (another one)
    Re: Problem open'ing a file to read utf16 <usenet@morrow.me.uk>
    Re: Removing accents from spanish characters <noreply@gunnar.cc>
    Re: This drives me crazy !!! <tassilo.parseval@rwth-aachen.de>
    Re: What with this open file descriptor/"Read on closed <tassilo.parseval@rwth-aachen.de>
    Re: What with this open file descriptor/"Read on closed <matthew.garrish@sympatico.ca>
    Re: What with this open file descriptor/"Read on closed <tassilo.parseval@rwth-aachen.de>
    Re: What with this open file descriptor/"Read on closed <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 4 Mar 2004 19:23:44 +0530
From: "Ravisankar Sivasubramaniam" <ravisankars74@hotmail.com>
Subject: 'require $test;' works?
Message-Id: <1078408327.942256@sj-nntpcache-5>

I have package file as follows

test.pm
--------
package test;
 ...
 ...
1;
-------------------------

I want to import the variables in this file to another.  The compiler goes
through if I add

require test;

but fails with the following error message if I add

$var = test;
require $var;

Can't locate test in @INC (@INC contains:
/opt/perl/packages/5.004_04/sparc-sun-solaris2.6/lib
/opt/perl/packages/5.004_04/lib
/opt/perl/packages/5.004_04/lib/site_perl/sparc-sun-solaris2.6
/opt/perl/packages/5.004_04/lib/site_perl .) at UpgradeNodes.pl line 26.

Can anyone tell what the problem?

Thanks,
Ravi




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

Date: Thu,  4 Mar 2004 06:15:01 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: alternative ways for writing many if-else
Message-Id: <6030e546d5b5b81862129501690a2bf1@localhost.talkaboutprogramming.com>

hi,

$a="<Bppf>protein</Bppf>";
$b="<p>kinase</p>";
         --or---
$a="<p>kinase</p>";
$b="<Bppf>protein</Bppf>";

 if (($a =~ /^<Bppf>/g) && ($b =~ /^(<p>|<B>)/g))
                {                      
                     $ret=$b;
            }
--->elsif(($a =~ /^(<p>|<B>)/g) && ($b =~ /^<Bppf>/g))
                {
                      $ret= $a ;
                }

elsif (($a =~ /^<Bpcf>/g) && ($b =~ /^<c>/g))
                {
                      $ret=$b;                        
                }
else{
$ret=0;
}
-This is a part of my program
In the place marked -->,is it the only way to check the alternative value of $a and $b?
if no,can u help me in writing an efficient code than this?

thanks!!!



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

Date: 04 Mar 2004 13:00:10 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: alternative ways for writing many if-else
Message-Id: <u9r7w822ed.fsf@wcl-l.bham.ac.uk>

"yamini" <yamini_rajan@nospam.com> writes:

> hi,
> 
> $a="<Bppf>protein</Bppf>";
> $b="<p>kinase</p>";
>          --or---
> $a="<p>kinase</p>";
> $b="<Bppf>protein</Bppf>";
> 
>  if (($a =~ /^<Bppf>/g) && ($b =~ /^(<p>|<B>)/g))
>                 {                      
>                      $ret=$b;
>             }
> --->elsif(($a =~ /^(<p>|<B>)/g) && ($b =~ /^<Bppf>/g))
>                 {
>                       $ret= $a ;
>                 }
> 
> elsif (($a =~ /^<Bpcf>/g) && ($b =~ /^<c>/g))
>                 {
>                       $ret=$b;                        
>                 }
> else{
> $ret=0;
> }
> -This is a part of my program

Looks to me like you should be using an XML processor.

> In the place marked -->,is it the only way to check the alternative value of $a and $b?
> if no,can u help me in writing an efficient code than this?

Do you know what a /g means on a m// in a scalar context?

Do you really want those semantics?  I doubt it.  I think you could
get some really weird effects.

Anyhow to answer your question I can think of no way to simplify the
one line in isolation. 

There are almost certainly much better ways to do whatever it is you
want but without knowing what that is I can't really help.

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


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

Date: 04 Mar 2004 13:02:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: alternative ways for writing many if-else
Message-Id: <u9n06w22a5.fsf@wcl-l.bham.ac.uk>

"yamini" <yamini_rajan@nospam.com> writes:

> Subject: alternative ways for writing many if-else

[ snip body asking different question ]

In my previous follow-up I answered the question in the message body.

To answer the question in the subject line:

See FAQ: How do I create a switch or case statement?

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


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

Date: Thu, 4 Mar 2004 19:28:16 +0530
From: "Ravisankar Sivasubramaniam" <ravisankars74@hotmail.com>
Subject: Can package prefix be avoided?
Message-Id: <1078408600.27715@sj-nntpcache-5>

I have a package file as follows:

test.pm
-------
package test;
 ...
$name = "World";
 ...
1;
-----------------------------

In the main program, if I add

use test;

I can acces the package variables without package prefix.  For example I can
do the following:

print $name;

But if I add

require test;

I can access the package variables only with the package prefix.  For
example, I can do only the following:

print $test::name;

Is here a way to do away with the package prefix when employing 'require'?

Thanks,
Ravi




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

Date: Thu, 04 Mar 2004 14:02:41 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Double Jump Box Redirection
Message-Id: <mr-4C5EC1.14024104032004@news.fu-berlin.de>

In article <f18c773b.0403031758.4a80bb8c@posting.google.com>,
 kenton_mcleod@hotmail.com (Kenton) wrote:

> Sandman <mr@sandman.net> wrote in message 
> news:<mr-B4933B.18140827022004@news.fu-berlin.de>...
> > 
> > All you seem to have recieved was attitude.
> > 
> 
> You're not wrong ... thanks for your help Sandman, nuts to the rest of
> you.
> 
> I am fully aware that what I had was JS. 
> Sorry if that wasn't clear.
> 
> I also said that I'd been scared off JS which is why I wasn't posting
> to a JS group.
> Sorry if that wasn't clear.
> 
> I listed the JS just to show what I already had (and wanted to
> replace)
> Sorry if that wasn't clear.
> 
> I wanted to use a cgi script and I thought this was an appropriate
> place to post.
> Sorry if that wasn't clear.
> 
> Bugger it ... Javascript programmers are friendlier I'll just go and
> see them and do it their way. Obviously 5/6 perl programmers are rude.

Not really, but many oldies in this group are eager to complain about what they 
feel are posts that aren't up to a certain standard. They have no tolerance for 
newbies. 

It's a shame, since it's a *.misc group. there are posting "rules" here, and 
they are a great reference, but being naive enough to think that everyone 
should follow them is a little too much.

You posted to the correct group and I hope my post at least helped some.

-- 
Sandman[.net]


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

Date: Thu, 4 Mar 2004 13:39:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Double Jump Box Redirection
Message-Id: <c27bho$e2q$1@wisteria.csv.warwick.ac.uk>


Sandman <mr@sandman.net> wrote:
> In article <f18c773b.0403031758.4a80bb8c@posting.google.com>,
>  kenton_mcleod@hotmail.com (Kenton) wrote:
> > Sandman <mr@sandman.net> wrote in message 
> > news:<mr-B4933B.18140827022004@news.fu-berlin.de>...
> > > 
> > > All you seem to have recieved was attitude.
> > 
> > You're not wrong ... thanks for your help Sandman, nuts to the rest of
> > you.

If you're looking for help here, talking like that's hardly going to
improve your chances...

> > I listed the JS just to show what I already had (and wanted to
> > replace)
> > Sorry if that wasn't clear.
> > 
> > I wanted to use a cgi script and I thought this was an appropriate
> > place to post.
> > Sorry if that wasn't clear.

What wasn't the least bit clear was that you wanted to replace the JS
with a Perl CGI script. For future reference, a statement along the lines
of 'Here is some JavaScript that I am using currently. I would like to
produce a Perl CGI script that does the same thing.' will work wonders.
Also, many of us do not speak JavaScript, so a concise (and complete)
English description of the problem wouldn't go amiss, either.

Another thing that you seem to unfortunately to have fallen foul of is
the assumption that perl <=> CGI. This is very much not the case, and
those of us who know otherwise find it irritating, in the end.

> > Bugger it ... Javascript programmers are friendlier I'll just go and
> > see them and do it their way. Obviously 5/6 perl programmers are rude.

Not so much 'are rude' as 'have a different idea of what is rude and
what is not from most of society'. Here, it is considered rude not to
explain yourself properly, or not to take the trouble to make sure you've
spelt the name of the language correctly.

> Not really, but many oldies in this group are eager to complain about what
> they feel are posts that aren't up to a certain standard. They have no
> tolerance for newbies. 

s/newbies/clueless newbies/. I joined this group as a newbie a while
ago, and have never found it unfriendly. I was smacked a couple of times
for making stupid mistakes, but that's what you should expect for
stupidity.

> It's a shame, since it's a *.misc group. there are posting "rules" here, and 
> they are a great reference, but being naive enough to think that everyone 
> should follow them is a little too much.

It's not a question of naivete. It's a question of 'if you're not even
going to bother to read and follow a few simple guidelines, why should I
bother to spend time trying to help you?'.

> You posted to the correct group and I hope my post at least helped some.

You are indeed (probably) in the right place, and I would have thought
that if you try again with a little more respect for the conventions of
this group that you will find it not unhelpful.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: Thu, 04 Mar 2004 14:18:41 +0100
From: Tony Muler <t_lawetta@yahoo.com>
Subject: Re: new to perl
Message-Id: <40472cb1$1_1@news.vo.lu>

Regent wrote:

> Well, I believe your shebang line should be
> 
> #!c:\perl\bin\perl

And I believe the shebang is not necessary at all
on Windows. Right?

T.



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

Date: Thu, 04 Mar 2004 14:23:06 +0100
From: Tony Muler <t_lawetta@yahoo.com>
Subject: Re: new to perl
Message-Id: <40472dba$1_1@news.vo.lu>

Regent wrote:

> Tsui Wai-ming wrote:
> 
>> I just started to learn CGI by writing a perl script, but what 
>> appeared on
>> the browser was exactly what I'd typed in the editor, minus the
>> <title>xxx</title> line.
[...]

> Why not tell us WHAT is on the browser.

He said it: Exactly what was typed into the editor.
This means that the file is treated as a normal
text file by the webserver, not as a CGI script.
It was not executed but just displayed.

But as others have said already: This is more
a comp.infosystems.www.servers.ms-windows
or s.th. like that.

T.



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

Date: Thu, 04 Mar 2004 21:29:36 +0800
From: Regent <arthur0421@163.com>
Subject: Re: new to perl
Message-Id: <c27b16$61n$1@mail.cn99.com>

Tony Muler wrote:
> Regent wrote:
> 
>> Well, I believe your shebang line should be
>>
>> #!c:\perl\bin\perl
> 
> 
> And I believe the shebang is not necessary at all
> on Windows. Right?
> 
> T.
> 
Why not?

Regent


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

Date: Thu, 4 Mar 2004 13:40:56 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: new to perl
Message-Id: <c27bl8$e2q$2@wisteria.csv.warwick.ac.uk>


Regent <arthur0421@163.com> wrote:
> Tony Muler wrote:
> > Regent wrote:
> > 
> >> Well, I believe your shebang line should be
> >>
> >> #!c:\perl\bin\perl
> > 
> > And I believe the shebang is not necessary at all
> > on Windows. Right?
> 
> Why not?

Err... because Windows doesn't follow the #! convention? It does have a use,
however: perl will read switches from the #! line if it is there. This can
be the only way to specify -T.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Thu, 04 Mar 2004 22:00:38 +0800
From: Regent <arthur0421@163.com>
Subject: Re: new to perl
Message-Id: <c27crd$75a$1@mail.cn99.com>

Ben Morrow wrote:

> Regent <arthur0421@163.com> wrote:
> 
>>Tony Muler wrote:
>>
>>>Regent wrote:
>>>
>>>
>>>>Well, I believe your shebang line should be
>>>>
>>>>#!c:\perl\bin\perl
>>>
>>>And I believe the shebang is not necessary at all
>>>on Windows. Right?
>>
>>Why not?
> 
> 
> Err... because Windows doesn't follow the #! convention? It does have a use,
> however: perl will read switches from the #! line if it is there. This can
> be the only way to specify -T.
> 
> Ben
> 
Oh really. Does this mean the shebang can be omitted, if no switch is 
used? I've programmed Perl on Windows for a few years but never thought 
about this :-(

Regent


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

Date: Thu, 04 Mar 2004 09:57:44 +0000
From: "Steve (another one)" <y66y@56yu4b6.com>
Subject: Re: Perl & Sessions?
Message-Id: <c26uiq$nlh$1@news.liv.ac.uk>

Malcolm Dew-Jones wrote:
> Greg Klinedinst (g_klinedinst@hotmail.com) wrote:
> : On Wed, 03 Mar 2004 21:07:58 +0100, Vetle Roeim <vetro@online.no>
> : wrote:
> 
> : >  If you put the session id in the URL, your system may be vulnerable
> : >  to session hijacking.
> : >
> : >  If the user goes to a page in your system (with the session id in
> : >  the URL) and clicks a link to an external site, the session id will
> : >  appear in the referer-header that is sent to the external site.
> : >
> : >  Sverre H. Husebys "Innocent Code" covers this, and much more.
> : >  <URL:http://innocentcode.thathost.com/>
> 
> : The user can find out their own session ID in all cases, since in all
> : cases it is data they(the client) are sending to your server. The only
> : real difference is that with the URL/hidden vars way you don't need to
> : worry about the client rejecting cookies. Also the URL way(GET)
> : probably isn't ideal b/c the URL has a maximum length, so hidden
> : vars(POST) are best IMHO. You just have to make sure that they cannot
> : guess how you created the session ID, and make sure you expire session
> : IDs in your DB.
> 
> 
> Cookies are handled by the browser, so they may be easier to code.  You
> set them just once, and then read them as necessary, no need to ever
> accomodate them in your pages.  In particular your web site can use static
> pages when ever it is convenient, and the context is not lost.
> 
> Caching can mean that old values are passed around, whereas the cookie is
> always up to date.
> 
> A cookie can be changed independently of the pages (which can be good or
> bad).
> 
> Personally, I have set up pages that used nothing but hidden fields, but I
> don't do it anymore.  I have found that a cookie is just too much easier
> to use (unless you pay me well - then I would of course) mostly because
> you only ever use them when you need them, whereas a hidden field must
> always be passed around somehow, which limits the techniques available for
> generating pages, links, and etc.
> 
> Someone mentioned the problem of the referrer header passing information
> to unrelated sites, and therefore links should not contain session ids. I
> just thought I would reiterate that, because if you know someones session
> id it can be trivial to play in their session.
> 
> As for user's turning cookies off, this is no different than (for example)  
> selling an item with a picture and trying to accomodate a person with a
> text browser - at some point you just have to say "sorry", you need a
> certain base level to access all the features of this site.  Same with
> Javascript.  I understand the reluctance of some people to turn it on, but
> at some point the user needs to decide if they want to interact with you,
> kind of like deciding whether they will bite the bullet and key in their
> credit card number - at some point they must do what _you_ want if they
> want to interact with your system.
> 
> 
> 
> --
> Web Work Wanted, Perl Projects Programmed, Database Development Done.
> 
> I'm looking for telecommute projects. (Paying that is, various
> arrangements possible.)


OK I'm convinced that I should re-examine my approach - I will consider 
cookies for future projects. However, can I please nail-down the 
comments such as:

 >Caching can mean that old values are passed around, whereas
 >the cookie is always up to date.

and

 >If you put the session id in the URL, your system may be
 >vulnerable to session hijacking.

These are simply not issues with properly desgined session id's which 
are properly managed by the application. This proper design needs only 
to be done once !

No system can guard against a user wandering off with a session underway 
and a baddy coming along and taking it over before the application 
times-out the session whether via cookie or POSTed id.

Steve



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

Date: Thu, 4 Mar 2004 13:07:52 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Problem open'ing a file to read utf16
Message-Id: <c279n8$cmg$1@wisteria.csv.warwick.ac.uk>


alex522@mailinator.com (alex) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<c24u6o$jeo$1@wisteria.csv.warwick.ac.uk>...
> > 
> > Hmmmm.... try ':encoding(utf16le)': you'll have to strip the BOM
> > yourself.
> 
> One question remains - what is the point of the plain 'utf16'
> encoding when opening files if it expects a BOM at the start
> of every chunk. Surely it should remember the endiannes from
> the initial BOM. Feels like a bug to me.

It does indeed... I may take a look at it later.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Thu, 04 Mar 2004 13:34:39 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Removing accents from spanish characters
Message-Id: <c277or$1pn8k4$1@ID-184292.news.uni-berlin.de>

Helgi Briem wrote:
> gnari wrote:
>> what's the deal with the return within the loop? you realize this
>> will just return the first argument (fixed), so the loop has no
>> real purpose, other than a fancy way to do $_=$_[0]
> 
> No, gnari, you are wrong.  It will return the substituted text.
> 
> Try this with and without the return.  You can feed the subroutine
> either and array or a scalar.  It will work with either.

No, it won't. If you feed it with an array (or a list), it will only
return the first element (as expected, since the return() function
interrupts the whole subroutine).

     my @text = ('Þjóðlegir þýskir ferðamenn',
                 'líða ekki fúlar fréttir');
     @text = fix_Icelandic_letters(@text);
     print "@text\n";

Outputs:
Thjodlegir thyskir ferdamenn

But it can be fixed, of course:

     sub fix_Icelandic_letters
     {
         for (@_)
         {
         tr/ÁÐÉÍÓÚÝÖáðéíóúýö/ADEIOUYOadeiouyo/;
         s/Þ/Th/;
         s/Æ/Ae/;
         s/þ/th/;
         s/æ/ae/;
         }
     wantarray ? @_ : $_[0];
     }

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



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

Date: 4 Mar 2004 11:33:01 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: This drives me crazy !!!
Message-Id: <c2745d$7ar$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Foo Bar:

> Singleton.pm:
>=============
> package Singleton;
> my $instance = undef;
> sub new
> {
>   if (!defined $instance) {
>     $instance->{count} = 0;
>     bless($instance, 'Singleton');

This will bless the object into the hard-coded class
'Singleton'.

>   }
>   return $instance;
> }
> 1;
> 
> Obj.pm:
>=======
> package Obj;
> use Singleton;
> @Obj::ISA = qw(Singleton);
> sub count {
>   my $self = shift;
>   return $self->{count}++;
> }
> 1;
> 
> test.pl:
>========
> #!/usr/bin/perl -w
> use Obj;
> my $obj = new Obj;

Here you want to create an object that is an instance of the class Obj.
Obj inherits new() from Singleton which always blesses the created
object into 'Singleton'. However, you want it to bless into 'Obj'.

So change the inherited new():

    sub new {
	my $class = shift;
	if (!defined $instance) {
	    $instance->{count} = 0;
	    return bless $instance => $class;
	}
    }
    
Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 4 Mar 2004 11:22:05 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: What with this open file descriptor/"Read on closed filehandle " stuff?
Message-Id: <c273gt$4o2$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Rex Gustavus Adolphus:

> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c14sju$c84$1@wisteria.csv.warwick.ac.uk>...
>> uffesterner@spamhole.com (Rex Gustavus Adolphus) wrote:
>> >
>> > sub check_for_file {
>> > my ($dbh, $filename,$wait_after_last_write, $msglevel) = @_;
>> >         my ($file);
>> >         my @files;
>> >         my $age_in_seconds;
>> 
>> You don't really need to declare these up here: it's better to keep
>> variables in as small a scope as possible, and simply declare them the
>> first time you use them.
> 
> I guess this is mostly a matter of personal taste (TMTOWTDI), or is
> there any special reason your way is better?

Fewer variables are always a good thing. By putting them into the
smallest possible scope, variables will only be accessible therein and
not somewhere else.

Also, perl will destroy them more timely and thus can reuse the memory
associated with them.

>> >         &printlog($msglevel,3,"looking for $filename");
>> 
>> Don't call subs with & unless you need to (here you don't).
> 
> Isn't this another case of TMTOWTDI?

Yes.

>> > Would using File::glob solve the issue?
>>                     ^ G
>> Yes.
> 
> But File::Glob isn't available right now (pre-5.6 perl as it is),
> so I figure I could do it this way:
> 
> I forgot to mention it in my first post, but more often than not
> there's
> actually no need to glob() at all since $filename seldom contains
> wildcards.
> 
> I change this code 
>         @files = glob($filename);
> to this:
>         $_ = $filename;
>         # check for existence of ? and/or * 
>         if ( m/.*[\?|\*].*/ ) {
>             @files = glob($filename);
>         } else {
>             push(@files,$filename);
>         }
> 
> It's not a perfect solution, but will at least make the number of
> glob()-call much less.

Be aware however, that your regex is too simpleminded. It doesn't catch
(for instance):

    file.[ch]

whereas it (falsely) does catch

    file\*.c

In the latter, the asterics is escaped and thus to be taken as a literal
literally.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 4 Mar 2004 07:31:06 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: What with this open file descriptor/"Read on closed filehandle " stuff?
Message-Id: <dkF1c.17009$qA2.976400@news20.bellglobal.com>


"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
news:c273gt$4o2$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach Rex Gustavus Adolphus:
>
> > Ben Morrow <usenet@morrow.me.uk> wrote in message
news:<c14sju$c84$1@wisteria.csv.warwick.ac.uk>...
> >> uffesterner@spamhole.com (Rex Gustavus Adolphus) wrote:
> >> >
>
> >> >         &printlog($msglevel,3,"looking for $filename");
> >>
> >> Don't call subs with & unless you need to (here you don't).
> >
> > Isn't this another case of TMTOWTDI?
>
> Yes.
>

I have to ask why you keep going against the grain on this? The & obviously
has a special meaning in subroutine calls, whether it's applicable in this
situation or not. Even if it never causes a problem for you to prefix your
subroutine calls with an ampersand, it's still not good practice (and goes
beyond a mere style issue). By saying that it's just another way to call a
subroutine you are implying that there is no difference, and that's patently
untrue.

Matt




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

Date: 4 Mar 2004 12:58:18 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: What with this open file descriptor/"Read on closed filehandle " stuff?
Message-Id: <c2795a$t3o$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Matt Garrish:

> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
> news:c273gt$4o2$1@nets3.rz.RWTH-Aachen.DE...
>> Also sprach Rex Gustavus Adolphus:
>>
>> > Ben Morrow <usenet@morrow.me.uk> wrote in message

>> >> Don't call subs with & unless you need to (here you don't).
>> >
>> > Isn't this another case of TMTOWTDI?
>>
>> Yes.
>>
> 
> I have to ask why you keep going against the grain on this? The & obviously
> has a special meaning in subroutine calls, whether it's applicable in this
> situation or not. Even if it never causes a problem for you to prefix your
> subroutine calls with an ampersand, it's still not good practice (and goes
> beyond a mere style issue). By saying that it's just another way to call a
> subroutine you are implying that there is no difference, and that's patently
> untrue.

Of the two side-effects that exist (passing @_ and circumventing the
prototype), only the latter could ever come into the game as the
parameters were passed explicitely. What remains are prototypes that
weren't used in this case. 

When speaking about prototypes, we have to acknowledge that they
themselves are a rather questionable concept. They were originally
introduced in order to create functions behaving similar to some
builtins (such as push() or map()). I don't see why the ampersand should
be condemned just because they affect something that is used in maybe 1%
of all function definitions in existing Perl code.

Finally the statement

    Don't call subs with & unless you need to.

is a violation against anything that Perl stands for. After all, we
don't object when people write object-oriented Perl although you never
'need to' and we all know that a simple method call is by a magnitude
slower than calling a plain function. The above statement implies that
something like a correct way of doing things exists. But it doesn't.
Neither in Perl nor in programming in general.

Having said that, I wouldn't mind if people explained what the ampersand
does and pointed out in which circumstances it could be wrong. That
would put someone into the position of deciding whether he wants it or
not. Simply telling not to use it is the wrong thing.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 4 Mar 2004 13:19:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: What with this open file descriptor/"Read on closed filehandle " stuff?
Message-Id: <c27aco$cmg$2@wisteria.csv.warwick.ac.uk>

[please wrap attribution lines at 72 columns]

uffesterner@spamhole.com (Rex Gustavus Adolphus) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<c14sju$c84$1@wisteria.csv.warwick.ac.uk>...
> >
> > You don't really need to declare these up here: it's better to keep
> > variables in as small a scope as possible, and simply declare them the
> > first time you use them.
> 
> I guess this is mostly a matter of personal taste (TMTOWTDI), or is
> there any special reason your way is better?

It is not so much a matter of taste as a matter of good programming
practice.  If variables are declared in the smallest scope possible
there is the minimal chance of confusion with other variables of the
same name. Also, it is then (usually) possible to see at a glance the
whole scope the variable is valid over.

> > Don't call subs with & unless you need to (here you don't).
> 
> Isn't this another case of TMTOWTDI?

No, the two different ways of calling subs have different semantics (see
perlsub).  Even if it makes no difference in this case, it will confuse
someone else reading your code (they will spend time trying to work out
why you needed the &-semantics).

> > On older perls (pre-5.6), glob is performed by forking a csh(1). This is
> > a Bad Thing, so it was replaced with File::Glob in 5.6.
> 
> But even if it is performed that way, why is the program running out
> of file descriptors eventually?
> Seems to me like a bug in the pre-5.6-glob() or File::Copy::move then.

Yes, it does; unless you are performing many globs simultaneously?

> But File::Glob isn't available right now (pre-5.6 perl as it is),
> so I figure I could do it this way:

But you can install File::Glob from CPAN and use that. It is a much
better solution. (See the FAQ if you don't have root to install new
modules globally.)

> I forgot to mention it in my first post, but more often than not
> there's
> actually no need to glob() at all since $filename seldom contains
> wildcards.
> 
> I change this code 
>         @files = glob($filename);
> to this:
>         $_ = $filename;
>         # check for existence of ? and/or * 
>         if ( m/.*[\?|\*].*/ ) {
>             @files = glob($filename);
>         } else {
>             push(@files,$filename);
>         }
> 
> It's not a perfect solution, but will at least make the number of
> glob()-call much less.

There is still a bug waiting to bite, though.

> I guess it won't help much if the real problem is the
> File::Copy::move-call

Just for the hell of it, you could try installing the latest version of
File::Copy from CPAN as well.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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