[6916] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 541 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 29 20:17:29 1997

Date: Thu, 29 May 97 17:00:25 -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           Thu, 29 May 1997     Volume: 8 Number: 541

Today's topics:
     Re: $ENV{PWD} versus `pwd' (Alan Myers)
     Re: Any non number but not a dot... (Craig Berry)
     Re: Arg. This isn't a CGI question, really it isn't. <rootbeer@teleport.com>
     Re: Associate This! <jstern@world.northgrum.com>
     Re: Can't locate perldb.pl in @INC (Andrew M. Langmead)
     Embed perl script in HTML josephn@mail.mcoe.k12.ca.us
     Engineering Format printing (Kevin Earls)
     Re: Engineering Format printing (Hope this helps!)
     Formatting question (Sara Young)
     Re: From Unix Perl programming to NT Perl Programming.. (Jeff Yoak)
     Re: Help with ( (Andrew M. Langmead)
     Re: Help with ( (Chipmunk)
     Re: Idiom for list summation? (Craig Berry)
     Re: Inheritance help <minaret@sprynet.com>
     Re: Inheritance help <jstern@world.northgrum.com>
     Re: LEXICAL Scoping Hell! (explain?) <jdane@honlab.nmfs.hawaii.edu>
     Re: LEXICAL Scoping Hell! (explain?) <jstern@world.northgrum.com>
     Re: MACPERL - is it (Paul J. Schinder)
     Re: Magical Auto-increment operator <rootbeer@teleport.com>
     PERL for win32 question... <chronow1@jeflin.tju.edu>
     Re: PURE PERL .gif creating library needed; not in @#$  <zenin@best.com>
     Re: running ftp in a Perl script. ataide@planetarium.com.br
     Re: script optimization of grep -c (Jeff Gruszynski)
     script pull images off web pages <cathyh@cs.berkeley.edu>
     Script to DELETE SIMILAR FILENAMES WITH IDENTICAL FILE  (Ivan Gum)
     Re: Script to DELETE SIMILAR FILENAMES WITH IDENTICAL F <merlyn@stonehenge.com>
     Re: Slices of lists <byoung@riag.com>
     Re: sort algorithms <rootbeer@teleport.com>
     Re: STDIN hang-up <rootbeer@teleport.com>
     Re: STYLE: subclass method names (Hope this helps!)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 29 May 1997 22:12:38 GMT
From: awmyers@netcom.com (Alan Myers)
Subject: Re: $ENV{PWD} versus `pwd'
Message-Id: <awmyersEAyr13.EBE@netcom.com>

Clark Dorman (dorman@s3i.com) wrote:

: Greetings,
: 	I admit that I'm very confused.  In my application, I need to change
: the working directory fairly frequently, creating subdirs, removing them,
: etc.  I was under the impression that the ENV hash gives me the current
: environment.  Therefore, if I change the environment within the perl script
: that the ENV hash will change.  From perlvar:

[snip]
I'm still on perl4 (because the O'reilly book is small enough to fit in my 
briefcase), but it does provide you with the pwd.pl library
package.  This guy tries to set up your $ENV{'PWD'} (&initpwd)
even if it is not set or set wrong, and then rewrites chdir
to keep track.  I'm sure that Perl5 has something similar.

Alan


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

Date: 29 May 1997 20:46:33 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Any non number but not a dot...
Message-Id: <5mkpv9$932$2@marina.cinenet.net>

christopher (christopher@wonderlandinorbit.com) wrote:
: - what could I use to check if a string has any non digit in it, as long
: as that / those non digit is/aren't a dot.  Don't care where anything
: appears, I just need to return true if a string is made entirely of
: numbers and dots.

  $string =~ /^[0-9\.]+$/;

This will evaluate true if $string contains only digits and dots.

I'm not *certain* that the escaping of dot is required inside square 
brackets, but it can't hurt. :)  If a zero-length string is acceptable, 
change + to *.  Hope this helps!

---------------------------------------------------------------------
   |   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: Thu, 29 May 1997 14:59:09 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Andy Shaw <a.j.shaw@shef.ac.uk>
Subject: Re: Arg. This isn't a CGI question, really it isn't.
Message-Id: <Pine.GSO.3.96.970529145822.19083M-100000@kelly.teleport.com>

On Thu, 29 May 1997, Andy Shaw wrote:

> I would like to be able to test my cgi programs on my stand-alone pc at
> home, without having to set up the ENV{"QUERY_STRING"} and similar each
> time I do it. 

Then you want CGI.pm, which will notice whether your script is running
interactively or not. It's great!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Thu, 29 May 1997 19:43:40 GMT
From: Jim Stern <jstern@world.northgrum.com>
Subject: Re: Associate This!
Message-Id: <338DDC6C.33DA@world.northgrum.com>

Steven T. Zydek wrote:
> [... %FriendsHeight is a hash]

