[18476] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 644 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 6 14:10:48 2001

Date: Fri, 6 Apr 2001 11:10:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986580622-v10-i644@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 6 Apr 2001     Volume: 10 Number: 644

Today's topics:
        password encryption <SiStie@nuclear-network.com>
    Re: password encryption (Steven Smolinski)
    Re: perl hacker wanted (Tad McClellan)
    Re: perl hacker wanted <flavell@mail.cern.ch>
    Re: Please Help <nap@illx.org>
        Posting Guidelines (was Re: Does this newsgroup have an (Tad McClellan)
    Re: Posting Guidelines (was Re: Does this newsgroup hav (Michel Dalle)
    Re: Posting Guidelines  <hillr@ugs.com>
    Re: Q: Units of Measurement in Convert-Units <ritchie@fnal.gov>
        Question about refcounting <Richard.Kreckel@Uni-Mainz.DE>
    Re: Question about refcounting <uri@sysarch.com>
    Re: Question about refcounting <Richard.Kreckel@Uni-Mainz.DE>
    Re: request help to read one line from tcp socket into  nobull@mail.com
        Script for downloading Yahoo mail? <kalin@thinrope.net>
    Re: Secured demo scripts nobull@mail.com
    Re: Seeking Perl Script for Notice Board <clinton.munden@alcatel.com>
        Time difference <Waarddebon@chello.nl>
    Re: Time difference <ubl@schaffhausen.de>
    Re: Time difference (Nick Condon)
    Re: Time difference nobull@mail.com
        Why won't this simple script work?? <ccoogan@speakeasy.net>
    Re: Why won't this simple script work?? (Tad McClellan)
    Re: Why won't this simple script work?? <skilchen@swissonline.ch>
        Windows but not UNIX!? <grahamANTISPAMMING@nme.com>
    Re: Windows but not UNIX!? <npertuset@hotmail.com>
    Re: Windows but not UNIX!? <comdog@panix.com>
    Re: Windows but not UNIX!? (Jon Bell)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 6 Apr 2001 18:40:08 +0200
From: Simon Stiefel <SiStie@nuclear-network.com>
Subject: password encryption
Message-Id: <Pine.LNX.4.31.0104061836340.1824-100000@server.stiefel.priv>

Hi,

I have to transmit a password with the "get"-function to my CGI-Script (so
it can be seen by everyone).

What is the easiest way to encrypt and decrypt the password?

Thanks for any help.



Mit freundlichen Gr=FC=DFen,        .~.     Open Minds.
with best regards               /V\             Open Sources.
                               // \\                    Open Future!
Simon Stiefel                 /(   )\_ I N U X
                               ^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.com   |  http://www.nuclear-network.com |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |



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

Date: Fri, 06 Apr 2001 17:26:14 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: password encryption
Message-Id: <slrn9cs40n.1b8.sjs@ragnar.stevens.gulch>

Simon Stiefel <SiStie@nuclear-network.com> wrote:
> I have to transmit a password with the "get"-function to my CGI-Script (so
> it can be seen by everyone).
> 
> What is the easiest way to encrypt and decrypt the password?

In security, "easy" is negatively correlated with "secure."  The easiest
way is to rot13 the password at the client, and rot13 it again at the
server.  This also provides no security.

\begin[pedantic]{aside}
  I suppose the easiest way is to double-rot13 it at the client. :-)
\end{aside}

Rather than encrypting and decrypting the password (symmetric ciphers
require you to solve the key distribution problem anyway), could you not
use web services set up to solve this problem already, like SSL?  Once
you have a secure channel, send the passowrd in plaintext.

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Fri, 6 Apr 2001 08:53:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl hacker wanted
Message-Id: <slrn9crf20.lp0.tadmc@tadmc26.august.net>

[ Please put your comments *following* the quoted text that you
  are commenting on.

  Please do not quote an entire article.

  Please never quote .sigs

  Thanks.
]


[ Left the text Jeopardy quoted 'cause it's too hard to sort it out... ]


A_Geekette <moiraine{NOSPAM}@qwest.net> wrote:

>I don't see what the big deal is about job posting.


Just because you do not see the reason does not imply that the
reason does not exist.

Why not just ask what the reason is for the job-posting prohibition?


>I mean...wouldn't it be nice to get paid for hacking?
>I sure as hell would like to get paid.


Of course. But I would look in a jobs newsgroup for jobs and look
in a discussion newsgroup for discussion.

This is a discussion newsgroup.


>Post away with your jobs...


Do *NOT* post jobs here! Job postings are off-topic here.

Do not abuse Usenet.


>if it's good enough, and you're not some
>sleezball co like Intel, I wouldn't mind.  However, if you are a sleezball
                          ^
                          ^

It is not _your_ newsgroup. It is our newsgroup. What's OK and what's
not OK should be arrived at by concensus, not by the edict of someone 
who has just arrived here.

Consensus has already been reached on the job posting issue.


>co., then go to hell.


Grow up.


>No under the table shit tho...no way.


No job postings here whatsoever. No legal jobs. No illegal jobs. No jobs.


>Look, if it's about the whole Open source thing....


No, it is about the spew from recruiter's auto-posting machines that 
will swamp the real articles written by people.

This newsgroup is for people. The "*jobs*" newsgroups are for
machines to dump their dross into.

If job postings are allowed here, we will have a *thousand* messages
each day!


>So, what's the job?


Do not answer that rhetorical question! (because it is off-topic here).


>Bart Lateur wrote:
>
>> Uri Guttman wrote:
>>
>> >if this was a real jobs
>> >post it would have been off topic and excused by the clueless author as
>> >why not post a perl job where the perl hackers hang out.
>>
>> I've been searching all over the Net today, for over an hour, looking
>> for a site with the rules that say that job offerings are indeed not
>> allowed in the comp.* or comp.lang.* hierarchy. It came out zilch. Does
>> anybody have an URL?



-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 6 Apr 2001 16:18:58 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: perl hacker wanted
Message-Id: <Pine.LNX.4.30.0104061616220.8404-100000@lxplus003.cern.ch>

On Fri, 6 Apr 2001, A_Geekette wrote:

> I don't see what the big deal is about job posting.
[...]
> Post away with your jobs...

Your application for fast-track killfile entry has been approved, and
if anyone else were so foolish as to take your advice then I'd be
happy to grant them the same privilege.


[and another free jeopardectomy...]



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

Date: Fri, 06 Apr 2001 09:01:18 -0700
From: Nick Pinckernell <nap@illx.org>
Subject: Re: Please Help
Message-Id: <3ACDE84E.6040404@illx.org>

I'm assuming your trying to write out to a file.
If so, your forgetting the 'mode' for writing.
which is a > in front of the filename in your open
statement.

open(FILEHANDLE, ">$file");

_nick

Waarddebon wrote:

  > Why doesn't this work ?
  >
  > $remote2="today";
  > open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
  > print THEFILE "hi";
  > close THEFILE;





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

Date: Fri, 6 Apr 2001 08:22:48 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Posting Guidelines (was Re: Does this newsgroup have an FAQ?)
Message-Id: <slrn9crd8o.lp0.tadmc@tadmc26.august.net>

Uri Guttman <uri@sysarch.com> wrote:

>well, tad was working on something of that nature for this group. 


Doh! It dropped off of my todo list without being "doed"!

I put it back on.


>it is
>on a web site somewhere 


It is (for now) available on my personal web site:

   http://www.augustmail.com/~tadmc/clpmisc_guide/

It will soon be available on some pm.org web page.


>but should be autoposted (probably once a day
>for the volume we get here). 


I'll go with once a week and we'll see how that goes.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 06 Apr 2001 15:35:48 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Posting Guidelines (was Re: Does this newsgroup have an FAQ?)
Message-Id: <9aknsq$1bi$1@news.mch.sbs.de>

In article <slrn9crd8o.lp0.tadmc@tadmc26.august.net>, tadmc@augustmail.com wrote:
>It is (for now) available on my personal web site:
>
>   http://www.augustmail.com/~tadmc/clpmisc_guide/
>
>It will soon be available on some pm.org web page.

Suggestion : explain in a bit more detail *how* people
are supposed to "check the Perl FAQ" and "check the
other standard Perl docs".

Otherwise, quite good :)

