[19732] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1927 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 14 14:10:32 2001

Date: Sun, 14 Oct 2001 11:10:10 -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: <1003083010-v10-i1927@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 14 Oct 2001     Volume: 10 Number: 1927

Today's topics:
        newbie question - how to rename files with Perl? <yes@yesIsuppose.org>
    Re: newbie question - how to rename files with Perl? <pilsl_@goldfisch.at>
    Re: newbie question - how to rename files with Perl? <jurgenex@hotmail.com>
    Re: Perl and Win32 <bootsy52@gmx.net>
    Re: Perl and Win32 <bart.lateur@skynet.be>
    Re: PERL freelance programmer availeable <pne-news-20011014@newton.digitalspace.net>
        program to email text file (Glenn White)
    Re: program to email text file <tony_curtis32@yahoo.com>
    Re: program to email text file (Chris Fedde)
    Re: program to email text file <dtweed@acm.org>
        Specifying a range of values (Gary)
    Re: Specifying a range of values <junk@mytechsolutions.com>
    Re: Specifying a range of values (Garry Williams)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Oct 2001 05:01:17 -0500
From: Brehm <yes@yesIsuppose.org>
Subject: newbie question - how to rename files with Perl?
Message-Id: <fboist81k93jbuirokiim7tkb9b17t8gtl@4ax.com>

Hello-

I was hoping to dive into Perl by learning how to do a simple task.

I spend quite a bit of time renaming files.  I would like a script /
program I write to do this for me.  For example, I do the following to
all files:

-removing "_-_"  & replacing with "-"
-converting to lowercase
-replacing an empty space with "_"

I am running on Win2000 Server, & have the Resource Kit which includes
Perl.

I have a friend who suggested I go about this routine task using Perl;
so here I am.

Any advice / tips much appreciated,

Brehmie


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

Date: Sun, 14 Oct 2001 12:59:42 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: newbie question - how to rename files with Perl?
Message-Id: <3bc97027$1@e-post.inode.at>

Brehm wrote:

> Hello-
> 
> I was hoping to dive into Perl by learning how to do a simple task.
> 
> I spend quite a bit of time renaming files.  I would like a script /
> program I write to do this for me.  For example, I do the following to
> all files:
> 
> -removing "_-_"  & replacing with "-"
> -converting to lowercase
> -replacing an empty space with "_"
> 
> I am running on Win2000 Server, & have the Resource Kit which includes
> Perl.
> 

Best way to learn perl is to buy and to read a book. You dont need to 
follow the book exactely, but you get the basic information and some nice 
and explained examples. Later - as apprentice for semi-professionality - 
you can read all the manuals coming with perl and ask questions.

For your task, you need a combination of the following elements:

cpan-module File::Find to get  a list of all Files in the current sub and 
its subs or the Fileglob-operator <*> to get a list of the files in the 
current directory only.
Then you will have to perform a while or foreach-structure to run through 
all the files, perform a s///-command to replace '_-_' and ' ' and a tr/// 
to convert to lowercase and finally rename() to actually rename the file. 
The stat-function might be very handy also to determine if the current file 
is a file, a symlink, a directory.

modules and much more information can be found at www.cpan.org.
If you want to learn perl, you can write scripts and if they dont work, 
post the code here and we will help you, but you wont learn if we write the 
scripts here for you.


peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Sun, 14 Oct 2001 07:16:30 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: newbie question - how to rename files with Perl?
Message-Id: <3bc99e3f$1@news.microsoft.com>

"Brehm" <yes@yesIsuppose.org> wrote in message
news:fboist81k93jbuirokiim7tkb9b17t8gtl@4ax.com...
> I was hoping to dive into Perl by learning how to do a simple task.
>
> I spend quite a bit of time renaming files.  I would like a script /
> program I write to do this for me.  For example, I do the following to
> all files:

Very easy to do with Perl, although in these simple cases a one-line shell
script would suffice, too.

The words "to all files which ..." always triggers
        use File::Find;

> -removing "_-_"  & replacing with "-"
Just 'find' for files where the filename contains _-_ and then use the s
operator to create the new name and then use Perl's rename function to
actually rename the file.

> -converting to lowercase
Same but instead of the s operator use the lc function to convert the name
into all lower case

> -replacing an empty space with "_"
Same procedure as in first case.

Because you said you wanted to learn I deliberately didn't include any
fit-and-polished code. You will learn most by reading the docs and then
write your own code. Further info can be found using
    perldoc File::Find
    perldoc -f rename
    perldoc -f s (you may want to skip to 'perldoc perlop' directly)
    perldoc -f ls

Have fun

jue




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

Date: Sun, 14 Oct 2001 13:36:08 +0200
From: "Carsten Menke" <bootsy52@gmx.net>
Subject: Re: Perl and Win32
Message-Id: <pan.2001.10.14.13.36.08.86.2432@gmx.net>

