[6945] in Perl-Users-Digest
Perl-Users Digest, Issue: 570 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 16:10:00 1997
Date: Wed, 4 Jun 97 13:00:23 -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, 4 Jun 1997 Volume: 8 Number: 570
Today's topics:
Re: Atomic file create or fail if already existing (R Bradley)
Re: EBCDIC and Perl <flavell@mail.cern.ch>
Exciting Job opening at start-up in California <michael@accrue.com>
Re: find out no.of lines in open file <rootbeer@teleport.com>
Finding string length <tullyk@tcd.ie>
Re: Finding string length <nospam-djohnson@uu.net-nospam>
Re: Finding string length (Honza Pazdziora)
Re: get the users login name <ray@icix.net>
Having problems producing an adequate s/// subst. <my@the.Bit.Bucket>
Re: Help building a regexp (bug?) (Chipmunk)
Help finding memory leak <kevin.t.huber@cdc.com>
Re: Help finding memory leak (Ilya Zakharevich)
Re: inconsistent opendir behaviour in Perl for win32 <rootbeer@teleport.com>
Re: Introductory Comparison of Perl and Python (Abigail)
Re: mount command in an suid script - howto ? <rootbeer@teleport.com>
Re: Need help with PERL! <johnc@interactive.ibm.com>
Re: Newbie question <rootbeer@teleport.com>
Re: Newbie question (Chipmunk)
Re: newbie question <rootbeer@teleport.com>
Re: newbie question2 (Tad McClellan)
open won't open files in subdirectories? <pociask@maricopa.edu>
PERL assistance w/NT simmonsl@smsndc.com
Re: printf padding ... <rootbeer@teleport.com>
Re: Read a file to $wholefile (Dave Cross)
Re: reading a file (html) from an other server <rootbeer@teleport.com>
Returning a filehandle from a module (Dirk Rheeder)
Re: Segmentation fault from multiple mkdirs in Perl scr (Abigail)
using select() and Perl/NT <jsolomon@oneiron.stanford.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Jun 1997 17:06:05 GMT
From: rick@rentec.com (R Bradley)
Subject: Re: Atomic file create or fail if already existing
Message-Id: <5n479t$6b4@puma.rentec.com>
Leonard Megliola (lmegliol@inertia.acs.uci.edu) wrote:
: I need an atomic operation which will create a new file if it
: doesn't exists, but fail if the file already does exist.
If you're on Unix you can man open(2) and look at O_EXCL and O_CREAT.
The open in the POSIX module should behave in the same way.
RIck
------------------------------
Date: Wed, 4 Jun 1997 17:38:49 GMT
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: EBCDIC and Perl
Message-Id: <Pine.A41.3.95a.970604191139.124544A-100000@sp072>
On Wed, 4 Jun 1997, Daniel Honig wrote:
> Has anyone seen or written a perl script to convert
> between EBCDIC and ASCII?
"Anyone" has: Altavista's first match to a search for ebcdic perl was
http://www.oasis.leo.org/perl/scripts/textproc/EBCDIC.2.ASCII.dsc.html
Remember, "ASCII" is an old 7-bit character code, and there are many
flavours of EBCDIC. I didn't take the time to check the conversion
table to see if it accords with the one that's commonly used.
If you want to convert between iso-8859-1 and the de-facto Latin-1
EBCDIC code (CECP1047), there's a better 8-bit conversion table at Andre
Pirard's site or mirrored at
ftp://watsun.cc.columbia.edu/kermit/charsets/iso8859.networking
Why do you want to do this? The code at the above URL looks quite
clumsy. There are excellent and efficient utilities for doing what
you want - e.g try GNU recode, if you don't specifically want Perl.
And if you do, then I suspect one of the regulars here can give you
some better coding than in the above script.
> Or if nothing else a reference page on the web for EBCDIC?
Sure, see RFC1345, and see Andre Pirard's document cited above.
Use that http://altavista.digital.com/ or your favourite search
engine, it's quicker and quieter. Then you get better value here
when you're _really_ stuck ;-)
------------------------------
Date: Wed, 04 Jun 1997 10:52:00 -0700
From: Michael Brodesky <michael@accrue.com>
Subject: Exciting Job opening at start-up in California
Message-Id: <3395AB40.20F9@accrue.com>
Looking for people with perl, sql, java, C, and other experience
to join an exciting company www.accrue.com. Email resume to
michael@accrue.com.
We are 35 people currently, and offer a great place to work, flexible
hours, good benefits.
Michael
------------------------------
Date: Wed, 4 Jun 1997 12:00:58 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Pui Ming WONG <s11976@net2.hkbu.edu.hk>
Subject: Re: find out no.of lines in open file
Message-Id: <Pine.GSO.3.96.970604120006.12995A-100000@kelly.teleport.com>
[ repost - I messed up the URL the first time. ]
On 4 Jun 1997, Pui Ming WONG wrote:
> Now i would like to know the total no. of lines in this file COUNT,
Did you check the FAQ? :-)
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq5/
How_do_I_count_the_number_of_lin.html
-- 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: Wed, 4 Jun 1997 19:15:50 +0100
From: Kieran Tully <tullyk@tcd.ie>
Subject: Finding string length
Message-Id: <Pine.OSF.3.96.970604191007.5593B-100000@alf2.tcd.ie>
Hi all,
How can I find the length of a string (or more particularly a line) in
Perl ? I know how to get the length of an array; is there a way to convert
a string so that it can be treated as an array of chars ? (or does Perl
even have a concept of arrays of chars ? - as you can probably guess, I'm
quite new to it.)
Thanks for your help,
|/ Internal TCD Home Page: http://www3.alf2.tcd.ie/~tullyk
|\ieran World access Home Page: http://www.angelfire.com/tx/tullyk/
E-mail: tullyk@tcd.ie
------------ // . Computer Science Student, Trinity College Dublin
Kieran Tully \X/ AM|GA Web Developer, Commodore Users Group of Ireland
------------------------------
Date: Wed, 04 Jun 1997 13:58:55 -0500
From: Dale Johnson <nospam-djohnson@uu.net-nospam>
To: Kieran Tully <tullyk@tcd.ie>
Subject: Re: Finding string length
Message-Id: <3395BAEF.167EB0E7@uu.net-nospam>
Kieran,
To find the length of a string, use length() in Perl 5.xxx. Something
like:
$length = length($string);
So, if $string was "abcde", then $length would be assigned a value of 5.
Hope this helps.
dale
Kieran Tully wrote:
>
> How can I find the length of a string (or more particularly a line) in
> Perl ? I know how to get the length of an array; is there a way to convert
> a string so that it can be treated as an array of chars ? (or does Perl
> even have a concept of arrays of chars ? - as you can probably guess, I'm
> quite new to it.)
>
--
Dale R. Johnson, Jr. -- djohnson[at]uu.net -- http://www.drsj.com/
PGP Key: 1024/7F16D9FF Fingerprint: D52DF796E5693AA3 F500A8FCEF354154
perl -e 'foreach(`finger johnson\@doit.net`){$a=1if/^-/;print if$a}'
------------------------------
Date: Wed, 4 Jun 1997 19:32:49 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Finding string length
Message-Id: <adelton.865452769@aisa.fi.muni.cz>
Kieran Tully <tullyk@tcd.ie> writes:
> Hi all,
>
> How can I find the length of a string (or more particularly a line) in
> Perl ? I know how to get the length of an array; is there a way to convert
> a string so that it can be treated as an array of chars ? (or does Perl
> even have a concept of arrays of chars ? - as you can probably guess, I'm
You might want to check the perldata man page about data types
available. To get the length of a string you use a function named
-- surprise -- length.
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
Have you done your DES today? --> http://www.des.sollentuna.se/
------------------------------
Date: Wed, 04 Jun 1997 15:16:08 -0400
From: Ramon Castillo <ray@icix.net>
To: orwant@media.mit.edu
Subject: Re: get the users login name
Message-Id: <3395BEF8.7095@icix.net>
Also if you have whoami you can do :
print ("Username : ,'whoami');
------------------------------
Date: Wed, 04 Jun 1997 14:46:17 -0400
From: Dan Hamilton <my@the.Bit.Bucket>
Subject: Having problems producing an adequate s/// subst.
Message-Id: <3395B7F9.7CE277BD@the.Bit.Bucket>
I have attempted, pondered, searched, read, attempted, pondered,
searched, read, .... and I STILL can't seem to come up with a
substitution that will do my job.
The problem is conceptually simple: Replace all spaces contained in
quotes with a placeholder. I found code that works, but seems quite
poor. The following code snippet is an example of what I would like to
do.
foreach $term (@terms) {
# Do some binary-state switching:
if ( $iterator == 1 ) {
$iterator--;
} else {
$iterator++;
}
# The iterator is 0 during grouped states:
$term =~ s/ /$placeholder/g unless $iterator;
$FORM{'terms'} .= $term;
}
(It has been adapted from a CGI script -- thus the $FORM{'terms'} )
My goal is similar, exept I am operating on a scalar text string. For
that reason, I cannot use a "foreach" construct. The text string
contains (possibly) multiple lines, with sections in double quotes; each
quoted snippet containing any number of words. The sections in double
quotes must be transformed into a single word before further processing
can take place. As I mentioned, i'd like to take $text and perform a
substitution:
$text =~ s/????/$placeholder/g
The next line would split $text by spaces to provide an array of
"terms". These terms will then be used individually (with $placeholder
removed).
Does anyone have any ideas about the s/// problem above? What can I use
as my regular expression? Can the problem be solved with s/// alone?
Thanks!
Matt
------------------------------
Date: 4 Jun 1997 18:50:09 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Help building a regexp (bug?)
Message-Id: <5n4dd1$62s$1@dartvax.dartmouth.edu>
In article <EB90nu.Hp8@mv.mv.com>
sdn@mv.mv.com (Eric Roode) writes:
> One complication is that the names can contain special characters;
> in fact, one of the names has a pipe character in it. So I have
> to include \Q and \E in my join.
How about using the quotemeta function on the names, before joining
them together with '|'?
Then you wouldn't need to use \Q and \E.
Chipmunk
------------------------------
Date: 04 Jun 1997 13:24:57 -0500
From: Kevin Huber <kevin.t.huber@cdc.com>
Subject: Help finding memory leak
Message-Id: <206icjk6.fsf@hobbit.udev.cdc.com>
Is there a way to tell how much memory Perl has allocated for a particular
data structure? It was also be helpful if there was a way to indicate how
memory data the process itself is using.
I'm trying to track down a memory leak and I'm not sure at what point it
is occurring (or in which structure). By memory leak, I mean that a data
structure is becoming very large due to a bug (400+ MB), rather than a
problem with perl itself (I think anyway!).
thanks,
-Kevin
Kevin.T.Huber@cdc.com
------------------------------
Date: 4 Jun 1997 19:08:24 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Help finding memory leak
Message-Id: <5n4ef8$j2c$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Kevin Huber
<kevin.t.huber@cdc.com>],
who wrote in article <206icjk6.fsf@hobbit.udev.cdc.com>:
> Is there a way to tell how much memory Perl has allocated for a particular
> data structure? It was also be helpful if there was a way to indicate how
> memory data the process itself is using.
>
> I'm trying to track down a memory leak and I'm not sure at what point it
> is occurring (or in which structure). By memory leak, I mean that a data
> structure is becoming very large due to a bug (400+ MB), rather than a
> problem with perl itself (I think anyway!).
If your Perl is compiled with -DDEBUGGING_MSTATS and Perl's malloc,
just set
env PERL_DEBUG_MSTATS=2 perl your_script
and this may give you some ideas. You can also get statistics at
runtime by using Devel::Peek.
I posted a patch for 5.004 which allows -DLEAKTEST again (look in p5-p
archives).
Ilya
------------------------------
Date: Wed, 4 Jun 1997 12:31:26 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Simon Oosthoek <s.oosthoek@student.utwente.nl>
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <Pine.GSO.3.96.970604122349.12995E-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, Simon Oosthoek wrote:
> The uppercase and the "/" for the "\" make no difference...
> This problem is so illogical, it looks more and more like a bug to me.
Maybe it is. But let's try a test to be sure. Does the output of this make
any sense? Hope this helps!
#!perl
@dirs = qw(d: d:/ d:/. d:/..
D: D:/ D:/. D:/.. ); # add or change as needed
for $dir (@dirs) {
print "Checking on '$dir'...\n";
unless (-d $dir) {
print " -d says false!\n\n";
next;
}
print " -d says true...\n";
unless (opendir DIR, $dir) {
print " but opendir can't open it: $!\n\n";
next;
}
print " and opendir can open it...\n";
@files = readdir(DIR);
$count = @files;
print " and it has $count items in it.\n\n";
closedir DIR;
}
-- 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: Wed, 4 Jun 1997 18:20:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Introductory Comparison of Perl and Python
Message-Id: <EB9K9z.9p5@nonexistent.com>
On Wed, 4 Jun 1997 11:26:07 +0200, Dominic Dunlop (domo@tcp.ip.lu) wrote in
comp.lang.python,comp.lang.perl.misc
<URL: news:19970604112607501983@dialup20.ip.lu>:
++ Tom Christiansen <tchrist@mox.perl.com> wrote:
++
++ > In comp.lang.python,
++ > tjreedy@udel.edu (Terry Reedy) writes:
++ > :This article compares basic features of Perl (4.x) and Python (1.4) by
++ > :means
++ > :of side-by-side code examples followed by minimal commentary.
++ >
++ > That's not very useful -- v4 Perl is six or seven years out of date.
++ > You need to think about v5.
++
++ Well, as far as it goes, the comparison's valid. That's to say, the
++ features compared are all in perl4, are still in perl5, and, by and
++ large, are still considered the 'natural' way to do things in perl5.
++ (Or natural to those who don't try to program in one-liners, anyway.)
++ The Perl side of a fuller comparison would be based on edition 2 of the
++ camel book, rather than on the llama book. But I think an adequate way
++ of meeting Tom's criticism is quickly to check the tables against the
++ camel book, discover that little needs changing, and then revise the
++ article prologue to say
Well, it seems you needed quite a lot of changes. I wanted to reply
to the first article too, but Tom beat me to it.
++ > name = stdin.readline()[:-1] $name = <STDIN>; chop($name);
++
++ Those of a one-line tendency would say chop($name = <STDIN>)
Or the safe version: chomp, which only chops a newline.
++ > # To avoid name collisions, both provide multiple name spaces
++ > - multiple modules and classes - flags for types of
++ > variables
++ > $name is a scaler (number/string)
++ ^
++ That's 'scalar'. Perl5 scalars can also hold references. References
++ are a key part of perl5's object-oriented features (although they can
++ also be used without all that OO stuff, should the programmer so wish).
Perl has modules/classes/packages/objects. And you are free to
use them. Or not.
++ > print 'Hello, '+name+'\n', print 'Hello, '.$name.'\n;
++
++ That should probably be print 'Hello, ' . $name . "\n";
Bleh. That should be: print "Hello $name\n"; Variable interpolation
is a not to be ignored feature of Perl.
++ > i=0; correct='?' # 0-based index $i = 0; $correct = '?'; # ditto
++ > while correct == '?': while ($correct eq '?') {
++ > if guess == words[i]: if ($guess eq $words[i])
++ > correct = 'y' {$correct = 'y';}
++ > elif i < 2: i = i+1 elsif ($i < 2) {$i = $i+1;}
++ > else: break else {last;}
++ > }
++
++ Perl's for(;;) is made for this sort of thing:
++
++ for ($i = 0, $correct = '?'; $i <= $#words; $i++) {
++ $correct = 'y', last if $guess eq $words[$i];
++ }
foreach (@words) {$correct = 'y', last if $guess eq $_;}
The for[each] [scalar variable] (list) {BLOCK}
construct is powerful, and often a lot easier than using index
variables.
++ > name = lower(name) # or, more general $name =~ tr/A-Z/a-z/; # lowercase it
++ > name = translate(name,maketrans(uppercase,lowercase))
tr/A-Z/a-z/; is bad because it doesn't take the current locale into
account. It won't do accented letters.
++ > return None or explicit expression return last expression evaluated
++
++ Perl, with return, can return an explicit value. There's no way to
++ return nothing, although, in perl5.004, functions can enquire whether
++ their caller is interested in getting a return value (that is, if the
++ return value is going to be used), and not waste time calculating
++ something meaningful if it's not.
It depends on what you mean by "nothing". return; returns undef or (),
depending on the context in which it was called.
Abigail
--
perl5.004 -wMMath::BigInt -e'$=new Math::BigInt+qq;$$783$[$%9889$47$|88768$596577669$%$5$3364$[$$$|838747$[8889739$%$|$673$%$98$76777$=56;;$=$]*(q.25..($=@))=>do{print+chr$%$;$/=$}while$!=$'
------------------------------
Date: Wed, 4 Jun 1997 11:48:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de>
Subject: Re: mount command in an suid script - howto ?
Message-Id: <Pine.GSO.3.96.970604113644.11389A-100000@kelly.teleport.com>
On 4 Jun 1997, Helmut Jarausch wrote:
> I tried to use
> system('/bin/mount ...');
> in a script that has been set root+suid (yes, I have suidperl)
>
> Still, I get the (system) error message
> mount: only root can do that.
> Probably the read UID is not root when mount is invoked. What did I
> miss?
Either your script isn't really being executed as setuid to root, or
you've done something that has dropped privileges. Try this sort of code
at your system call and see what it says.
@mount = qw(/bin/mount -v); # or whatever
print STDERR "About to try command @mount with uid $< and euid $>\n";
$status = system @mount;
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: Wed, 04 Jun 1997 13:34:34 -0600
From: John Call <johnc@interactive.ibm.com>
Subject: Re: Need help with PERL!
Message-Id: <3395C338.35D1@interactive.ibm.com>
There are different ways which may be more efficient depending on how
you want to search but here is one idea.
$searchword = lc($forminput{'searchword'});
open(IT,"filename");
@lines = <IT>;
close(IT);
foreach $line (@lines) {
if lc($line) =~ /$searchword/; {
print $line;
}
}
This is a rough out line of what you want to do. This should lower case
each line of input and compare it to a lowercased searchword and print
each line that contains that word.
Hope this helps,
John Call
------------------------------
Date: Wed, 4 Jun 1997 11:56:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Newbie question
Message-Id: <Pine.GSO.3.96.970604115059.11389B-100000@kelly.teleport.com>
On Tue, 3 Jun 1997, Andrew Johnson wrote:
> $nchars=pos if /$/g;
> or
> $nchars=s/(.)/$1/g;
Nice try, but inaccurate on some strings, like C<$foo = "ha\n" x 4;>.
> or perhaps an ugly regex approximation of a map{} in
> void context:
>
> s/(.)/!$`?$nchars=1:$nchars++;$1/eg;
That fails on the same ones, and also on ones which start with zero.
Don't try to re-write length(). It's too simple for these complex
attempts! :-)
-- 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: 4 Jun 1997 18:53:37 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Newbie question
Message-Id: <5n4djh$62s$2@dartvax.dartmouth.edu>
In article <339557FA.36C7@sweden.sun.com>
eliasm <Elias.Martenson@sweden.sun.com> writes:
> Andrew Johnson wrote:
> >
> > ! Bill Thompson wrote:
> > ! >
> > ! > To get the number of characters in a string, I'm
> > ! > using the following:
> > ! >
> > ! > sub ChkQID {
> > ! > my ($QID) = @_;
> > ! > my ($nchars, $i);
> > ! >
> > ! > $_ = $QID;
> > ! > $nchars = tr/\000-~//; # get the number of characters
> > ! >
> > ! > Is there a better way?
> > !
> > ! How about:
> > !
> > ! $nchars = scalar(split(//, $_));
> > !
> > ! ;-)
> > !
> > ! Chipmunk
> >
> > hmm
> > or even:
> >
> > $nchars=pos if /$/g;
> > or
> > $nchars=s/(.)/$1/g;
> >
> > or perhaps an ugly regex approximation of a map{} in
> > void context:
> >
> > s/(.)/!$`?$nchars=1:$nchars++;$1/eg;
> >
> > :-0
> >
> > (it would be nicer? if we could assume $nchars
> > was zero to start with: s/(.)/$nchars++;$1/eg; and
> > even a bit funky with a better choice of delimiter
> > s+(.)+$nchars\+\+;$1+eg;
> >
> > ;)
> > andrew
>
> Now, what is so wrong with the command "length"?
TMTOWTDI.
Obviously you're missing the point. ;-)
Chipmunk
------------------------------
Date: Wed, 4 Jun 1997 12:16:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: steven depuydt <steven.depuydt@wkb.be>
Subject: Re: newbie question
Message-Id: <Pine.GSO.3.96.970604120912.12995D-100000@kelly.teleport.com>
On Wed, 4 Jun 1997, steven depuydt wrote:
> Subject: newbie question
The real question is, "Have you seen the frequent posting about choosing
good subject lines?" They should be more meaningful than this; it doesn't
matter that you're a 'newbie', and of course you have a question! :-)
> Is there an easy way to open a text file, make changes to it and close
> the file?
Yes, that's what the -i command line option and the closely-related $^I
special variable are made to do.
> Is this a right way to do the job?
> open (FILE1,"c:/files/file1.txt");
> while (<FILE1>) {
> s/something/something else/g;
> push (@mylist,$_);
> }
> print "@mylist";
No. The main problems with that code are
1. it never checks that the file was successfully opened,
2. it needlessly loads the entire file into memory (in @mylist), and
3. it will indent every line after the first by one space.
Here's what I usually use for this sort of thing. It can be used on one or
more files. Any files which can't be opened are reported to the user by
Perl. For more information about what's going on here, see perlop(1) for
information about <> , and see perlvar(1) about $^I and @ARGV.
{
local($^I) = '.bak'; # Make backup file
local(@ARGV) = ('c:/files/file1.txt'); # files to edit
while (<>) {
s/something/something else/g;
print;
}
}
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: Wed, 4 Jun 1997 11:37:23 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: newbie question2
Message-Id: <3k54n5.sr8.ln@localhost>
steven depuydt (steven.depuydt@wkb.be) wrote:
: Is there a way to do this:
: open (SM,"test.txt");
: while(<SM>) {
: if (/picture ([0-9]{1,8})\.wmf/) {
: s/$1\.wmf/nice.gif/g;
: }
: }
: This piece of code doesn't work.
: I want to reuse the digits ([0-9]{1,8}) in my replecement rule.
: Is there a way to do this?
------------------------
#! /usr/bin/perl -w
$_ = "picture 1.wmf picture 10.wmf picture 12345678.wmf\n";
print "BEFORE: $_";
s/(picture )([0-9]{1,8})\.wmf/$1nice.gif/g;
print "AFTER: $_";
------------------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 04 Jun 1997 11:39:18 -0700
From: Jason Pociask <pociask@maricopa.edu>
Subject: open won't open files in subdirectories?
Message-Id: <3395B656.3997@maricopa.edu>
OK, I check dejanews and nothing there, so...
I have a perl script that I want to have walk a directory
and all subdirectories, opening each -Text file and searching
for lines that contain at least one instance of a search mask.
Works great--but only for the current directory. The Find::File::name
is definitely traversing all the subdirectories and their files,
but the "open(INFL,$n)" command is die'ing as soon as it tried to
open a file in a subdir, suchas as "./subdirA/fileA" or "subdirA/fileA".
All the files and dirs are chmod'd 777 at this point :-( but
that didn't help.
Any ideas? How can I traverse down the subdirectory chain as
the Find::File works its magic but be able to open the files
in the subdirectories (assume no Sym Links for simplicity's sake).
Thanks - Jason script follows:
#!/usr/local/bin/perl
# findtext.pl Prints indented directories, filenames for files foo
# that contain the indicated search string
# Program will ignore Binary files as written, remove -T test to enable
them
#
# Params: [-i] searchstring [directory1] [directory2...] foo
#
# A comment below shows where you would add code to screen for only
# selected filenames. Adding command line parameters for filename
filter
# is possible but introduces additional complexity unless really
needed. foo
# Directory defaults to "." current directory if not supplied.
#
# example: findtext.pl make /home/foo /usr/users/code /myfiles
#
# This program walks a file tree and reports any Text type files which
# contain at least one instance of a particular string. If "-i" appears
# as a qualifier prior to the other command line params, it makes the
# text string comparison case insentive (ala grep -i).
#
# Written: 06/97 by Jason Pociask, Maricopa Community Colleges IT/S
#
use File::Find;
if (@ARGV[0] eq "-i") {
$casesw = "-i";
shift(@ARGV);
} else {
$casesw = "";
}
my $str = @ARGV[0];
shift(@ARGV);
if (@ARGV[0] == "") {
@ARGV[0] = ".";
}
print "Searching For: $casesw $str In paths: @ARGV\n";
find (\&wanted, @ARGV);
sub wanted {
my $n = $File::Find::name;
# $n =~ s#.*?/# #gs;
# $n .= "/" if -d;
$n = substr($n,2,255); # gets rid of leading "./" - dies either way.
if (-d) {
print "$n/\n";
}
if (-T) {
print "$n\n";
open(INFL,$n); # || die "Could not open input text file $n\n";
$ctr1 = 0;
$ctr2 = 0;
$lins = "";
while (<INFL>) {
$lin = $_;
$ctr1++;
# print "$n:$ctr1 $lin";
if ($casesw eq "-i") {
if ($lin =~ /$str/i) {
$lins .= "$ctr1: $lin";
# print "$n $ctr1 $_";
$ctr2++;
}
} else {
if ($lin =~ /$str/) {
$lins .= "$ctr1: $lin";
# print "$n $ctr1 $_";
$ctr2++;
}
}
}
close(INFL);
print "File: $n Hits: $ctr2\n";
print $lins;
}
}
Example output when it dies: (first is a subdir, file_uno a text file)
Searching For: -i foo In paths: .
/
first/
first/file_uno
Could not open input text file first/file_uno
fbs.dist.maricopa.edu>
If I comment out the "die", it runs but only finds "foo" in
files in the current (pwd) directory, although it prints out
the list of each subdirectory and file in the whole tree since
I have the debugging print statements on...
------------------------------
Date: 4 Jun 1997 19:00:06 GMT
From: simmonsl@smsndc.com
Subject: PERL assistance w/NT
Message-Id: <5n4dvm$2jp$1@bilbo.reference.com>
I have a task that could use automating. I have a directory
structure that I create for each user of a specific group. This
directory has several subdirectories, and the permissions within
are always the same. Obviously, there's not much to creating
the directories (by username), but how to assign permissions has
me stumped a bit.
I am using the Win32 version of PERL with the modules that I
downloaded from www.activeware.com. Anyone who has any ideas on this, please email me at simmonsl@smsndc.com or
los94@neosoft.com. Any help would be greatly appreciated.
--
Posted using Reference.COM http://www.reference.com
Browse, Search and Post Usenet and Mailing list Archive and Catalog.
InReference, Inc. accepts no responsibility for the content of this posting.
------------------------------
Date: Wed, 4 Jun 1997 12:08:08 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Christopher Greenup <christopher.greenup@nashville.com>
Subject: Re: printf padding ...
Message-Id: <Pine.GSO.3.96.970604120311.12995C-100000@kelly.teleport.com>
On 4 Jun 1997, Christopher Greenup wrote:
> There are several places where the format specifications for printf are
> detailed, including the sprintf section of the Camel Book, the printf
> man page, several C books, and some other Perl books, etc. However,
> format specifications are not what I'm looking for.
>
> All these resources say that strings will be padded with spaces unless
> the format specifier '0' is given, in which case they will be padded
> with '0's. They do not say, however, if it is possible to pad with
> something else, and if it is, how to do so.
They don't say whether it's possible to print numerals spelled out either.
And the reason is the same: It's much simpler to document only what _can_
be done. :-)
But it's easy to change the padding.
($foo = sprintf "%10d", $bar) =~ tr/ /#/; # Pad with hashes
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: Tue, 3 Jun 1997 11:19:06 GMT
From: crossd@gb.swissbank.com (Dave Cross)
Subject: Re: Read a file to $wholefile
Message-Id: <CROSSD.97Jun3121907@ln4d110swk.gb.swissbank.com>
In article <adelton.865018534@aisa.fi.muni.cz> adelton@fi.muni.cz (Honza Pazdziora) writes:
> Lauri Laakso <lauri@nettipaja.clinet.fi> writes:
>
> > Ho I can read whole $message.dat file to $wholefile, I am using it
> > when I send multiple emails.
>
> $/ = undef;
> open FILE, $message.dat or die "Error reading $message.dat: $!\n";
> $wholefile = <FILE>;
> close FILE;
>
> __END__
>
> should work just fine.
>
I don't think this works. <FILE> returns one line from a file in a list
context.
@wholefile = <FILE>
will put the whole file in the array @wholefile. If you really want it
in a scalar, you could do something using 'join'.
Dave...
--
Opinions are mine, not the company's - hell I don't think the
company even knows who I am.
Dave.Cross@gb.swissbank.com
------------------------------
Date: Wed, 4 Jun 1997 12:02:35 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ekin Sokmen <mai96lgo@rzaix340.rz.uni-leipzig.de>
Subject: Re: reading a file (html) from an other server
Message-Id: <Pine.GSO.3.96.970604120119.12995B-100000@kelly.teleport.com>
On Tue, 3 Jun 1997, Ekin Sokmen wrote:
> How can I reach a html file on an other server with perl (cgi)?
This is a FAQ. In fact, this Q is so FA that I've A it at least three
times in the last day and a half. :-)
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq9/
How_do_I_fetch_an_HTML_file_.html
-- 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: Wed, 4 Jun 1997 20:58:41 -0100
From: drheeder@bcs.co.za (Dirk Rheeder)
Subject: Returning a filehandle from a module
Message-Id: <MPG.dffd94921e56528989684@hermes.is.co.za>
I'm trying to write my own module to handle some basic file functions,
like locking etc.
My problem is trying to return a filehandle from the module, or to send
it one to return for me. Is it possible to do this ?
ie. I would like to use something like
$filehandle = &mymod->fopen("file.dat");
And then be able to read the file in the calling program something like
$first = <$filehandle>;
All the opening functions of the file and the locking should be handled
by $mymod->fopen(). I just don't know how to make it accept or return a
file handle. The alternative is to send it the filehandle in the form of
&mymod->fopen($filehandle,"file.dat");
Does anyone know how to do this ?
Thanks
Dirk Rheeder
drheeder@bcs.co.za
------------------------------
Date: Wed, 4 Jun 1997 18:24:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Segmentation fault from multiple mkdirs in Perl script - Help!
Message-Id: <EB9KHK.9uo@nonexistent.com>
On Wed, 04 Jun 1997 14:23:21 +0100, Bruno Prior (bruno@prior.ftech.co.uk)
wrote in comp.lang.perl.misc
<URL: news:33956C49.5D71@prior.ftech.co.uk>:
++ I have written a basic Perl(4) script
++
++ [use & problem]
++
++ Does anyone have any ideas?
Upgrade to perl 5.004. Perl 4 has been dead for eons.
Abigail
--
perl5.004 -wMMath::BigInt -e'$=new Math::BigInt+qq;$$783$[$%9889$47$|88768$596577669$%$5$3364$[$$$|838747$[8889739$%$|$673$%$98$76777$=56;;$=$]*(q.25..($=@))=>do{print+chr$%$;$/=$}while$!=$'
------------------------------
Date: 04 Jun 1997 11:53:49 -0700
From: Jeff Solomon <jsolomon@oneiron.stanford.edu>
Subject: using select() and Perl/NT
Message-Id: <w4dyb8qmc76.fsf@oneiron.i-have-a-misconfigured-system-so-shoot-me>
Hi all,
Has anyone tried using the 'select()' system call with Perl under
WinNT when one of the the file descriptors being selected is
actually a TCP socket?
Here is the code:
sub Mainloop {
my ($fd_set, $command);
vec($global_fds, fileno(STDIN), 1) = 1;
vec($global_fds, fileno($SOCKET), 1) = 1;
for( ;; ) {
#wait forever until you get something
select($fd_set = $global_fds, undef, undef, undef);
if( vec($fd_set, fileno(STDIN), 1) ) {
ProcessInputChar();
}
if( vec($fd_set, fileno($SOCKET), 1) ) {
RecvPacketFunc();
}
}
}
This code works fine under variants of unix (solaris, SGI), but
does not work properly under winNT.
Any suggestions?
thanks,
Jeff
--
***********************************************************************
Jeff Solomon Tel: (415) 725-3701
Computer Systems Lab Email: jsolomon@oneiron.stanford.edu
Stanford University
***********************************************************************
------------------------------
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 570
*************************************