Michel.


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

Date: Fri, 06 Apr 2001 07:06:32 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: Posting Guidelines 
Message-Id: <3ACDCD68.473D8C3F@ugs.com>

Tad McClellan wrote:
[snipped]
> 
> It is (for now) available on my personal web site:
> 
>    http://www.augustmail.com/~tadmc/clpmisc_guide/
> 
> It will soon be available on some pm.org web page.
> 
> >but should be autoposted (probably once a day
> >for the volume we get here).
> 
> I'll go with once a week and we'll see how that goes.

One suggestion is under the provide enough information
heading you might want to add some thisngs that are listed
here:
http://perl.plover.com/Questions.html

specifically:
 

     ``I want to accomplish X.
     I thought that the following code fragment would do it:
     ...
     But instead it does Y.
     Why is that?''

This one is also pretty good: 

     ``I want to accomplish X.
     I thought I might be able to use facility Y.
     But Y doesn't seem like it's quite right, because of Z.
     What should I use instead of Y, or how can I overcome Z?''

I hope this helps

Ron Hill


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

Date: Fri, 06 Apr 2001 12:39:33 -0500
From: "David J. Ritchie" <ritchie@fnal.gov>
Subject: Re: Q: Units of Measurement in Convert-Units
Message-Id: <3ACDFF55.DFA676FE@fnal.gov>