On Sun, 14 Oct 2001 00:15:03 +0200, Darlene Murphy wrote:

> I am trying to get perl to run under WinME.  I have done web sites on
> unix systems with perl and they work fine.
> 
> For WinMe I am using WinSite and ActiveState Perl.  It dose not
> recognize #!g:\perl\bin\perl.  What should I use?  Also how do we put
> comments in our perl scripts.
> 
I would say you can give up, I tried this also once, but I have read that
windows is not able to process a shebang. And the funny thing on this?

Well, this was not possible in Win98 and from your post I see that it is
not possible until today :-)

So you have to call it explicit C:\perl yourscript.pl

But if you look in the ENVIROMENT VARIALBES of NT for example you see one
called PATHTEXT (hmmm, or similar) with the contents of .EXE;.BAT;COM. I
also do not know how where to add something to this variable but you
could try to add .PL. I'm very sure that you won't see this ENVIRONMENT
VARIALBE in WinME, but maybe on W2k. I know that this exists on WinNT 4.0
SP 5 Server Editon.

Hope that I could help you a little

Carsten


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

Date: Sun, 14 Oct 2001 14:54:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl and Win32
Message-Id: <be9jstgvgvce1sd9sl93ovc0bemts7i7ii@4ax.com>

Darlene Murphy wrote:

>I am trying to get perl to run under WinME.  I have done web sites on
>unix systems with perl and they work fine.
>
>For WinMe I am using WinSite and ActiveState Perl.  It dose not
>recognize #!g:\perl\bin\perl.  What should I use?

Is that indeed a valid path?

Apache, also a free download either from <http://httpd.apache.org/> or
it comes with IndigoPerl (<http://www.indigostar.com/indigoperl.htm>, a
proper alternative to ActivePerl), requires that this is the actual file
location, or you have to use a plain "perl".

>Also how do we put
>comments in our perl scripts.

Why, just right after a "#", which makes the interpreter ignore the rest
of the line. It is similar to Javascript's "//". Or you can use embedded
pod.

   HTH,
   Bart.


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

Date: Sun, 14 Oct 2001 09:46:48 +0200
From: Philip Newton <pne-news-20011014@newton.digitalspace.net>
Subject: Re: PERL freelance programmer availeable
Message-Id: <legistkca3631oqm5dq9qv568j7ke1mi85@4ax.com>

On 13 Oct 2001 19:03:11 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

> 7) Should I hire someone who has only a hotmail account?  What, you
> can't spring for the $20/month or so to get a real domain and hosting
> service?  How bad *is* your business at the moment.

He's probably done most of his work for clients who keep insisting
they're only 99 and 44/100 % satisfied and therefore don't need to pay
him. So he's been doing a lot of work for free.

