[6820] in Perl-Users-Digest
Perl-Users Digest, Issue: 445 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 7 12:17:59 1997
Date: Wed, 7 May 97 09:00:22 -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 Wed, 7 May 1997 Volume: 8 Number: 445
Today's topics:
Re: > 2GB "file too large", AIX 4.2, perl 5.001, not "u (Abigail)
Re: @INC Modification (Brian Jepson)
[Q] how to remove a part of a text file (between given (Wojtek Swiatek)
Re: [Q]: l.f. suggestions for implementing lookahead (Kyzer)
Re: CGI help! (Abigail)
Re: clever coding required (Lance A. Brown)
Re: closed filehandle error <mcampbel@tvmaster.turner.com>
Re: closed filehandle error (Mike Stok)
Re: closed filehandle error (Bob Wilkinson)
Re: closed filehandle error <seay@absyss.fr>
Re: Finding a pattern in a file (Mike Stok)
Re: help the newbie??? please? <melissa@vorlon.mit.edu>
Re: informix and perl (Mike Stok)
Re: limiting user log written in perl? (Kyzer)
Modules under NT? <paul@dcs.ed.ac.uk>
Re: Moving a file <merlyn@stonehenge.com>
Re: Moving a file <seay@absyss.fr>
Re: Notice to antispammers - is there a list of spammer <merlyn@stonehenge.com>
Re: Notice to antispammers PLEASE READ (Kyzer)
Re: PERL NT Help ! (Magnus Bodin)
Re: Perl to C <jong@mrc-lmb.cam.ac.uk>
Re: program for perl? <jeffo@execpc.com>
Re: program for perl? <lin.293@postbox.acs.ohio-state.edu>
Re: REGEXP HELP, PLEASE! (Tad McClellan)
Renaming a mail file based on the date (Zachary Brown)
Re: replacing escape characters in a text file. <a.aitken@unl.ac.uk>
Re: replacing escape characters in a text file. (Mike Stok)
Re: replacing escape characters in a text file. (Tad McClellan)
REQ: Perl obfuscator (Magnus Bodin)
Re: slow script <brandon@physics.utexas.edu>
thanks to <brandon@physics.utexas.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 7 May 1997 13:36:33 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: > 2GB "file too large", AIX 4.2, perl 5.001, not "ulimit"
Message-Id: <E9tCGx.M0G@nonexistent.com>
On 6 May 1997 20:25:52 GMT, Bob Shair wrote in
comp.lang.perl.misc,comp.unix.aix URL: news:5ko44g$qie@vixen.cso.uiuc.edu:
++ "Geoff Mottram" <minaret@sprynet.com> writes:
++
++ >Two gigabytes is the typical file size limit on a UNIX system. That's
++ >because it's the largest number you can hold in a signed 32 bit integer.
++ >Even if AIX can create larger files, Perl may not be able to manipulate
++ >them properly. Are you sure you can't break the files up a bit?
++
++ Would that we could! This client is growing so fast it's almost killed
++ them!
Well, if cat can where perl can't, maybe you can cheat and let perl
create 2 GB chucks, which you then cat together using system.
Abigail
------------------------------
Date: 7 May 1997 13:53:12 GMT
From: bjepson@bjepson.ids.net (Brian Jepson)
Subject: Re: @INC Modification
Message-Id: <slrn5n0kga.ca.bjepson@bjepson.ids.net>
In article <336F8819.12AD@erols.com>, Terry Robison wrote:
>Does anyone know how to initialize @INC to point to a specific
>directory? A little backround:
>
Terry,
You can do this with something like:
use lib '/path/to/perl/libs';
>I have a system standard version of perl installed on my server (Version
>5.001). I have acquired a CGI script that requires 5.002. The system
>folks have installed V. 5.003 in another directory on the server. I have
>changed the first line of the scripts to reflect the newer version path.
>But I am still getting an error not locating the Oraperl module that is
>referenced in a "use" statement.
[...]
This could get tricky, as perl does lots of site-specific stuff when you
install a module. I would do a 'make clean' on the Oraperl source
directory, use the production version of perl to do a:
perl Makefile.PL
and then install from scratch (make; make install). If you point your perl
at an old version of a library extension, I don't know that it will work,
and will probably give weird results, at a minimum.
Hope this helps,
Brian Jepson * (bjepson@ids.net) * http://www.ids.net/~bjepson
Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux: http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books
------------------------------
Date: 7 May 1997 11:17:21 GMT
From: swiatek@ftjibm.ftj.agh.edu.pl (Wojtek Swiatek)
Subject: [Q] how to remove a part of a text file (between given delimiters)
Message-Id: <5kpoc1$9hd$1@galaxy.uci.agh.edu.pl>
Hello,
After reading the FAQ and the docs I have I still have a
question about a task I would like to do witgh perl. I just
start with this language. The problems I would like to solve can
be useful to more people
1.
I have a text file (PostScript in this case) and I would like to
write a script to remove lines between two given delimitors
(say, %%Begin Setup and %%End Setup). I belive there is a
simple way to do this in perl.
2.
I have a huge file full of mails (separated by a line starting
with "From ") and I would like to divide it in parts according
to the date of arrival (which can be gotten from the headers).
What is the main idea of doing it with perl (reading the whole
file into memory and then to didvide it in arrays ? I really do
not know)
I would be grateful for email answers because I would like to
summarize the solutions to the net in form of ready to use
scripts. The first one would be interesting for people including
EPS files generated under Windows/95/NT into LaTeX and the secon
one to people with huge sent-mail files which need some tiding
up. If knows solutions already exist please send me a pointer to
them, I will include it in the summary.
Thank you,
Best Regards,
Wojtek
---
Wojtek Swiatek -- AGH, Dept. of Physics, Krakow, Poland
email: swiatek@ftj.agh.edu.pl / swiatek@cern.ch / swiatek@desy.de
WWW: http://www.ftj.agh.edu.pl/~swiatek (all details are there)
------------------------------
Date: 7 May 1997 12:41:23 GMT
From: junkmail@abdn.ac.uk (Kyzer)
Subject: Re: [Q]: l.f. suggestions for implementing lookahead
Message-Id: <5kpt9j$5h5@info.abdn.ac.uk>
Hurrah, for 'tis said that Luca Passani did write:
: Of course I could save some status information and decide which action
: to take afterwards, but the lookahead would let me have a much more
: elegant solution.
The problem with that is you might not be able to ensure the unreading of
a line - what if each line is several megabytes in size and coming from a
pipe? You can't seek backwards, and it's too expensive to cache.
: One solution I've been thinking of is slurping
good idea :)
: the whole file into an array in advance in order to do things like:
: if ($arraywithfile[$currentline+1] =~ /regexp2/)
: but maybe someone has a good reason not to.
Very big file and not enough memory/swap available?
Not (too much of) a problem on servers, but I for one
use perl on home computers too.
#anyway... where were we?
die unless open(FILE,'<file.txt'); my @file = <FILE>; close FILE;
foreach (0..$#file) {
if ($file[$_] =~ /regexp/) {
if ($file[$_+1] =~ /regexp2/) {action1;} else {action2;}
}
}
--
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:
DC.W f+++ s+++ df h++++ Csilv a+ $+++ m d--- WL++ Fr---- Bslobber
------------------------------
Date: Wed, 7 May 1997 14:54:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: CGI help!
Message-Id: <E9tG30.2y3@nonexistent.com>
On Tue, 06 May 1997 12:12:34 +0100, Andrew Lin wrote in
comp.lang.perl.misc URL: news:336F1222.8D0@postbox.acs.ohio-state.edu:
++ Hi,
++
++ I've been messing around with PERL and CGI's for a while now and have
++ been tripping over all sorts of problems.
++
++ I downloaded an experimental Form written in PERL but everytime I try it
++ out I get the error:
++
++ HTTP/1.0 501 Not Supported
++
++
++ I've already set all the permissions correctly as far as I know.
++ I would really appreciate it if someone here could either:
++
++ A. offer a suggestion as to what the problem is
++
++ or
++
++ B. redirect me to a more accurate newsgroup. I know this is a perl
++ newsgroup but I figured someone here must know something since perl is
++ such a popular CGI language.
comp.infosystems.www.authoring.cgi, and/or
comp.infosystems.www.servers.<your-os>.
Your question has *nothing* to do with perl. I'm 99.9% sure you get the
same message if you rewrite the program in PL1, Cobol, or even delete
the entire cgi.
Oh, and it would help to give some HTML code.
Abigail
------------------------------
Date: 07 May 1997 11:28:02 -0400
From: brown9@niehs.nih.gov (Lance A. Brown)
Subject: Re: clever coding required
Message-Id: <55hggfs3nh.fsf@splat.niehs.nih.gov>
alex <alex99@ozemail.com.au> writes:
> a field | some more stuff | another field | field4 | hello mum
> If the leading and trailing whitespace can be consumed before the split,
> the split would be nicer, each field would be ready to go.
Try something like this:
$input=" a field | some more stuff | another field | field4 | hello mum";
print $input . "\n";
$input =~ s/\s*\|\s*/\|/g;
print $input . "\n";
The regexp matches 0 or more whitespace, a |, and zero or more
whitespace and replaces it with just a |.
--[Lance]
------------------------------
Date: 07 May 1997 07:33:09 -0400
From: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: closed filehandle error
Message-Id: <r5d8r3h5ze.fsf@tvmaster.turner.com>
Scott Blanksteen <sib@worldnet.att.net> writes:
> > close(FILE);
>
> You probably also want to check the return value of 'close'.
I've often wondered about this practice. Other than for reporting
purposes, of what value is checking to see whether or not a 'close'
was successful? I mean, what would you do if it weren't?
------------------------------
Date: 7 May 1997 12:16:34 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: closed filehandle error
Message-Id: <5kprr2$k76@news-central.tiac.net>
In article <r5d8r3h5ze.fsf@tvmaster.turner.com>,
Mike Campbell <mcampbel@tvmaster.turner.com> wrote:
>Scott Blanksteen <sib@worldnet.att.net> writes:
>> > close(FILE);
>>
>> You probably also want to check the return value of 'close'.
>
>I've often wondered about this practice. Other than for reporting
>purposes, of what value is checking to see whether or not a 'close'
>was successful? I mean, what would you do if it weren't?
If you're writing to a file and a file system fills up it's sometimes
easier to check the final close rather than checking the individual prints
(and I don't see that much code about which checks whether prints succeed
all the time ;-) This could be useful if you're about to delete a load of
data which was meant to have been summarised in the output file, for
example.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Wed, 07 May 1997 14:37:39 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: closed filehandle error
Message-Id: <b.wilkinson-0705971437390001@ip57-york.pindar.co.uk>
In article <336DD8B8.618F@sys.uea.ac.uk>, Undergraduate labs
<nobody@sys.uea.ac.uk> wrote:
> What could possibly be wrong with this program? I get the error
>
> print on closed file handle main::FILE
>
>
> #! /usr/local/bin/perl
>
> open(FILE, "</fozz/home1/ug/cmp/u9437517/www/cgi-bin/test.pab");
> print FILE "Hello\n";
> close(FILE);
>
>
> I am trying to write some perl to handle some routines in my web site
> but I can't get anything to write to a file. So I thought I'd go back
> to basics as above, even this doesnt work.
>
> Paul.
Paul,
Please check the retrun codes of the functions you use to interact with
the system.
e.g. open(FILE, "</fozz/home1/ug/cmp/u9437517/www/cgi-bin/test.pab")
or die "Can't open file for reading, $!";
At this point, you'd probably notice your major error, i.e. you've opened the
file for reading, rather than writing.
You should use a ">" to give write permission, rather than the "<" you used.
Bob
--
I have become death, destroyer of the worlds.
------------------------------
Date: Wed, 07 May 1997 17:13:00 +0200
From: Douglas Seay <seay@absyss.fr>
Subject: Re: closed filehandle error
Message-Id: <33709BFC.B80964C@absyss.fr>
Mike Stok wrote:
>
> In article <r5d8r3h5ze.fsf@tvmaster.turner.com>,
> Mike Campbell <mcampbel@tvmaster.turner.com> wrote:
> >Scott Blanksteen <sib@worldnet.att.net> writes:
>
> >> > close(FILE);
> >>
> >> You probably also want to check the return value of 'close'.
> >
> >I've often wondered about this practice. Other than for reporting
> >purposes, of what value is checking to see whether or not a 'close'
> >was successful? I mean, what would you do if it weren't?
>
> If you're writing to a file and a file system fills up it's sometimes
> easier to check the final close rather than checking the individual prints
> (and I don't see that much code about which checks whether prints succeed
> all the time ;-) This could be useful if you're about to delete a load of
> data which was meant to have been summarised in the output file, for
> example.
Also, if the handle was really a process, this is the easiest way to
detect an error. open() returning a TRUE value means that the fork()
was successful, it doesn't say that the exec() worked, nor anything else
about the status of the child process.
- doug
------------------------------
Date: 7 May 1997 11:56:27 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Finding a pattern in a file
Message-Id: <5kpqlb$i9t@news-central.tiac.net>
In article <5kpb0u$lnt@triton.np.ac.sg>, <Query???> wrote:
> I would like to find if a pattern exist in a certain file.
> If it does output the finding into another file.
> Both input and output file name is in a variable.
>
> e.ga:-
> $infile="/tmp/abc";
> $outfile="/tmp/out";
>
> grep $pat $infile > $outfile;
If you're working on a line by line basis then you might be able to start
with something like:
open (IN, "<$infile") || die "can't open $infile to read ($!)\n";
open (OUT, ">$outfile") || die "can't open $outfile to write ($!)\n";
while (<IN>) {
print OUT if /$pat/;
}
close (OUT) || warn "close $outfile ($!)\n";
close (IN) || warn "close $infile ($!)\n";
you can use a construct like
print OUT grep (/$pat/, <IN>);
but be aware that this can consume a lot more memory if the input file is
large.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 07 May 1997 09:07:08 -0400
From: Melissa Algeo <melissa@vorlon.mit.edu>
Subject: Re: help the newbie??? please?
Message-Id: <m3g1vzfn2b.fsf@vorlon.mit.edu>
>>>>> "Dave" == Dave Murray <makepono@hawaiian.net> writes:
Dave> Aloha all, I've decided to take the plunge into Perl, as I have
Dave> heard it is the mother of all scripting languages. I have
Dave> downloaded and installed the win32 perl install in my windows
Dave> 95 machine. I extracted the files into the directory
Dave> D:\Program Files\perl5
[snip]
Dave> The hello.pl file is in my d:\cgi folder, and as the readme
Dave> says, I copied that file into the d:\Program Files\perl5\bin
Dave> directory.
Dave> Now, 1. should I uninstall and install directly to D:\perl5
Dave> ???? 2. Is there something to do w/ long file names??? 3.
Dave> Can this interpreter run from the D:\ drive????
I'd recommend running the install.bat that Activeware gives you
instead of copying stuff around by hand. That would put Perl
in your path, adjust your registry a tad, and do other fun and
helpful things.
You don't have to have your scripts in Perl's bin directory. You
will have to associate "pl" (or some other extension) with the
Perl executable in File Manager/Explorer if you don't want to call
Perl explicitly all the time.
You might be interested in the Perl for Win32 FAQ:
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html
--
melissa@vorlon.mit.edu Melissa Algeo aa575@seorf.ohiou.edu
"Never trust a machine that can't count higher than one."
-Unknown
------------------------------
Date: 7 May 1997 11:37:30 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: informix and perl
Message-Id: <5kpphq$gf2@news-central.tiac.net>
In article <33701BD1.508@calweb.com>,
Frank S. (Lpage) <frank@calweb.com> wrote:
>has anyone accessed informix databases using perl?
>i'd love to know how. thanks.
If you're thinking of perl 5.xxx then you might want to look at
http://www.hermetica.com/technologia/perl/DBI/ for a description of the
database interface (DBI) to perl which presents a database independent
interface to perl and uses database driver (DBD) modules to communicate
with databases. It also contains information on the latest versions of
various drivers.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 7 May 1997 13:49:54 GMT
From: junkmail@abdn.ac.uk (Kyzer)
Subject: Re: limiting user log written in perl?
Message-Id: <5kq1a2$5h5@info.abdn.ac.uk>
Hurrah, for 'tis said that Pearl Fox did write:
: Hi,
Well, this is really a CGI application, but it's _about_ perl usage, so
heregoes.
: I would like to know how to program my user log for my web page from
: the program easylog to limit showing only the last 20 users of my web
: page and no more.
: How do I do this please?
Assuming you have a file with the log in this sort of format:
jim
doug
tom
kev
we can get a list of the names in the log (if the log format's more fancy
then you'll have to do extra parsing here)
die unless open (LOG,'<my_logfile'); my @names=<LOG>; close LOG;
now, we have a nice list of names in chronological order with newlines at the
end. the last 20 logins would be:
if ($#names >= 20) {
foreach (reverse($#names-20..$#names)) { print $names[$_]; }
}
however, the last 20 _people_ is more complex: we'll need Handy Harry the Hash
#warning - this destructs all of the @names list
my (%foo, $count, $next); $count=1;
while ($next = pop @names) { $foo{$next} = $count++ unless $foo{$next}; }
foreach ((sort { $foo{$a} <=> $foo{$b} } keys %foo)[0..19]) { print; }
--
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:
StudentCode(v1.0) BSc A Y-- C++ E L W- G+ X? P-- T++ F M H++
------------------------------
Date: Wed, 7 May 1997 12:52:46 GMT
From: Paul Anderson <paul@dcs.ed.ac.uk>
Subject: Modules under NT?
Message-Id: <E9tAG1.3M6.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk>
I'd *really* like to use the Bit::Vector module, but unfortunately, I
need
it to run on an NT machine as well.
I tried to build the module under NT, but it failed at the first stage
(perl makefile.PL) complaining that it couldn't find any of the files in
the kit. Even if I get past this stage, I'm not sure how to compile the
thing (I have visual C++, but I've not used it).
Is it possible (easy) to build modules like this under NT? If so, what do
I
and are there any instructions anywhere?
Alternatively, does anyone have a pre-compiled version of this module for
NT?
Many thanks
Paul
Paul Anderson <mailto:paul@dcs.ed.ac.uk> Phone: (+44)
(0)131-650-5193
LFCS, Department of Computer Science, University of Edinburgh, EH9 3JZ,
UK
<http://www.dcs.ed.ac.uk/~paul/> (PGP Key) Fax: (+44)
(0)131-667-7209
Fingerprint: 512/1EE87121 A3 31 BC FD 70 FE 9D 3E 18 CC 36 AB 56 F6 CB
C8
------------------------------
Date: 07 May 1997 06:52:25 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: schlein@umbc.edu (Jonas J. Schlein)
Subject: Re: Moving a file
Message-Id: <8cd8r34cfa.fsf@gadget.cscaper.com>
>>>>> "Jonas" == Jonas J Schlein <schlein@umbc.edu> writes:
Jonas> PERL doesn't seem to have a "move" or "copy" operator for files. The
Jonas> "Learning Perl" book does suggest that you may 'move' a file by using
Jonas> the rename command, however this does not appear to work across file
Jonas> systems. I guess I'd have to blame this on the way UNIX implements the
Jonas> underlying "rename" function.
Jonas> Anyway what is the best work around for this? Calling 'mv'
Jonas> would certainly, work, but it's not 100% portable to non-UNIX
Jonas> systems. I'd really rather not write my own copy function
Jonas> although this seems like the best way off the top of my head
Jonas> followed by an unlink call.
This works in 5.004:
use File::Copy "move";
move("/etc/fred","/usr/src/barney");
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 482 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: Wed, 07 May 1997 16:57:26 +0200
From: Douglas Seay <seay@absyss.fr>
To: a.aitken@unl.ac.uk
Subject: Re: Moving a file
Message-Id: <33709856.13C311C4@absyss.fr>
[posted and mailed]
Alastair Aitken wrote:
>
> Jonas J. Schlein wrote:
> >
> > PERL doesn't seem to have a "move" or "copy" operator for files. The
> > "Learning Perl" book does suggest that you may 'move' a file by using
> > the rename command, however this does not appear to work across file
> > systems. I guess I'd have to blame this on the way UNIX implements the
> > underlying "rename" function.
>
> I think rename is just mv by any other name. If you check your /usr/bin
> directory for ln, cp and mv you may find, as I did, that they are all
> the same file. It's behaviour depends how the file is called (by what
> name) at invocation time.
I don't think so, although since I've never read the source, I'm stating
opinion, not fact. I think that rename calls rename(2), a Unix system
call to rename a file on the same filesystem. If perl's rename called
/bin/mv (or whatever), then it would have been called "move" or "mv" or
something of the sort. And why isn't there a "copy" or "cp" function
too? The same logic holds for symlink calling symlink(2) but there
being no equivalent for a hard (non-symbolic) link.
For more information about rename(2), check your man pages or
comp.os.linux.misc with Deja News because this was a topic there a week
or two ago.
As for ln/cp/mv being the same, that is implementation dependent. I
think that it is a good idea as they all muck around the same places.
But on my RedHat 4.0 (linux 2.0.18) system, these files all have
different inodes and sizes, so for me they are three different files.
/bin> ls -il cp mv ln
10203 -rwxr-xr-x 1 root root 29348 Aug 19 1996 cp
10208 -rwxr-xr-x 1 root root 20284 Aug 19 1996 ln
10209 -rwxr-xr-x 1 root root 21380 Aug 19 1996 mv
/bin>
> > Anyway what is the best work around for this? Calling 'mv' would certainly,
> > work, but it's not 100% portable to non-UNIX systems. I'd really rather
> > not write my own copy function although this seems like the best way
> > off the top of my head followed by an unlink call.
>
> Copying can be easily achieved by opening the original for read and the
> new for write and streaming the one into the other:
>
> open (IN, "/path/to/old.file");
> open (OUT, "> path/to/new.file");
> while ( <IN> ) {
> print OUT $_;
> }
> close (IN);
> close (OUT);
This works, but needs quite a bit more error checking. I realize that
you already know this, but since it was an example, I would have
prefered to have seen the "open() || die" principle. And instead of <>
I would use read() as it can grab large(r) chunks and sling them around,
but just because efficency is a bugaboo of mine.
> A move is then achieved by deleting the original after the copy.
>
> This was tested with a copy of the cp program, an ELF 32-bit stripped
> executable.
>
> unlink "/path/to/old.file";
This is another system call accessed by a Perl function/operator.
- doug
------------------------------
Date: 07 May 1997 07:00:03 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: regan@ao.com (Dave Regan)
Subject: Re: Notice to antispammers - is there a list of spammers to pluginto procmail?
Message-Id: <8cafm74c2k.fsf@gadget.cscaper.com>
>>>>> "Dave" == Dave Regan <regan@ao.com> writes:
Dave> There is a list that AOL maintains. It isn't necessarily in a format
Dave> for directly plugging into procmail. See:
Dave> http://www.idot.aol.com/preferredmail/
Dave> With a short Perl program I'm sure you can remove the HTML wrapping
Dave> and get straight to the addresses. From there it should be easy
Dave> to add the wrapping to make it fit into procmail. Then you can fire
Dave> the whole mess off with cron and not have to worry about it anymore
Dave> (except for when AOL changes the format of the file. :))
Ooh. Ooooh. I think you just gave me the content of my next
WebTechniques column (due this week anyway :-). "Extract the meat of
this webpage and generate the appropriate procmail blocklist". Yes.
Cool. (Prior WebTechniques columns are online at
http://www.stonehenge.com/merlyn/WebTechniques/ -- if for some reason
you haven't already seen the announcement in comp.lang.perl.announce.)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 482 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: 7 May 1997 12:25:36 GMT
From: junkmail@abdn.ac.uk (Kyzer)
Subject: Re: Notice to antispammers PLEASE READ
Message-Id: <5kpsc0$5h5@info.abdn.ac.uk>
Hurrah, for 'tis said that Me did write:
: What some don't like is the fact that these addresses being on a page
: are very very easy for spam bots to get and use.
Do you think it's any harder than grepping through newsfeed?
/local/bin/perl - /news/comp/lang/perl/misc/*
while (<>) { print if /^From:/i or /^Reply-To/i; }
: The simple way Tom can stop that is to split each address into 2 parts
: without using links, like so...
: <B>a3200 at hotmail.com</b>
: <B>Joe at did.com</b>
: This will make it hard for spam bots to read the addresses but the real
: users, ie. you and me can use the addresses easily.
s/<B>(\S+)\ at\ (\S+)</b>/$1\@$2/gim;
--
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:
Amiga makes it, well, not necesarily possible, but a lot of fun trying anyway.
------------------------------
Date: Wed, 07 May 1997 13:06:56 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: PERL NT Help !
Message-Id: <33706986.1137139550@news1.telenordia.se>
Paul Zahnle <webmaster@nuro.com> wrote:
>Hey All,
>
>In NT Land, Were having trouble passing an Arg. to our script.
>the string will be:
>/user-bin/ourscript.pl?file_number
>
>we need to delete the file using unLink
>
>here's our script:
>
>print "HTTP/1.0 200 OK\n";
>print "Content-type:text/html\n\n";
>
>print "<html>";
>print "<head>";
>print "<title>Test Perl Script</title>";
>print "</head>";
>print "<body>";
>print "<h1>Removing File</h1>";
>
>if( !defined($ENV{"QUERY_STRING"})){
> &pk_error("No File name to remove\n");
>}
>
>$input=$ENV{"QUERY_STRING"};
>
>print $input;
>unlink 'C:\InetPub\ftproot\staging\@input';
Apart from being a little dangerous script,
you are not going the right way with the backslashes...
First: your @input should be $input.
Second: If you use ' the $input won't change... :-)
Third; when you've changed to " then, use double backslashes...
Rewrote it a little like this and it works...
print "Content-type: text/html\n\n";
print <<'--CUT';
<html>
<head>
<title>Test Perl Script</title>
</head>
<body>
--CUT
$input=$ENV{'QUERY_STRING'};
$path="f:\\pub\\scripts\\test\\";
#concatenate strings
$file=$path . $input;
# if file $file is writable
if (-w $file) {
print "<h1>Removing $file</h1>";
unlink $file;
} else {
print "<h1>Can\'t find $file<\/h1>";
}
print "</body></html>";
------------------------------
Date: Wed, 07 May 1997 14:21:20 +0100
From: Jong <jong@mrc-lmb.cam.ac.uk>
To: "Simon E." <NYXEL@ny.ubs.com>
Subject: Re: Perl to C
Message-Id: <337081D0.167E@mrc-lmb.cam.ac.uk>
Simon E. wrote:
>
> Hi there,
> Does anyone know if there is a Perl to C translator program out there?
> We want to convert a couple of perl scripts into C functions, but trying
> to avoid re-writing.
>
> Please e-mail to nyxel@ny.ubs.com, -- I don't really check this
> newsgroup.
> thanks a lot,
> -Simon
There is a perl compiler by Malcolmn Beatie,
Try CPAN site for it.
Jong
--
I support Perl, Linux ...
With OVER SIX MILLION USERS, up from only ten or so a very few years
ago, Linux has taken it's place as the world's #3 computer operating
system overall. And Linux is breathing down the neck of #2 for very good
reasons. If growth rate to date continues, Linux will be the #1 computer
operating system by late '98 or '99. Are YOU ready?
) Linux Newsletter
http://www.smli.com/people/john.ousterhout/scripting.html
------------------------------
Date: 7 May 1997 14:29:05 GMT
From: "Jeff Oien" <jeffo@execpc.com>
Subject: Re: program for perl?
Message-Id: <01bc5af4$2999da00$7042cfa9@Pjeffo.execpc.com>
> >Wow, I thought I was the only one doing that! Do you find gazelle blood
> >works as well, or do you really need antelope? I'm experimenting with
> >ibexes (ibices?), too.
>
> That's fine, unless you want to see what would happen under VMS. In that
> case you had better be careful to use the correct plural - ibexen :-)
>
I'm surprised nobody has yet discovered that camel blood works best.
--
Jeff Oien, WebDesigns
http://www.execpc.com/webdesigns/
jeffo@execpc.com
------------------------------
Date: Wed, 07 May 1997 10:54:08 +0100
From: Andrew Lin <lin.293@postbox.acs.ohio-state.edu>
Subject: Re: program for perl?
Message-Id: <33705140.6176@postbox.acs.ohio-state.edu>
Jeff Oien wrote:
>
> > >Wow, I thought I was the only one doing that! Do you find gazelle blood
>
> > >works as well, or do you really need antelope? I'm experimenting with
> > >ibexes (ibices?), too.
> >
> > That's fine, unless you want to see what would happen under VMS. In that
> > case you had better be careful to use the correct plural - ibexen :-)
> >
>
> I'm surprised nobody has yet discovered that camel blood works best.
> --
> Jeff Oien, WebDesigns
> http://www.execpc.com/webdesigns/
> jeffo@execpc.com
Actually, I've been trying with my own blood, but eventually I can't
think straight and then I pass out. When I wake up, the scripts usually
don't work...
Andrew
------------------------------
Date: Tue, 6 May 1997 23:48:47 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: REGEXP HELP, PLEASE!
Message-Id: <fj1pk5.lu.ln@localhost>
Samson Melamed (samson@otterspace.com) wrote:
: Subject: REGEXP HELP, PLEASE!
^^^^^^^^^^^^^^^^^^^^
Ouch!
You don't need to yell at us. Shouting may actually result in less
people reading your post. The opposite effect of what you
were probably trying to get with all that upper case...
[ many folks have killfiled Subjects that do not contain any
lower case letters. Gets rid of the "MAKE MONEY FAST" kind
of thing...
]
: Hello,
Hi.
: I'm working on a project, and I've stumbled in my fluency in Regexpese.
: ;-) I need three subroutines, each to parse the following lines as
: described through a '$var =~ /regexp/' If anyone can send me the regexps
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I hope you don't really need this restriction. I believe I can
get the parts you want separated into variables, but I don't want
to have to do it that way ;-)
: to do that, I would be very greateful.
[ snip sample data and desired output ]
------------------------------------------
#! /usr/bin/perl -w
##############
### first line
##############
$name = 'N3TJU MELAMED, SAMSON LIC ISU 15-FEB-1997';
@parts = (split /,?\s+|-/, $name)[0..2,5..7]; # or let "\s+LIC ISU " be
# another separator
foreach (@parts) {print "$_\n"}
print "\n\n";
###############
### second line
###############
$street = 'GENERAL 10422 BURNT EMBER DR LIC EXP 19-SEP-2004';
@parts = (split /\s+LIC EXP |\s\s+|-/, $street);
foreach (@parts) {print "$_\n"}
print "\n\n";
##############
### third line
##############
$city = ' SILVER SPRING MD 20903 LST UPD 15-FEB-1997';
@parts = (split /\s+LST UPD |\s\s+|-/, $city);
foreach (@parts) {print "$_\n"}
----------------------------------------
: Thanks a lot!
You're welcome.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 7 May 1997 08:46:33 -0400
From: zbrown@lynx.dac.neu.edu (Zachary Brown)
Subject: Renaming a mail file based on the date
Message-Id: <5kptj9$mov@lynx.dac.neu.edu>
I want to use procmail and formail to organize mailboxes, and part of the
organization process is to put groups of messages in date order. Procmail
and formail won't do this, unless I have a short script that can
understand email headers, extract the date, translate it into the number
of seconds since 1970 (or whatever that number is that I've read about),
and use that as the new filename to put the message in.
I'd like to use a script that already exists and has been thoroughly
tested, if possible, rather than kludge up my own. I'm sure other people
have, from time to time, had need of a script like this. Is one available?
Zack
------------------------------
Date: Wed, 07 May 1997 13:10:13 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: replacing escape characters in a text file.
Message-Id: <33707125.265E@unl.ac.uk>
cedric tio wrote:
>
> Dear Perl users,
> I need to replace escape characters (^[) in a text file with asterixs. I
> tried doing s/\^\[/*/g; but it doesn't work.
> Can someone help me with this?
s/\e/*/g; # check out man perlre - an escape char is denoted by \e
Alastair.
------------------------------
Date: 7 May 1997 12:01:16 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: replacing escape characters in a text file.
Message-Id: <5kpquc$ijt@news-central.tiac.net>
In article <01bc5ac5$87121e60$5378238a@pc1.asia.compaq.com>,
cedric tio <cedric=tio%design%eng=sin@bangate.compaq.com> wrote:
>Dear Perl users,
> I need to replace escape characters (^[) in a text file with asterixs. I
>tried doing s/\^\[/*/g; but it doesn't work.
> Can someone help me with this?
You're actually trying to replace the 2 chatacter sequence ^[ with an
asterisk here, if you have an escape character in a string then you might
do something like
$string =~ s/\e/*/g;
or you can use an escape sequence to represent ESC (27 in ASCII)
$string =~ s/\033/*/g;
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Wed, 7 May 1997 06:24:56 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: replacing escape characters in a text file.
Message-Id: <8qopk5.sg.ln@localhost>
cedric tio (cedric=tio%design%eng=sin@bangate.compaq.com) wrote:
: Dear Perl users,
: I need to replace escape characters (^[) in a text file with asterixs. I
: tried doing s/\^\[/*/g; but it doesn't work.
: Can someone help me with this?
s/\c[/*/g; # see perlop or perlre man page, search for 'control char'
: Thanx.
You're welcome.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 07 May 1997 13:10:20 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: REQ: Perl obfuscator
Message-Id: <33717f04.1142641281@news1.telenordia.se>
Is there a perl obfuscator around?
As if lurkers hadn't problems yet reading regexps :-D
I really need one.
------------------------------
Date: Wed, 07 May 1997 09:52:49 -0500
From: "Brandon W. Metcalf" <brandon@physics.utexas.edu>
Subject: Re: slow script
Message-Id: <33709741.167E@physics.utexas.edu>
Thanks to everyone that responded.
--
Brandon Metcalf
UNIX Systems Administrator
Department of Physics - UT Austin
brandon@physics.utexas.edu
------------------------------
Date: Wed, 07 May 1997 09:49:23 -0500
From: "Brandon W. Metcalf" <brandon@physics.utexas.edu>
Subject: thanks to
Message-Id: <33709673.41C6@physics.utexas.edu>
everyone that responded.
--
Brandon Metcalf
UNIX Systems Administrator
Department of Physics - UT Austin
brandon@physics.utexas.edu
------------------------------
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 445
*************************************