Mark Jason Dominus wrote:

> Abigail already suggested that you look at the 'units' program in the
> Perl Power Tools distirbution, or at
>
>         http://perl.plover.com/units/
>
> I second this suggestion.  It solves a number of these problems (not
> all of them) in a much more general way.
>

Yes, I third the suggestion.  I cited the SIunits reference earlier--namely,

 http://www.fnal.gov/fermitools/abstracts/siunits/abstract.html

only because it's my understanding that it has some useful approaches
that might be of value elsewhere...considering it however is all in
C++ it's probable it will only be useful in a conceptual way.

David

--
ritchie@fnal.gov
http://home.fnal.gov/~ritchie/






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

Date: 6 Apr 2001 15:09:00 GMT
From: "Richard B. Kreckel" <Richard.Kreckel@Uni-Mainz.DE>
Subject: Question about refcounting
Message-Id: <9akm6c$fkg$1@bambi.zdv.Uni-Mainz.DE>

Hi,

From the O'Reilly book "Mastering Algrithms with Perl" we learn that
the following procedure produces a circular loop and hence a memory
leak (which can easily be verified by repeatedly calling the function
and observing the memory consumption of the process):

1   sub memleak
2   {
3       # declare two vars:
4       my $e1 = "x";
5       my $e2 = "y";
6       # point them at each other
7       $e1 = \$e2;
8       $e2 = \$e1;
9   }

I have seen some implementations of reference counting, but I am
having some trouble understanding what is going on in Perl.  Could
anybody with expertise in Perl's internals please enlighten me?

In line 4 and 5 we declare two variables.  After that, "x" and "y"
should have refcount==1.  In lines 7 and 8 we do stuff to $e1 and $e2,
after which "x" and "y" aren't referenced any more and can be
destroyed.  Is this correct?  And then we have increaded the refcounts
of $e2 and $e1 both from one to two and they drop to one again when
they leave the scope leaving that circular reference.  Now I am
confused.  Is there a reference count variable both for "x" and for
$e1?  Really?  Doesn't the one handle the other?  And why is the
reference count of $e1 not zero to begin with?  Then, a circular
reference should not be left at the end, as far as I can see.