> # Now how would I list the existing friend's height's in a way
> # that I could also count how many friend's heights I have left
> # in the array?
> # I have tried this:
> 
> foreach (%FriendsHeight) {
>     $x++;
>     print "$_\n";
>     }
> 
> # but this adds the name of each element (i.e. Greg, Pete, Jack...)
> # as if it were a height?  Is there some sort of command that simply
> # flushes out the name of the element and it's contents as ONE entry?
> # Tell me what you think!

I think "yes." :-)  Read about 'each' in the perlfunc man pages
-- 
Jim Stern -- Views here are my own, not Northrop Grumman's.   (El
Segundo, CA)


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

Date: Thu, 29 May 1997 13:06:19 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Can't locate perldb.pl in @INC
Message-Id: <EAy1qK.5Br@world.std.com>

dominic@thiru.vetri.com writes:

>I would like to change the @INC permanently. (I dont want to use
>unshift(@INC, /bla)  each time. Can any one help me out to achieve this.

Maybe try setting the PERL5LIB environment variable in your .profile or
 .login script.

See the perl man page for details.
-- 
Andrew Langmead


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

Date: Thu, 29 May 1997 17:22:37 -0600
From: josephn@mail.mcoe.k12.ca.us
Subject: Embed perl script in HTML
Message-Id: <864944221.8263@dejanews.com>

I have written a perl counter script. I would like to call it from already
written html web pages. How do I go about this? Any comments would be
most appreciated. Thanks Joseph.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 29 May 1997 20:39:23 GMT
From: kevin@ti.com (Kevin Earls)
Subject: Engineering Format printing
Message-Id: <5mkphr$cl3$1@tilde.csc.ti.com>
Keywords: engineering format printing

Anyone know of a better/faster/cleaner way to get engineering format
for numbers?  Is there a module or library that can do this?
This is what I'm doing now.

 #### FORMAT THE OUTPUT TO ENGINEERING FORMAT ( E-03,E-06,E-09,E-12)
 AVE: {
        ($num,$exp) = split(/e/,$ave{$tn});
        if ($exp =~ /-01/) {$ave{$tn} = sprintf("%ge-03",$num*100); last AVE;}
        if ($exp =~ /-02/) {$ave{$tn} = sprintf("%ge-03",$num*10); last AVE;}
        if ($exp =~ /-03/) {$ave{$tn} = sprintf("%ge-03",$num*1); last AVE;}
        if ($exp =~ /-04/) {$ave{$tn} = sprintf("%ge-06",$num*100); last AVE;}
        if ($exp =~ /-05/) {$ave{$tn} = sprintf("%ge-06",$num*10); last AVE;}
        if ($exp =~ /-06/) {$ave{$tn} = sprintf("%ge-06",$num*1); last AVE;}
        if ($exp =~ /-07/) {$ave{$tn} = sprintf("%ge-09",$num*100); last AVE;}
        if ($exp =~ /-08/) {$ave{$tn} = sprintf("%ge-09",$num*10); last AVE;}
        if ($exp =~ /-09/) {$ave{$tn} = sprintf("%ge-09",$num*1); last AVE;}
        if ($exp =~ /-10/) {$ave{$tn} = sprintf("%ge-12",$num*100); last AVE;}
        if ($exp =~ /-11/) {$ave{$tn} = sprintf("%ge-12",$num*10); last AVE;}
        if ($exp =~ /-12/) {$ave{$tn} = sprintf("%ge-12",$num*1); last AVE;}
      }

-- 

_/_/_/_/_/ _/_/_/   Kevin Earls
   _/       _/      kevin@ti.com
  _/       _/       Product Engineering
 _/       _/        Texas Instruments
_/     _/_/_/       Sherman, TX 




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

Date: 29 May 1997 18:23:21 -0500
From: scribble@wwa.com (Hope this helps!)
Subject: Re: Engineering Format printing
Message-Id: <5ml359$8mv@shoga.wwa.com>
Keywords: engineering format printing

In article <5mkphr$cl3$1@tilde.csc.ti.com>, Kevin Earls <kevin@ti.com> wrote:
>Anyone know of a better/faster/cleaner way to get engineering format
>for numbers?  Is there a module or library that can do this?
>This is what I'm doing now.

One way would be to take

	$newexp = sprintf "%2d", 3*int((1+$exp)/3) - 3;

this gives

	sprintf "%ge" . $newexp, $num*10**($exp - $newexp);

which takes care of all the exponents you have mentioned.

I have no idea about efficiency. Your way feels better, but you
should of course check for ($exp eq "-01"), not ($exp =~ /-01/).


> #### FORMAT THE OUTPUT TO ENGINEERING FORMAT ( E-03,E-06,E-09,E-12)
> AVE: {
>        ($num,$exp) = split(/e/,$ave{$tn});
>        if ($exp =~ /-01/) {$ave{$tn} = sprintf("%ge-03",$num*100); last AVE;}
>        if ($exp =~ /-02/) {$ave{$tn} = sprintf("%ge-03",$num*10); last AVE;}
>        if ($exp =~ /-03/) {$ave{$tn} = sprintf("%ge-03",$num*1); last AVE;}
>        if ($exp =~ /-04/) {$ave{$tn} = sprintf("%ge-06",$num*100); last AVE;}
>        if ($exp =~ /-05/) {$ave{$tn} = sprintf("%ge-06",$num*10); last AVE;}
>        if ($exp =~ /-06/) {$ave{$tn} = sprintf("%ge-06",$num*1); last AVE;}
>        if ($exp =~ /-07/) {$ave{$tn} = sprintf("%ge-09",$num*100); last AVE;}
>        if ($exp =~ /-08/) {$ave{$tn} = sprintf("%ge-09",$num*10); last AVE;}
>        if ($exp =~ /-09/) {$ave{$tn} = sprintf("%ge-09",$num*1); last AVE;}
>        if ($exp =~ /-10/) {$ave{$tn} = sprintf("%ge-12",$num*100); last AVE;}
>        if ($exp =~ /-11/) {$ave{$tn} = sprintf("%ge-12",$num*10); last AVE;}
>        if ($exp =~ /-12/) {$ave{$tn} = sprintf("%ge-12",$num*1); last AVE;}
>      }


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

Date: Thu, 29 May 1997 19:04:46 GMT
From: syoung@actcom.co.il (Sara Young)
Subject: Formatting question
Message-Id: <EAyIBy.M97@actcom.co.il>

I want to print out some data, making sure that all lines are no longer 
than a specific length.

Does the following make sense, or is there an easier way to do this (I
want to preserve paragraphs)?

format = 
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$text
 .

while (<>) {
    if (/^\s*$/) {
       write;
       print "\n";
       $text = "";
    } else {
       $text .= $_;
    }
}

TIA,

Sara


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

Date: Thu, 29 May 1997 19:04:03 GMT
From: jeff@yoak.com (Jeff Yoak)
Subject: Re: From Unix Perl programming to NT Perl Programming... Help!
Message-Id: <5mkueo$bud@sjx-ixn6.ix.netcom.com>

scott@lighthouse.softbase.com (Scott McMahan) wrote:

[snip]

>Bummer. You ought to get in the beta test program for my new Automail
>program. It works, because I use it all the time!

>Scott

Scott,

	Is there a URL describing the product and maybe the beta program?

Cheers,
Jeff

Jeff Yoak  jeff@yoak.com  http://yoak.com/



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

Date: Thu, 29 May 1997 21:28:00 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Help with (
Message-Id: <EAyoyo.DAr@world.std.com>

Dave Boswell <dave_boswell@nt.com> writes:

>> Dave Boswell  <dave_boswell@nt.com> wrote:
>> >   #!/usr/local/perl-5.004/bin/perl -w
>> >   print ( "hello world\n" );
>> >
>> >When run from the command line, with 'perl -w file' it works fine, if I
>> >however make the file executable and run it I get the error.  I have
>> >removed the () pair and ran it as an executable and everything is OK.
>> 

>No whitespace.  I'm running ksh under HPUX 9.05, nothing special there. 

Many systems have a 32 character limit on the "#!" line, including the
switches. (Of which many only allow one, but perl tries to make up for
it.) Sorry I didn't notice that before.

This used to be in the FAQ, but it doesn't seem to be in the current
version.
-- 
Andrew Langmead


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

Date: 29 May 1997 20:00:34 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Help with (
Message-Id: <5mkn92$egp$1@dartvax.dartmouth.edu>

In article <338C3E56.138D@nt.com>
Dave Boswell <dave_boswell@nt.com> writes:

> We have just recently moved to 5.004 and I am getting the following
> error, which I am unable to figure out.
> 
>    syntax error at line 2 : `(' unexpected
> 
> The script that generates this is as follows:
> 
>    #!/usr/local/perl-5.004/bin/perl -w
>    print ( "hello world\n" );
> 
> When run from the command line, with 'perl -w file' it works fine, if I
> however make the file executable and run it I get the error.  I have
> removed the () pair and ran it as an executable and everything is OK. 
> Any and all ideas would be helpful since we are now basically dead in
> the water.

I would check to make sure that the path to the perl executable
(/usr/local/perl-5.004/bin/perl) is valid.  It certainly isn't
intuitive.
Also, type 'which perl' at the command line to see what path is used
for the 'perl' command.

Chipmunk


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

Date: 29 May 1997 20:05:54 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Idiom for list summation?
Message-Id: <5mknj2$932$1@marina.cinenet.net>

fawcett.NOSPAM@nynexst.com wrote:
: cberry@cinenet.net (Craig Berry) writes:
: > I have the need to take a list of numbers and determine their sum.  I can 
: > easily to this with code like this:
[snip]
: >   foreach $n (@nums) {
: >     $sum += $n;
: >   }
: > 
: > However, I can't shake the nagging feeling that there must be an easier 
: > way, using a 'map' or something like that.  Any suggestions?
: 
: You've done it about the most direct way possible.  You can use map to do
: foreach's job, but you'd just be discarding map's return value so map is
: less efficient for this.

Yes, that did kind of bother me, and since reading Randal's criticism of 
that idiom on this thread, it bothers me more. :)

: The simple answer is no, there's no simple perl function (like Lisp's
: reduce) to do this automatically.

Caught me.  Way back when I was a Lisp programmer, before a more recent
detour into C++.  One of the things I liked immediately about Perl when I
started using it last year was its slight Lispiness.  Sometimes, though, I
guess I get a bit carried away... 

Thanks once again to you and all the others who answered my question.  I 
feel calmer about just using a foreach loop, now.  And, btw, I loved the 
eval trick a couple of people suggested. :)

---------------------------------------------------------------------
   |   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 May 1997 13:49:36 GMT
From: "Geoff Mottram" <minaret@sprynet.com>
Subject: Re: Inheritance help
Message-Id: <01bc6c36$e1aee2e0$13acaec7@cactus>

> When I run a script that uses "MY_CGI" I get the error,
> "Can't locate object method "new" via package "MY_CGI" at test.pl line
2."
> 
> The beginning of MY_CGI.pm has:
> package MY_CGI;
> @ISA = qw(CGI);
> <some new methods and an overridden method>
> 
> The script test.pl begins with:
> use MY_CGI;
> $q = new MY_CGI;
> 
> Why can't the inherited "new" be found?

I think you need a "use CGI" in your MY_CGI.pm package.

-- 
Geoff Mottram
minaret@sprynet.com


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

Date: Thu, 29 May 1997 23:02:41 GMT
From: Jim Stern <jstern@world.northgrum.com>
Subject: Re: Inheritance help
Message-Id: <338E0B11.3B77@world.northgrum.com>

Tim Groner wrote:
> 
> I'm familiar with OOP, and Perl4 in general, but I'm new to Perl5.
> I want to add some functionality to CGI.pm and I wanted to do that
> through inheritance.
> 
> When I run a script that uses "MY_CGI" I get the error,
> "Can't locate object method "new" via package "MY_CGI" at test.pl line 2."
> 
> The beginning of MY_CGI.pm has:
> package MY_CGI;
> @ISA = qw(CGI);
> <some new methods and an overridden method>
> 
> The script test.pl begins with:
> use MY_CGI;
> $q = new MY_CGI;
> 
> Why can't the inherited "new" be found?

My site doesn't have CGI installed so I created a base class and
a derived class of my own.  I think I see the problem.

It appears that Perl has to load CGI.pm before it can process
'new MY_CGI'.  So add "require CGI;" to MY_CGI.pm and you should
be all set.  A look at the perlobj and perlbot man pages failed
to find this caution but maybe I've missed something obvious.

Questions for Perl gurus:  Is this documented?  Is my fix
correct?  It seems reasonable that Perl won't go to the trouble
of automatically loading a package just because some derived package
might need it, but I don't know the interpreter's internals.

-- 
Jim Stern -- Views here are my own, not Northrop Grumman's.   (El
Segundo, CA)


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

Date: 29 May 1997 10:46:53 -1000
From: Joe Dane <jdane@honlab.nmfs.hawaii.edu>
Subject: Re: LEXICAL Scoping Hell! (explain?)
Message-Id: <29k9kixayq.fsf@honlab.nmfs.hawaii.edu>


A few people have already posted good answers.  Here's a shorter
example.

#!/usr/local/bin/perl -w

sub sub1 {
    local $local1 = 'local1';
    &sub2;
}

sub sub2 {
    print "$local1\n";
}

&sub1;

----------

menpachi [~/cs/lang/perl]>lex4.pl
local1

Now, if I change the "local" in sub1 above to "my", I get

menpachi [~/cs/lang/perl]>lex4.pl
Identifier "main::local1" used only once: possible typo at lex4.pl line 9.
Use of uninitialized value at lex4.pl line 9.

Good Luck

joe



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

Date: Thu, 29 May 1997 20:10:50 GMT
From: Jim Stern <jstern@world.northgrum.com>
Subject: Re: LEXICAL Scoping Hell! (explain?)
Message-Id: <338DE2CA.206@world.northgrum.com>

Jason Fish - SunEducation wrote:
> 
> I'm playing with STATEMENT BLOCKS and what I thought was the creation
> of new lexical (textual) areas regarding my() vs local() scoping.
> I don't understand why the following happens.  if anyone can help,
> I'd sure appreciate it.  I know what is going on, but it seems
> to 'break' what is said about the lexical-ness of my() variables.
> Test code below states the "problem".  Output from the run of the
> code follows that.  If you wade through it all and help, you are a
> true 'pearl' or a being.

Interesting.  I knew what the perlfunc man pages meant about 'my'
right away because I have experience with other block-structured
languages.  However, when I reread the 'my' text, I see how your
interpretation is possible.  If I read your [elided] program
notes correctly, you apparently think that a 'my' variable's
scope is restricted to the block in which it is declared, exclusive
of any contained blocks.  

Not so.  A 'my' variable's scope is meant to include contained
blocks.  This is the usual case for block-structured languages.

However, there is an exception.  If one of the contained blocks
declares a 'my' variable of the same name, it effectively hides
the outer 'my' variable for the duration of the contained block.
(This exception is also the usual case for block-structured languages.)

Whew!  We need an example:

=============================
#!/usr/local/bin/perl -w
use strict;
OUTER: {
    my $var = "abc";
    print "OUTER: var=$var\n";
    INNER: {
        my $var = "def";
        print "INNER: var=$var\n";
    }
    print "OUTER again: var=$var\n";
}
===============================

The output is:
===============================
OUTER: var=abc
INNER: var=def
OUTER again: var=abc
===============================

> [... Program trimmed.]
-- 
Jim Stern -- Views here are my own, not Northrop Grumman's.   (El
Segundo, CA)


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

Date: Thu, 29 May 1997 19:01:11 -0400
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: MACPERL - is it
Message-Id: <schinder-2905971901110001@schinder.clark.net>

In article <FAQ-NOT-FOR-EMAIL-2905970655000001@bohdan.dialup.access.net>,
FAQ-NOT-FOR-EMAIL@Tryzub.com (Bohdan Peter Rekshynskyj) wrote:

}         
}  still alive?

Certainly.

}  
}  I see the last updates (perl.com) around July of last year...

Must be a problem with perl.com.  MacPerl 5.13r2 was released in late
January 1997. 
<ftp://sunsite.cnlab-switch.ch/software/platform/macos/perl/>

}  
}  Is there a MacPerl email list?

Yes. <mailto:mac-perl-request@iis.ee.ethz.ch>, using majordomo commands. 
There's an archive of the list at
<http://www.its.unimelb.edu.au:801/hma/pub/macperl/>, but 
it's no longer up to date.

}  
}  Thanks!
}  
}                Bohdan
}  
}  PS - please email me at Bohdan@TRYZUB.com - I do not have
}         daily access here.  Thanks!  8-)

-- 
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@leprss.gsfc.nasa.gov


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

Date: Thu, 29 May 1997 14:46:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Rob Perelman <robp@electriciti.com>
Subject: Re: Magical Auto-increment operator
Message-Id: <Pine.GSO.3.96.970529142225.19083G-100000@kelly.teleport.com>

On Wed, 28 May 1997, Rob Perelman wrote:

> I believe you are missing my underlying point.  I hate to say this
> because I feel like I am disrespecting my religion in arguing with you,

You're always entitled to disagree, since I'm not infallible. :-)

> but here is what I was trying to illustrate in my program: 
> 
> 1. If the argument is numeric, Perl would increment it normally
> 2. If the argument was not numeric, the rules would be applied and the
> string would be incremented

Ah, there's the rub. Perl already has rules for turning strings into
numbers and vice versa. They're well-defined and universal. Here they are.

    1. If you use a number as a string, Perl converts it for you. 
       Nobody is surprised by the results. :-)

    2. If you use a string as a number, Perl converts it for you.
       It ignores leading whitespace and trailing non-numeric junk.
       If there's not a number at the beginning (after any 
       whitespace), it uses zero.

Now, a moment ago I called these rules universal. But sometimes you may
have an operation which can work on either numbers or strings; how does
Perl decide whether to do a conversion or not? The answer is that Perl
will not do a conversion if it can help it. In the case of bitwise
operators, for example, Perl will do bitwise string operations if you give
it two strings, which is why 10 & 12 gives a different answer than '10' &
'12' does. 

So, what happens when we want to do a magic autoincrement? If you've got a
number, there's no problem - and no magic. :-)  If you have a string, Perl
has to figure out whether you want magic or not, since maybe you've got a
string that you thought had been converted to a number already. Here is
the rule that Perl currently uses. (Since I've paraphrased it from what's
on p. 79 of the new Camel, let's call it "Rule 79".)

    If it's a string with no numeric value (that is, it hasn't 
    already been converted to a number), and it's not an empty string,
    and if it matches /^[a-z]*[\d]*$/i, then you can have a magical
    increment. If anything goes wrong, you get the default.

This is where you come in. I think this is the rule you want to change.
I'm not sure that it can be changed without breaking something, or making
things slower, but you're welcome to attempt to alter my opinion. :-)

To my mind, the big problem is that somebody may have a string reading "12
cats" which they want to treat numerically. If they increment the number
of cats, they don't want to have "12 catt". (Lest this seem unlikely,
remember that Perl is often parsing crufty output from other programs.
There's no telling what trailing junk might be out there.) So, right away,
I don't see how we can allow anything like that to be incremented.

> My original problematic string, 'cs2#09', fails the ++ operation.  I
> want it to come back as 'cs2#10'. I personally think this is highly
> logical. 

Well, just because something is logical, that doesn't necessarily mean
it's a good idea. :-) But what would you get from incrementing that string
a few more times. I think it would eventually count up to 'cs2#99'. At
this point, logic fails me; should it become 'cs3#00' or 'cs3#0' or
'cs3#100'? I could make a good case for any two of them. :-) Can you give
a simple rule for what should be done, and can you give a convincing
argument that it's more useful than the alternatives?

Well, I'd love to stay and talk, but I've got to run soon. If you have a
proposed replacement for rule 79, please let me know so I can try to
demolish it. :-)

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Thu, 29 May 1997 18:41:46 -0400
From: Greg Chronowski <chronow1@jeflin.tju.edu>
Subject: PERL for win32 question...
Message-Id: <338E062A.69A4@jeflin.tju.edu>

I'm new to Windows NT, here's my questions:

I have written a PERL script which now runs on a Linux server, I need to
run it on an NT server (IIs).

I realize that the directory structure for NT and Unix are different
(one uses forward slashes "/" and one uses backslashes "\") is this
correct?

Do I need to change all the directory URLs in the script to backslashes
to run the script under NT?

Do I call the script the same way I do under Unix? 
(i.e. using <A HREF="http://www.somewhere.com/cgi-bin/script.pl">
(is there even a cgi-bin directory in NT?)

How are permissions set under NT?

I'll be doing all of this remotely...the server is far away.

Does anyone have a resource that can explain what this whole Active
Server business is about (I have NO idea as of yet)

These questions are BASIC, so I'd appreciate a REALLY basic, hands on
response.

TIA,

GC


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

Date: 29 May 1997 21:29:19 GMT
From: Zenin <zenin@best.com>
Subject: Re: PURE PERL .gif creating library needed; not in @#$ C language or external modules.  PERL!
Message-Id: <5mksff$opi$1@nntp2.ba.best.com>

Ronald L. Parker <ron@farmworks.com> wrote:
> On Wed, 28 May 1997 02:30:20 GMT, abigail@fnx.com (Abigail) wrote:
> Well, there's the little thing called "using someone else's web 
> server."  Our Web provider doesn't provide a C compiler.  I don't have
> access to the same architecture anywhere else.
	You provider bites.  However, all is not lost.  GCC (much better
	then almost any system's native cc anyway) cames pre-compiled
	for almost all architectures.  Just install it under your
	home directory.

> I think an all-Perl
> GIF library would be nice, too. if it could be gotten to run quickly.
	It couldn't.  Far too much low level coding that perl doesn't
	do well.  It's not bit-level (at least not most of it), but
	it would need to do tons of byte comp and movement.

-- 
-Zenin
 zenin@best.com


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

Date: Thu, 29 May 1997 18:18:32 -0600
From: ataide@planetarium.com.br
To: junkmail@sysc.abdn.ac.uk
Subject: Re: running ftp in a Perl script.
Message-Id: <864946605.10220@dejanews.com>

I've tested this code downloading and uploading files from a UNIX machine
to another UNIX machine, and it works fine. I would like to write a Perl
CGI program that sends a file from my PC (running under Windows95) to a
UNIX machine, through the Internet. How can this be done?

Thanks in advance for any help.
Efigenio Ataide
ataide@planetarium.com.br

In article <5lf9e1$jp1@info.abdn.ac.uk>,
  kyzer@hotmail.com wrote:
>
> Florence Kuan, while smelling of fish, wrote:
> : I need to ftp a file from another server while running a Perl program. Does
> : anyone know how I can pass arguments to the ftp program while running a
> : Perl program? Is it possible for the Perl program to supply the user
> : account name, password, and ftp commands to the ftp program so that the
> : user does not have to enter anything.
> : I am working on a Unix X-terminal.
> : Thanx.
>
> You could always use the Net::FTP module (I've just used it myself in a CGI
> script) which gives you a direct connection to FTP servers, without faffing
> about with the ftp command, which can differ on different machines.
> The module Net::FTP and the docs for it are on CPAN http://www.perl.com/CPAN/
> however this is a (crap) example of getting a file witht the ftp command.
>
> open (FTP, "|/bin/ftp -n") || die "Can't open FTP command, $!\n";
> print FTP <<"EOFTP";
> open ftp.doc.ic.ac.uk
> user anonymous -kyzer\@hotmail.com
> cd /pub/aminet
> asc
> get README /tmp/myfile-$$
> EOFTP
> close FTP;
> open (FILE, "</tmp/myfile-$$") || die "FTP didn't succeed";
> @myfile=<FILE>;
> close FILE;
>
> print "here we are...\n";
> print join('',@myfile);
>
> --
> Stuart 'Kyzer' Caie - Kyzer/CSG |undergraduate of Aberdeen University |100%
> http://www.abdn.ac.uk/~u13sac   |My opinions aren't those of Aberdeen |Amiga -
> kyzer@4u.net kyzer@hotmail.com  |University or AUCC, thankfully.***** |always!
>
> --
> Random sig of the day:
> BEAU PEEP: This "Cow-man" comic of yours is riduiculous!
> DENNIS: S'not!
> BEAU: How is this "half-man, half-cow" supposed to catch criminals?
> DENNIS: HE'S GOT LASER-BEAM UDDERS!

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 29 May 1997 21:22:00 GMT
From: jeffg@ptp.hp.com (Jeff Gruszynski)
Subject: Re: script optimization of grep -c
Message-Id: <5mks1o$1am@hpscit.sc.hp.com>

Eric Finley (ez041407@chip.ucdavis.edu) wrote:
: Chipmunk (Ronald.J.Kimball@dartmouth.edu) wrote:
: : In article <5ltcgi$l3m$1@mark.ucdavis.edu>
: : ez041407@chip.ucdavis.edu (Eric Finley) writes:
: : 
: : > I frequently have to do a "grep -c <word> <file>" on very large (~100Meg)
: : > files and wrote this script to hopefully do it faster, grep take >5 min.
: : > Is there any way to optimize this code?
: : 
: : How does your script as it is right now compare to grep in terms of
: : speed?
: : 
: : Chipmunk
: After some advice on my regex my code looks like: 
: open(FILE, $ARGV[1]) || die "Could not open $ARGV[1]\n$!\n";
: $i = 0;
: $pattern = $ARGV[0];
: while(<FILE>) {
:     $i++ if m/$pattern/o
: }
: print "$ARGV[0] found $i times in $ARGV[1]\n"

: and it is slightly slower than grep -c :(

If you read the O'Reilly book on Regular Expressions, you'll discover
that most modern greps will almost always out perform a Perl grep-oid
in this type of application even with optimizations and tweaks, due the
differences in the implementation of the regular expression engines (NFA
vs.  DFA as I remember).  I "discovered" this empirically on a number of
search projects.  Reading the O'Reilly RE book explained it.  I typically
use something like:

# where grep is actually an egrep version
open(GREP,qq{/usr/bin/grep "$target" $db|}) or die "yada yada";

while (<GREP>) {	# every line is a match
	blah($_);
	}

close(GREP);

to get the best of both worlds.  In side-by-side tests, this has always
given me better performance over a perl-only solution.  The speed
depends on the query hit.  A clean miss takes longer than good hit.  I
get 3-10 second response time on a 23 Mbyte/161 KLine data file (using a
HP 9000 745, HPUX 9.05).  (The 745 CPU was top-of-line 5-10 years ago.)


Jeff
--
=============================================================================
Jeff Gruszynski                          Any Standard Disclaimers Apply
Test & Measurement Electronic Commerce
Hewlett-Packard Company
=============================================================================
jeffg@ptp.hp.com                         http://www.tmo.hp.com/
=============================================================================


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

Date: Thu, 29 May 1997 16:07:09 -0700
From: Cathy Huang <cathyh@cs.berkeley.edu>
Subject: script pull images off web pages
Message-Id: <338E0C1D.1F51@cs.berkeley.edu>

Anyone know of any perl scripts that pull all the gif's and jpeg's off
designated web pages into your directory? This is on Solaris 2.5.1.

Please email cathyh@cs.berkeley.edu if possible.

Thanks,
Cathy


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

Date: Thu, 29 May 1997 22:05:56 GMT
From: igum@us.oracle.com (Ivan Gum)
Subject: Script to DELETE SIMILAR FILENAMES WITH IDENTICAL FILE SIZE
Message-Id: <5mkuok$j3i$1@inet16.us.oracle.com>

Does someone have a script that does this?  I could probably whip it up in a 
day but have too much work at the moment.  I hoping somone already has this or 
could write a script before I go at it.

Basically, the script delete all duplicate filenames in a directory that have 
the same starting characters and are the exact same file size.

My approach would be to read the a directory into an array.  Sort the array.
Then loop through it, testing the current file with the next file and if they
satisfy the following conditions, then delete the next file, and skip to the
next-next file. The conditions would be 1) first n chars of 2 filenames match
and 2) (-s file1) = (-s file2).

Can somone help me find or write a similar script?  Thanks.

__________________________________________________________________________
Ivan Gum                                        phone: (415) 506-2754
Information Technologies Analyst                  fax: (415) 506-7119
Global Applications Integration                 email: igum@us.oracle.com


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

Date: 29 May 1997 16:25:10 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: igum@us.oracle.com (Ivan Gum)
Subject: Re: Script to DELETE SIMILAR FILENAMES WITH IDENTICAL FILE SIZE
Message-Id: <8cbu5tx3mx.fsf@gadget.cscaper.com>

>>>>> "Ivan" == Ivan Gum <igum@us.oracle.com> writes:

Ivan> Basically, the script delete all duplicate filenames in a
Ivan> directory that have the same starting characters and are the
Ivan> exact same file size.

Ivan> My approach would be to read the a directory into an array.
Ivan> Sort the array.  Then loop through it, testing the current file
Ivan> with the next file and if they satisfy the following conditions,
Ivan> then delete the next file, and skip to the next-next file. The
Ivan> conditions would be 1) first n chars of 2 filenames match and 2)
Ivan> (-s file1) = (-s file2).

Normally, I don't write more than a few lines here, but this looks
like it could be the basis for another Unix Review column (archived at
http://www.stonehenge.com/merlyn/UnixReview/).  So, you got lucky. :-)

    $n = 4; # this many letters must be identical

    # gather data
    for (<*>) {
      my $size = -s;
      my $prefix = substr($_,0,$n);
      $saw{$prefix}{$size}{$_}++;
    }

    # look for candidates
    for $prefix (sort keys %saw) {
      my $prefix_hash = $saw{$prefix}; # all files with same prefix
      for $size (sort keys %$prefix_hash) {
	my $size_hash = $prefix_hash{$size}; # all files with same prefix/size
	@names = sort keys %$size_hash;
	if (@names > 1) {
	  print "candidates are @names\n";
          shift @names;
          unlink @names;
	}
      }
    }

I arbitrarily kept the lowest lexical name, but you could do what you want.

Yeah.  Nice idea for a column.  Thank you.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 459 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Thu, 29 May 1997 15:51:08 -0700
From: Brian Young <byoung@riag.com>
Subject: Re: Slices of lists
Message-Id: <338E085C.4771D57F@riag.com>

<HTML>
You might want to try using the splice() function

<P>@old = ("one", "two", "three");
<BR>@new = splice(@old, 1, 1, "twoa", "twob");

<P>that should do it.

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Brian

<P>Brian Orpin wrote:
<BLOCKQUOTE TYPE=CITE>As a newcomer to Perl I have hit my first (apparently)
insurmountable
<BR>problem which on line help (The downloaded HTML man pages are broken
<BR>but that's another thread) hasn't and is beyond 'Learning Perl' (what
<BR>a great starter).

<P>I wish to replace a slice of an array.

<P>I used a grep to find if the item (string) exists in the array but
<BR>could not find a function to tell me it's position other than by going
<BR>through the array and incrementing a counter.&nbsp; Is there a better
way?

<P>So I can find the start and end points of the slice I want to remove.

<P>@new = @old[$start..$end];

<P>However, how do I replace the slice with a different array e.g. or
<BR>even delete those elements I have identified.

<P>@old = ("one", "two", "three");
<BR>@new = ("twoa", "twob");

<P>to get&nbsp; an array ("one", "twoa", "twob", "three")

<P>All help gratefully received.

<P>--
<BR>Brian Orpin&nbsp;&nbsp;&nbsp; (These thoughts are my own .........
for once!)
<BR>brian.orpin@gecmX.com or BrainOrpin@BigfootX.com
<BR><A HREF="http://www.borpin.demon.co.uk/">http://www.borpin.demon.co.uk/</A>&nbsp;
**Anti-spam reply-to remove X**</BLOCKQUOTE>
&nbsp;</HTML>



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

Date: Thu, 29 May 1997 14:49:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Pierre Merle <pmerle@corp.sun.com>
Subject: Re: sort algorithms
Message-Id: <Pine.GSO.3.96.970529144840.19083H-100000@kelly.teleport.com>

On Wed, 28 May 1997, Pierre Merle wrote:

> I need to sort datas.

Perl can do that; sort is documented in perlfunc(1).

> I used to make chained list in C language.
> What about it in perl ? 

Usually you don't need that sort of thing in Perl; perlref(1) explains why
not. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Thu, 29 May 1997 14:50:59 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ira <ira@rta.nsw.gov.au>
Subject: Re: STDIN hang-up
Message-Id: <Pine.GSO.3.96.970529144950.19083I-100000@kelly.teleport.com>

On Thu, 29 May 1997, Ira wrote:

> while (<STDIN>) {
>    print ;
> }
> 
> Okay, but what if the program looks for STDIN and there is none. 

Then the loop will exit, since you're at the end of the file. Or did you
mean that the user isn't typing anything and you want to go on anyway?
That's covered in the FAQ's section on telling whether there's input
waiting, and reading one character at a time. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 29 May 1997 17:46:42 -0500
From: scribble@wwa.com (Hope this helps!)
Subject: Re: STYLE: subclass method names
Message-Id: <5ml10i$1jg@shoga.wwa.com>

Tim  Smith <trs@azstarnet.com> wrote:
>I made a test class called CommentMunger that inherits from HTML::Parser.
>I want to add methods to CommentMunger so that one can write:
>
>$cm = new CommentMunger "$outfile";
>$cm->write "text";
>
>But I don't want to use sub write { ... } because it might be used in
>HTML::Parser some day and cause a conflict.  I decided to use a prefix,
>such as:
>
>$cm->CM_write "text";

Another suggestion-- You are obviously not planning now on using a
method which might exist in the future. Your write method considers
the structure of $cm as a CommentMunger, not HTML::Parser.

So if a "write" appears for HTML::Parser and you find you want to
make it available, do so and call THAT one super_write or ht_write
or something else. Can't worry about it now.

Now you have to weigh between this choice and the other.



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

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

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