(Seriously, that clause just seems to leave WAAY too much wiggle room
IMO.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Sun, 14 Oct 2001 16:52:19 GMT
From: spam.killer@home.com_nospam (Glenn White)
Subject: program to email text file
Message-Id: <Xns913A641A3F90Accruizermydejacom@24.0.0.25>

Instead of reinventing the wheel, I'm looking for a NT Perl email program 
that will help with the following task: I have a folder that receives text 
files by FTP. I need a program that will read the first few lines to get 
the To, CC, From, and subject lines, then place the remaining text in the 
body. After that, then send the email.

I will be adding the above code to a program that finds the correct file in 
the directory, adds additional info to the file, copies it to a different 
directory, then deletes the file from the current directory. At best, my 
Perl abilities are about an intermediate level.

Most the scripts I am finding receive input from web pages, not from text 
files. Any suggestions on the names and locations of a few good scripts I 
can reveiw? 

Thanks.


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

Date: Sun, 14 Oct 2001 11:56:29 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: program to email text file
Message-Id: <87adyucg8y.fsf@limey.hpcc.uh.edu>

>> On Sun, 14 Oct 2001 16:52:19 GMT,
>> spam.killer@home.com_nospam (Glenn White) said:

> Instead of reinventing the wheel, I'm looking for a NT
> Perl email program that will help with the following
> task: I have a folder that receives text files by FTP. I
> need a program that will read the first few lines to get
> the To, CC, From, and subject lines, then place the
> remaining text in the body. After that, then send the
> email.

The following modules are likely to be of help:

    Mail::Internet
    Mail::Mailer

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Sun, 14 Oct 2001 17:02:18 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: program to email text file
Message-Id: <uyjy7.106$oe8.170716672@news.frii.net>

In article <Xns913A641A3F90Accruizermydejacom@24.0.0.25>,
Glenn White <spam.killer@home.com_nospam> wrote:
>Instead of reinventing the wheel, I'm looking for a NT Perl email program 
>that will help with the following task: I have a folder that receives text 
>files by FTP. I need a program that will read the first few lines to get 
>the To, CC, From, and subject lines, then place the remaining text in the 
>body. After that, then send the email.
>

The FAQ has a section on sending mail.  Use the command 'perldoc -q mail'
in a command window to see a couple approaches.

Opening a file and parsing out a few details should not pose much of a
challenge.  I'm sure that the FAQ has something to say about that too.

Good Luck
-- 
    This space intentionally left blank


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

Date: Sun, 14 Oct 2001 17:26:23 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: program to email text file
Message-Id: <3BC9C95C.2802746B@acm.org>

Glenn White wrote:
> Instead of reinventing the wheel, I'm looking for a NT Perl email program
> that will help with the following task: I have a folder that receives text
> files by FTP. I need a program that will read the first few lines to get
> the To, CC, From, and subject lines, then place the remaining text in the
> body. After that, then send the email.

Here's a program I use for sending mail. It doesn't look for the Subject:
field, but I'll leave that as a simple exercise for you. Be sure to set
$server to something reasonable for your setup.

-- Dave Tweed

#!perl -w

# send-file.pl - Send a message from a file. The file must contain a header
#                with at least a To: field and a From: field.

use strict;
use Net::SMTP;
use Mail::Address;

&send_file (shift);

sub send_file {
    my ($filename) = @_;
    my (@email_to, @email_from);
    my $server = 'smtp.my.isp';    # <=== SET THIS!

    # Read the header of the file and find the To:, CC: and From: fields.
    open (IN, $filename) || die "can't read $filename: $!\n";
    my $nextline = <IN>;
    while ($nextline !~ /^\s*$/) {
        my $thisline = $nextline;
        # check to see if the next line is a continuation of this line
        while (($nextline = <IN>) =~ /^\s+\S/) {
            $thisline .= $nextline;
        }
        my ($name, $value) = split (/:\s+/, $thisline, 2);
        if ($name =~ /^to|cc$/i) {
            my @addrs = Mail::Address->parse ($value);
            push @email_to, map {$_->address || join ('', $_->phrase)} @addrs;
        } elsif ($name =~ /from/i) {
            my @addrs = Mail::Address->parse ($value);
            push @email_from, map {$_->address || join ('', $_->phrase)} @addrs;
        }
    }
    close IN;

    die "no To: address" unless @email_to;
    die "no From: address" unless @email_from;
    my $email_from = shift @email_from;

    warn "opening connection to $server\n";
    my $smtp = Net::SMTP->new ($server);

    warn "sending mail to <", join ('>, <', @email_to), "> from <$email_from>\n";
    $smtp->mail($email_from);
    foreach (@email_to) { $smtp->to($_); }
    $smtp->data();
    open (IN, $filename) || die "can't read $filename 2nd time: $!\n";
    while (<IN>) {
        $smtp->datasend($_);
    }
    close IN;
    $smtp->dataend();
    $smtp->quit;
}


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

Date: 14 Oct 2001 10:45:33 -0700
From: gary@academe-solutions.com (Gary)
Subject: Specifying a range of values
Message-Id: <43533b19.0110140945.1677e986@posting.google.com>

Probably a simple question, but I was wondering how I can specify a
range of vaules to use in an if statement.

For example, I want to specify for an action to be taken if a user
scores between X and Y.   How do I code that?  Thanks.


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

Date: Sun, 14 Oct 2001 12:06:07 +0000
From: Jopa <junk@mytechsolutions.com>
Subject: Re: Specifying a range of values
Message-Id: <vpky7.959$AU.285662@news.uswest.net>

Gary wrote:

> Probably a simple question, but I was wondering how I can specify a
> range of vaules to use in an if statement.
> 
> For example, I want to specify for an action to be taken if a user
> scores between X and Y.   How do I code that?  Thanks.


if (($X >= 20) && ($Y <= 30)) {
        do somthing....
}


this is one way, or you could use.



some stuff if (($X >= 20) && ($Y <= 30));



There may be an easier way but this is the way I know of and use.

Jopa
~~~~~`


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

Date: Sun, 14 Oct 2001 18:01:51 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Specifying a range of values
Message-Id: <slrn9sjkof.i33.garry@zfw.zvolve.net>

On 14 Oct 2001 10:45:33 -0700, Gary <gary@academe-solutions.com> wrote:
> Probably a simple question, but I was wondering how I can specify a
> range of vaules to use in an if statement.
> 
> For example, I want to specify for an action to be taken if a user
> scores between X and Y.   How do I code that?  Thanks.

  if ( $score > $X && $score < $Y ) { ... }

-- 
Garry Williams


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

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.  

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


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