Regards
    -richy.
-- 
Richard Kreckel
<Richard.Kreckel@Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>



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

Date: Fri, 06 Apr 2001 16:43:10 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Question about refcounting
Message-Id: <x7k84yrnc1.fsf@home.sysarch.com>

>>>>> "RBK" == Richard B Kreckel <Richard.Kreckel@Uni-Mainz.DE> writes:

  RBK> 1   sub memleak
  RBK> 2   {
  RBK> 3       # declare two vars:
  RBK> 4       my $e1 = "x";
  RBK> 5       my $e2 = "y";
  RBK> 6       # point them at each other
  RBK> 7       $e1 = \$e2;
  RBK> 8       $e2 = \$e1;
  RBK> 9   }

  RBK> In line 4 and 5 we declare two variables.  After that, "x" and "y"
  RBK> should have refcount==1.  In lines 7 and 8 we do stuff to $e1 and $e2,

no, perl doesn't refcount the data, it ref counts variables. x and y are
just strings. it is $e1 and $e2 that are initialized to a ref count of 1

  RBK> after which "x" and "y" aren't referenced any more and can be
  RBK> destroyed.  Is this correct?  And then we have increaded the refcounts
  RBK> of $e2 and $e1 both from one to two and they drop to one again when
  RBK> they leave the scope leaving that circular reference.  Now I am

after the circularity is done $e1 and $e2 have ref counts of 2.

  RBK> confused.  Is there a reference count variable both for "x" and for
  RBK> $e1?  Really?  Doesn't the one handle the other?  And why is the
  RBK> reference count of $e1 not zero to begin with?  Then, a circular
  RBK> reference should not be left at the end, as far as I can see.

when you exit the sub, the ref counts of $e1 and $e2 are decremented by
one since their names when out of scope. but that leave both of them
with a ref count of 1 so they don't get freed. they are now inaccessable
to any perl code and are a memory leak. you can get the same effect with
one variable with:

	$e3 = \$e3 ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 6 Apr 2001 16:47:43 GMT
From: "Richard B. Kreckel" <Richard.Kreckel@Uni-Mainz.DE>
Subject: Re: Question about refcounting
Message-Id: <9akrvf$hf4$1@bambi.zdv.Uni-Mainz.DE>

Uri Guttman <uri@sysarch.com> wrote:
[...]
: no, perl doesn't refcount the data, it ref counts variables. x and y are
: just strings. it is $e1 and $e2 that are initialized to a ref count of 1

Thanks a lot!  I had already suspected this.  But the book talks
explicitly about refcounts of the strings and that is quite
confusing (or maybe confused).

Regards
    -richy.
-- 
Richard Kreckel
<Richard.Kreckel@Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>



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

Date: 06 Apr 2001 17:20:42 +0100
From: nobull@mail.com
Subject: Re: request help to read one line from tcp socket into mysql
Message-Id: <u97l0yq9t1.fsf@wcl-l.bham.ac.uk>

"David Armstrong" <david.armstrong@ntlworld.com> writes:

> Could i respectfully request some help as a newbie to perl ( only 1
> week into it) could someone please give me an example of reading a
> single line from a tcp socket connecton

{ # Extra stack frame to localise changes to $/
  local $/ = "\cM"; # Or whatever is the EOL sequence. 
  chomp ($line = <$socket>);
}

> while ( <$s> ) {

Are you sure that the sending system is using the default EOL sequece
for the OS on the reciving system?

> $line = $s->getc();

Why discard the first character of the next line?

Why use a variable called $line to hold a character?

> chop;

Why not chomp?

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


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

Date: Fri, 06 Apr 2001 22:59:42 +0900
From: Kalin Kozhuharov <kalin@thinrope.net>
Subject: Script for downloading Yahoo mail?
Message-Id: <3ACDCBCE.E2CF38E4@thinrope.net>

Hello!

I was thinking to write a script for downloading yahoo mail a folder at
a time.

But first to check, Anybody elese working on the same project? Or
somebody has already done it?

The problem is that I have around 4MB of mail (several thousand MSGs) in
my old Yhaoo account and there is no way I can donload them in a
reasonable time.

Any ideas? Links?

Kalin.

-- 
||///_ o  *******************************
||//,_/>   WWW:     http://ThinRope.Net/  
|||\ <"       
|||\\ '   *******************************


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

Date: 06 Apr 2001 17:58:06 +0100
From: nobull@mail.com
Subject: Re: Secured demo scripts
Message-Id: <u91yr6q82p.fsf@wcl-l.bham.ac.uk>

erabbott@DONTSPAMterra.com.br (Er Galvão Abbott) writes:

> Does someone have a solution to expire a perl sctipt in a specific
> amount of time, like a demo software?

die "Licence expired\n" if time > 987410915;

> Does someone knows about a solution to "lock" a perl script if one or
> more lines of it are changed?

No, see FAQ "How can I hide the source for my Perl program?"
 
> I've seen some scripts that gives an Error if you change some specific
> lines of it...

Unless, of course, you modify the lines that do the checking!

> Does anyone have practical or even teorical examples?

If you find the FAQ answer insufficient please see numerous recent
threads dicussing this matter.  These threads will be easy to find
with a search engine because they'll all contain the string "How can I
hide the source for my Perl program?".

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


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

Date: Fri, 06 Apr 2001 11:20:00 -0400
From: Clinton Munden <clinton.munden@alcatel.com>
Subject: Re: Seeking Perl Script for Notice Board
Message-Id: <3ACDDEA0.E2F235F4@alcatel.com>

try this script at this site
http://www.waytotheweb.com
the script is called talkback

Clinton Munden

Mark Ryan wrote:

> Hi People,
>
> My company wishes to have a customer support notice board on the web site,
> and presently I have no real knowledge of Perl scripting, could someone
> point me to a source which is pre-written?
>
> --
>
> Regards,
>
> Mark Ryan - IT Administrator,
> Thermo Allen Coding Ltd., Unit 6, Little Mundells,
> Welwyn Garden City, Hertfordshire. AL7 1LD.
> Tel +44 (0) 1707 379500  Fax +44 (0) 1707 320225
> Email: it.admin@thermoallen-coding.co.uk
> Web Site: http://www.thermoallen-coding.co.uk



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

Date: Fri, 06 Apr 2001 14:30:04 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: Time difference
Message-Id: <Mpkz6.29466$Xx6.374334@Flipper>

Hi,

On my site I want to display the difference in time between a file on my
host and the current time on my host.
I need to know how I can display the days and hours that are between the
file and the current time.

Can someone help me out with this one ?




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

Date: Fri, 06 Apr 2001 16:49:42 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Time difference
Message-Id: <3ACDE595.E16F3E77@schaffhausen.de>

Waarddebon schrieb:
> 
> Hi,
> 
> On my site I want to display the difference in time between a file on my
> host and the current time on my host.
> I need to know how I can display the days and hours that are between the
> file and the current time.

Check out localtime + Date::Calc.

->malte


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

Date: 6 Apr 2001 15:43:17 GMT
From: nickco3@yahoo.DONT-SPAM-ME.co.uk (Nick Condon)
Subject: Re: Time difference
Message-Id: <907BAFEADNickCondon@132.146.16.23>

Waarddebon wrote:

>Hi,
>
>On my site I want to display the difference in time between a file on my
>host and the current time on my host.
>I need to know how I can display the days and hours that are between the
>file and the current time.
>
>Can someone help me out with this one ?

Assuming you mean the file's modification time, stat("filename")[9] will 
give you that in seconds since the epoch.

The function time() returns the system time in epoch seconds. So subtract 
the stat() value from the time() value and you have the age of the file in 
seconds. I'm sure you can take it from there.
-- 
Nick


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

Date: 06 Apr 2001 18:00:22 +0100
From: nobull@mail.com
Subject: Re: Time difference
Message-Id: <u9zoduoteh.fsf@wcl-l.bham.ac.uk>

"Waarddebon" <Waarddebon@chello.nl> writes:

> On my site I want to display the difference in time between a file on my
> host and the current time on my host.

Subtract the timestamp of the file from the current time.

perldoc -f time
perldoc -f stat

> I need to know how I can display the days and hours that are between the
> file and the current time.

You can convert seconds to hours by dividing by 3600.

There are 24 hours in a day.

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


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

Date: Fri, 6 Apr 2001 07:19:33 -0600
From: "Corey" <ccoogan@speakeasy.net>
Subject: Why won't this simple script work??
Message-Id: <tcrg7k8vmvokd9@corp.supernews.com>

I have this script that is supposed to do this:
Go through an entire dir, including subdirs, and look for matching file
names with a .shtml and .loc extension.  Then it should add an X to the
 .shtml file.  This works, but only at the root dir where I run it.  It won't
recurse.

I am new to PERL and didn't write this.  Could someone tell me what -e does?
Also, what is this doing?  What is the purpose of the *, to say all?:

*name = *File::Find::name;


#!/usr/bin/perl -lw
#add_x - append an x to files that have lock files associated with it
@ARGV = qw(.) unless @ARGV;

use File::Find();
sub find(&@) { &File::Find::find }
*name = *File::Find::name;
find

 if ($name =~ /\.loc$/ ) {
   substr($name,-3,3) = "shtml"; #$filename;
   if ( -e $name ) {
     $nwname = $name . "X";
     rename($name, $nwname) || warn "can't rename $name to $nwname"  ;
  }
 }
} @ARGV;




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

Date: Fri, 6 Apr 2001 09:12:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why won't this simple script work??
Message-Id: <slrn9crg5r.mad.tadmc@tadmc26.august.net>

Corey <ccoogan@speakeasy.net> wrote:

>Could someone tell me what -e does?


Yes, but if we read the docs to you for this question, we will
have to do it repeatedly for all future questions.

So please look it up yourself. Get the answer faster that posting
to Usenet:

   perldoc -f -e


Learn how to search Perl's standard docs and become more
self-sufficient.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 6 Apr 2001 17:52:11 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Why won't this simple script work??
Message-Id: <9akotj$5pss2$1@ID-13368.news.dfncis.de>

"Corey" <ccoogan@speakeasy.net> schrieb im Newsbeitrag
news:tcrg7k8vmvokd9@corp.supernews.com...
> I have this script that is supposed to do this:
> Go through an entire dir, including subdirs, and look for matching
> file names with a .shtml and .loc extension.  Then it should add
> an X to the .shtml file.  This works, but only at the root dir
> where I run it. It won't recurse.
>
It does recurse, but it doesn't rename because it doesn't find the
file it was looking for.

> I am new to PERL and didn't write this.  Could someone tell me
> what -e does?

-e checks for the existence of a file.

> Also, what is this doing?  What is the purpose of the *, to say
> all?:
>
> *name = *File::Find::name;
>
That creates an alias: after this $name is the same variable as
$File::Find::name. Thats unneeded "cleverness" in this case.

>
> #!/usr/bin/perl -lw
> #add_x - append an x to files that have lock files associated with
> @ARGV = qw(.) unless @ARGV;
>
> use File::Find();
> sub find(&@) { &File::Find::find }
> *name = *File::Find::name;
> find
>
>  if ($name =~ /\.loc$/ ) {
>    substr($name,-3,3) = "shtml"; #$filename;
>    if ( -e $name ) {
>      $nwname = $name . "X";
>      rename($name, $nwname) || warn "can't rename $name to $nwname"
;
>   }
>  }
> } @ARGV;
>
The script (assuming the typing errors were fixed) only works if you
use absolute path names as command line arguments. The problem is
that the File::Find chdirs() into the directory it is scanning, but
then $File::Find::name contains the full path name of the file
currently processed.

If you have a foo.shtml and a foo.loc in directory ./tmp then:
- File::Find chdirs to ./tmp
- it finds foo.loc
- it puts ./tmp/foo.loc in $File::Find::name
- the script changes that to ./tmp/foo.shtml
- in subdirectory tmp the script checks for the existence of
  ./tmp/foo.shtml (assuming . is still the directory from which
  the script was started then it actually checks if file
  ./tmp/tmp/foo.shtml exists)
- usually no such file will be found and so no rename will be
  executed


You have two possibilities:
1. reuse the original script and only use absolute path names as
   command line arguments

2. change the script to something like:

#!/usr/bin/perl -w
#add_x - append an x to files that have lock files associated with it

use strict;
use File::Find ();

sub wanted {
 my $name = $_;
 if ($name =~ /\.loc$/ ) {
   substr($name,-3,3) = "shtml"; #$filename;
   if ( -e $name ) {
     my $nwname = $name . "X";
     rename($name, $nwname) || warn "can't rename $name to $nwname"  ;
  }
 }
}

@ARGV = qw(.) unless @ARGV;
File::Find::find(\&wanted, @ARGV);







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

Date: Fri, 6 Apr 2001 17:02:08 +0100
From: "Plastic Fantastic" <grahamANTISPAMMING@nme.com>
Subject: Windows but not UNIX!?
Message-Id: <GKlz6.1009$cF4.149674@news6-win.server.ntlworld.com>

hey,

ive written a perl script which works fine when I run it through the Windows
port of perl (perl.exe). When I try to run it through UNIX however, it
reports some syntax errors and wont run. I dont use the -w switch either
time btw.

Any ideas?

Graham




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

Date: Fri, 6 Apr 2001 12:18:59 -0400
From: "Nathan Pertuset" <npertuset@hotmail.com>
Subject: Re: Windows but not UNIX!?
Message-Id: <41mz6.316$2a3.5893@newscontent-01.sprint.ca>

well, what's your script on? what's it do? maybe if you gave some of this
info, we could try to help you (and i dont' mean that in a mean way)...
"Plastic Fantastic" <grahamANTISPAMMING@nme.com> wrote in message
news:GKlz6.1009$cF4.149674@news6-win.server.ntlworld.com...
> hey,
>
> ive written a perl script which works fine when I run it through the
Windows
> port of perl (perl.exe). When I try to run it through UNIX however, it
> reports some syntax errors and wont run. I dont use the -w switch either
> time btw.
>
> Any ideas?
>
> Graham
>
>




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

Date: Fri, 06 Apr 2001 12:24:01 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Windows but not UNIX!?
Message-Id: <comdog-98000E.12240106042001@news.panix.com>

In article <GKlz6.1009$cF4.149674@news6-win.server.ntlworld.com>, 
"Plastic Fantastic" <grahamANTISPAMMING@nme.com> wrote:

> ive written a perl script which works fine when I run it through the Windows
> port of perl (perl.exe). When I try to run it through UNIX however, it
> reports some syntax errors and wont run. I dont use the -w switch either
> time btw.


what are the syntax errors?  have you tried fixing them and then 
running the script again in both places?

-- 
brian d foy <comdog@panix.com>



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

Date: Fri, 6 Apr 2001 16:24:13 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Windows but not UNIX!?
Message-Id: <GBDpKD.20L@presby.edu>

In article <GKlz6.1009$cF4.149674@news6-win.server.ntlworld.com>,
Plastic Fantastic <grahamANTISPAMMING@nme.com> wrote:
>
>ive written a perl script which works fine when I run it through the Windows
>port of perl (perl.exe). When I try to run it through UNIX however, it
>reports some syntax errors and wont run. I dont use the -w switch either
>time btw.
>
>Any ideas?

How about telling us what the syntax errors *are*?  And maybe showing 
the code that they point to?  :-\

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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