[8924] in Perl-Users-Digest
Perl-Users Digest, Issue: 2542 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 8 16:08:16 1998
Date: Fri, 8 May 98 13:00:41 -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 Fri, 8 May 1998 Volume: 8 Number: 2542
Today's topics:
Re: "tail -f" emulation under Linux <jmscott@ainet.com>
Re: 2 columns, one blank, need to repeat col 1 in col 2 <danboo@negia.net>
a header for `Mail me copies' or `Do not mail me copies <Russell_Schulz@locutus.ofB.ORG>
Re: Better Sort? <jdf@pobox.com>
Re: Better Sort? <danboo@negia.net>
Re: Better Sort? (Andrew M. Langmead)
cross platform perl? (Drew W Weirshousky)
Re: dup2 and fork and exec <rootbeer@teleport.com>
Expanding arrays in strings nikitins@infoservriga.lv
Re: fixed width text files <aqumsieh@matrox.com>
flock is not <andrewf@cp.pathfinder.com>
Re: Grabbing a webpage with Perl <andy@interactive.net>
Re: HELP ON FILE LOCKING <brianm@kodak.com>
Re: Help! This is drivin me nuts <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Help... validate FTP links? (Jocke...)
Re: how to create name for temporary file (Andrew M. Langmead)
Re: how to create name for temporary file (Andrew M. Langmead)
Re: Indexing directory's on server <rootbeer@teleport.com>
LotusNotesSQL Driver for Perl <dougw@webworks.ca>
Re: Multiline substitution from command line in Perl 4. (Andrew M. Langmead)
Re: Multiline substitution from command line in Perl 4. <rootbeer@teleport.com>
outputting ufsdump frost@avanticorp.com
Perl 5.005 schedule update????? <david_ransier@intercept.com>
Re: PErl Functions <andrewf@cp.pathfinder.com>
Re: PErl Functions <brackett@pobox.com>
Re: PErl Functions <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Perl NT IIS PWD <jbattikha@highsynth.com>
Re: perl scripts dealing with /etc/passwd <rootbeer@teleport.com>
Re: perl scripts dealing with /etc/passwd <rootbeer@teleport.com>
Re: perl win32 - newbie help <andrewf@cp.pathfinder.com>
Re: Please Help ! <rootbeer@teleport.com>
Re: Problem with xemacs and perl syntax hilitghtning (Gerd Schering)
Re: Q: Missing Last Character <aqumsieh@matrox.com>
Re: QRe: == vs. eq (John Moreno)
Re: Strange problem. <andrewf@cp.pathfinder.com>
Re: Symbolic References <akushner@lebeaux.cup.hp.com>
Re: Tip: Hash Slices <gnat@frii.com>
Using split to return a @ without splitting on spaces <tech@BMEi.on.ca>
Re: WIN32 tee command (Craig Berry)
Re: Windows 95 Problem <bobras@erols.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 08 May 1998 11:00:28 -0700
From: "Joseph M. Scott" <jmscott@ainet.com>
To: John Ackermann <jra@febo.com>
Subject: Re: "tail -f" emulation under Linux
Message-Id: <3553483C.2974@ainet.com>
I was looking for something like this ( on FreeBSD ), and came across a
couple of different things. There is a perl module that can be found at
:
http://www.chocobo.org/~tgy/perl/IO-Tail.html
I didn't open to go that route, but it does seem to work from the little
bit that I tried it out. I went with some thing more like :
require 'open2.pl';
$input = '/usr/bin/tail -f somefile';
&open2('WATCH', 'write_fh', $input) or die("$0: Unable to open
$input\n$!\n");
while(defined($line = <WATCH>)) {
# do what ever
}
Anyway, I think you get the idea. I would assume this would work fine
under Linux.
Joseph Scott
jmscott@ainet.com
John Ackermann wrote:
>
> Hi --
>
> I've read the FAQ and tried the three methods shown there to "tail -f" a
> file in perl (5.003_07 ) under Linux, but none of them seem to work --
> all dump the existing contents of the file, but don't remain open.
>
> Could some kind soul provide a code fragment showing how to do this
> under Linux? My goal is to have a pair of processes, one of which
> writes to a spool file on disk, the other of which is a server run from
> inetd that dumps the contents of the file to a remote host and keeps
> sending data as it is appended by the other process. I've got the
> network stuff working (more or less... I'm posting another question on
> that), and the real barrier is just getting the following tail to work.
>
> Thanks,
>
> John Ackermann
> jra@febo.com
> http://www.febo.com
------------------------------
Date: Fri, 08 May 1998 12:45:46 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: 2 columns, one blank, need to repeat col 1 in col 2
Message-Id: <355336BA.3802D45D@negia.net>
Mike Hammernik wrote:
>
> I have a fike that started iut looking like
>
> ----------------------------------------------
> | 216453 | |
> -----------------------------------------------
> | 219405 | 219406 |
> -----------------------------------------------
> | 219410 | |
> -----------------------------------------------
> | 219697 | |
> -----------------------------------------------
> | 315414 | 315418 |
> -----------------------------------------------
> Now I nee to duplicate column 1 in column 2 if it is empty. But I want
> to leave the line alone if it has two columns.
>
> 216453|216453
> 219405|219406
> 219410|219410
> 219697|219697
> 315414|315410
>
well i've got two versions for you. a one-liner i did for fun that i
would not recommend for large files, and a more practical 'while'
approach. i made the assumption that the second string of digits
would never be '0'. if it can be then you can change ($2 || $1) to
(defined $2 ? $2 : $1).
practical:
the basic idea is to iterate through the data, line by line, seeing
if a line contains a string of digits. if so use the && operator to
perform a task. in this case the task is to create a string comprised
of the first string of digits followed by a |, followed by our second
string of digits if true. if the second string of digits is not true,
use the first string again. this string is then pushed onto our array
of pairs.
while (<DATA>) {
/(\d+)\D+(\d+)?/ && push @pairs, "$1|" . ($2 || $1);
}
one-liner:
here, we read the entire file into a list and then pass it through
a filter implemented with grep. since grep returns only the list
elements that return true for our designated operation, those list
elements (or lines), that don't perform the specified substitution
get dropped. the basic idea of the substitution is to replace the
entire string with with the first string of digits, a |, and the
second string of digits if true. otherwise use the first string
again. so we're not just filtering, we're modifying as well.
@pairs = grep s/\D+(\d+)\D+(\d+)?.+/"$1|" . ($2 || $1)/se, <DATA>;
ahh, just thought of a shorter 'map' version as well. this one i'll
leave as an exercise to dissect. it's kind of a cross between the
first two.
@pairs = map /(\d+)\D+(\d+)?/ ? "$1|" . ($2 || $1) : (), <DATA>;
cheers,
--
Dan Boorstein home: danboo@negia.net work: danboo@y-dna.com
"THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
- Cosmic AC
------------------------------
Date: Fri, 8 May 1998 16:51:51 +0100
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: a header for `Mail me copies' or `Do not mail me copies' (was Re: Ever Wonder Why Not Everyone Uses Modules?)
Message-Id: <19980508.165151.1F2.rnr.w164w_-_@locutus.ofB.ORG>
why was this in comp.lang.perl?
why was this Subject: header totally wrong?
why does Gary still post with that PC-specific barcode sig
even after I've pointed this out in mail (and he's been
annoyed at me for doing so, so I know he's seen it)?
Gary L. Burnore <gburnore@netcom.com> writes:
> Emailing when posting is oine of the rudest things you can do.
one of the billion most; definitely not one of the ten most. or thousand.
> It IS like being spammed "or something". If you email, don't
> post. If you post, don't email.
ah, to live in a world where news never gets lost.
> Unless of course it's REQUESTED of you.
the `Mail-Copies-To: never' header explicitly advises
actively-maintained newsreaders to NOT mail the copies; the
`Mail-Copies-To: always' advises (up to the user, of course)
to do so.
not using the header at all leaves the decision to the whims of
others, outcomes from both of which being popular -- and thus
ultimately to disappointment.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: 08 May 1998 14:46:06 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: snowbird <snowbird@pcisys.net>
Subject: Re: Better Sort?
Message-Id: <btt8v94x.fsf@mailhost.panix.com>
snowbird <snowbird@pcisys.net> writes:
> A list of:
> PHSS_9928 PHSS_10234 PHSS_1133 PHCO_3234 PHCO_11011 PHKL_8872
> would sort as:
> PHCO_3234 PHCO_11011 PHKL_8872 PHSS_1133 PHSS_9928 PHSS_10234
>
> Breaking the patch names into a tmp hash and then performing the sort is
> the only way that I can get this to work, can it be done with one sort {
> BLOCK } withou the hash? for ( sort { BLOCK } @arr ) { .....
This is the aim of the often-invoked and rarely-understood Schwartzian
transform. You are directed to
http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html
my @sorted =
map { $_->[2] }
sort { $a->[0] cmp $b->[0] or $a->[1] <=> $b->[1] }
map { /^([A-Z]+)_(\d+)$/; [$1, $2, $_] }
@unsorted;
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: Fri, 08 May 1998 15:41:36 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Better Sort?
Message-Id: <35535FF0.74674DA5@negia.net>
snowbird wrote:
>
> Is there a way to perform the sort below without having to use the tmp
> hash?
>
> I have an array of patch names that I would like to sort, first by the
> alpha identifier and then the numeric identifier.
> A list of:
> PHSS_9928 PHSS_10234 PHSS_1133 PHCO_3234 PHCO_11011 PHKL_8872
> would sort as:
> PHCO_3234 PHCO_11011 PHKL_8872 PHSS_1133 PHSS_9928 PHSS_10234
>
> Breaking the patch names into a tmp hash and then performing the sort is
> the only way that I can get this to work, can it be done with one sort {
> BLOCK } withou the hash? for ( sort { BLOCK } @arr ) { .....
>
how about this?
@arr = qw(PHCO_3234 PHCO_11011 PHKL_8872 PHSS_1133 PHSS_9928 PHSS_10234);
print map { $_->[0], "\n" }
sort { $a->[1] cmp $b->[1] or $a->[2] <=> $b->[2] }
map { [$_, split /_/] }
@arr;
--
Dan Boorstein home: danboo@negia.net work: danboo@y-dna.com
"THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
- Cosmic AC
------------------------------
Date: Fri, 8 May 1998 19:37:02 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Better Sort?
Message-Id: <EsnL5q.3t8@world.std.com>
snowbird <snowbird@pcisys.net> writes:
>Is there a way to perform the sort below without having to use the tmp
>hash?
You can hide the extra list or has by using the Scwartzian Transform,
but it still exists.
print map { "$_->[2]\n" } # return an list based on...
sort { $a->[0] cmp $b->[0] or $a->[1] <=> $b->[1] } # the sorted fields
map { [ m/(PH...)(\d+)/, $_ ] } @arr; # extracted from the re
If you want the increased speed of calculating the fields once, you
need to deal with the tradeoff of the increased memory used to hold
the results of calculations.
--
Andrew Langmead
------------------------------
Date: 8 May 98 18:11:56 GMT
From: dweirsho@ic.sunsyb.edu (Drew W Weirshousky)
Subject: cross platform perl?
Message-Id: <35534aec.0@news.ic.sunysb.edu>
------------------------------
Date: Fri, 08 May 1998 19:07:36 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: indhiraa@hotmail.com
Subject: Re: dup2 and fork and exec
Message-Id: <Pine.GSO.3.96.980508115807.20271C-100000@user2.teleport.com>
On Fri, 8 May 1998 indhiraa@hotmail.com wrote:
> What will be the status of STDOUT and STDERR when i do fork and
> then exec another program. In the program I exec where will the
> STDOUT be directed to.
A fork shouldn't affect filehandles. But some filehandles may be set to
close upon exec. Normally, that won't include the "big three", STDIN,
STDOUT, and STDERR, though. Typically, you'll have the child process close
or open any necessary filehandles before the exec. See your system's docs
for fork and exec, and perl's docs for the magical $^F variable. Hope this
helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 08 May 1998 18:55:42 GMT
From: nikitins@infoservriga.lv
Subject: Expanding arrays in strings
Message-Id: <6ivkfe$ljp$1@nnrp1.dejanews.com>
Hello PERL experts,
PERL FAQ describes the situation when expanding single variables.
$text = 'this has a $foo in it and a $bar';
$text =~ s/\$(\w+)/${$1}/g;
I need to have
$text = 'this has a $foo[$bar] in it';
or even simplier
$text = 'this has a $foo[2] in it';
Please do not kick me for ignorance. This regular expression is the only
thing I need to complete a large and important PERL programm.
Thank you so much for dropping me a line of code!
Regards,
Mihails Nikitins
--------------------------------
|A code! My kingdom for a code!|
--------------------------------
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Fri, 08 May 1998 13:43:21 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: fixed width text files
Message-Id: <35534439.4BB3BA07@matrox.com>
Eric Wong wrote:
> Jeff <jeffmcc@mindspring.com> wrote:
> : I have a text file with approximately 400 rows. Each row has 31
> : columns, and each column has a different width. I'm a newbie so if
> : this elementary question frustrates anyone I apologize. But, how can
> : I read from this file and set the width for each individual column so
> : I can reference them?
>
> I assume that when you say "each column has a different width",
> you mean a different width between the columns, not between rows.
> (i.e. the first column is always 5 chars, the second is 6, etc.)
>
> If I understand your question correctly, you might try something
> like this:
>
> open(F, $filename) || die "Can't open $filename";
> while $line (<F>) {
> @data = $line =~ /(.{5})(.{6}) ... /;
> }
I would use split() ... but that's only me!!
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Fri, 8 May 1998 14:16:49 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: flock is not
Message-Id: <Pine.GSO.3.95.980508135725.29060B-100000@cp.pathfinder.com>
perl -v gives me
This is perl, version 5.002
The following script dies :
#!/usr/local/bin/perl
$LOCK_EX = 2;
$LOCK_UN = 8;
&read_data("foobar.txt");
print "Done!\n";
sub read_data {
my $file = shift;
open(DATA, $file) or die $!;
flock(DATA, $LOCK_EX) or die $!;
while(<DATA>) {
if(/^\s*SECTION:\s*(\w+)/) {
$section = $1;
}
}
flock(DATA, $LOCK_UN) or die $!;
close(DATA) or die $!;
}
with error "Bad file number at ./Example.pl line 9."
The permissions on foobar.txt are rw-rw-rw-
I did not build this Perl, but we are using gcc ver. 2.7.2 ...
hmmmmmmmmmmm??????
Am I missing something???
TIA
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: 8 May 1998 15:31:34 +0400
From: Andy Murren <andy@interactive.net>
Subject: Re: Grabbing a webpage with Perl
Message-Id: <35535d96.0@208.192.224.3>
In comp.lang.perl.misc brian d foy <comdog@computerdog.com> wrote:
> >Chris: if garbbing a simple web page is all you need, you could
I have a script at
http://www.murren.org/andy/programs/getpage/tahoe.txt
This grabs the National Weather Service page that has the weather for
NV and emails it to me. The script also parses out just the Lake
Tahoe weather before mailing it, but that is more than you need.
--
Andy Murren andy@murren.org
------------------------------
Date: Fri, 08 May 1998 15:13:49 -0400
From: Brian Mathis <brianm@kodak.com>
To: DAVID CHEW <dcc1234@pacific.net.sg>
Subject: Re: HELP ON FILE LOCKING
Message-Id: <3553596D.2201228C@kodak.com>
[posted and emailed]
DAVID CHEW wrote:
>
> Anyone can help on this:
> If A is writing on a fileX, and locks the fileX
> and someone else B starts reading the fileX,
> Would B be able to read fileX correctly if fileX is locked for writing by
> A.
> Should B test for locking before reading fileX?
> THANKS
> DAVID
If you are locking files, you need to make sure that all of the programs
that need to use that file check for file locking.
Brian Mathis
------------------------------
Date: Fri, 8 May 1998 20:14:45 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Help! This is drivin me nuts
Message-Id: <6ivlk4$nqn$1@plug.news.pipex.net>
>cgi-lib.pl: Unknown Content-type:
>[Thu May 7 21:52:19 1998] lingering close lost connection to client
>207.141.176.82
Silly question time, perhaps... you ARE putting in a
print( "Content-Type: text/html\n\n" );
to tell the browser what it's getting, aren't you?
------------------------------
Date: Fri, 08 May 1998 18:34:49 GMT
From: m-39772@mailbox.swipnet.se (Jocke...)
Subject: Re: Help... validate FTP links?
Message-Id: <35534ee2.4222661@nntpserver.swip.net>
On Thu, 7 May 1998 12:08:54 -0700, "matthew d. p. k. lanier"
<lanier@shell6.ba.best.com> wrote:
[8<]
>if they are links to other machines, i might take a look the libwww module
>available on cpan. methods for just about every conceivable type of net
>communication are there, including ftp.
Yes, it's links to other machines...
Well... I downloaded the libwww module, but as a newbie to this, I
don't understand anything... ;-)
>good luck!
Thanks!
//jocke...
------------------------------
Date: Fri, 8 May 1998 19:01:14 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: how to create name for temporary file
Message-Id: <EsnJI3.17y@world.std.com>
root.noharvest.\@not_even\here.com (-) writes:
>This sounds unnecessary. This is the reason Microsoft succeeds in the
>computer business - people are indecisive and can't make decisions on
>their own, they need someone (or something) else to do it for them.
Although, I do agree that there are some problems using POSIX.pm for a
quick running script, I don't think that it is a good idea for
everyone to invent their own temp file naming convention.
If everyone who writes software that runs on a system uses the same
naming convention, there will be no clashes between them, if everyone
invents their own, whose to say that everyone will choose methods that
will not conflict with each other. (or that their convention is as
unique as they expect it to be, more on that later)
>Just use $$ or some variant. Make up your own temporary file, it's
>not that hard. You don't need someone else to do it for you.
>Here........
>srand($$^TIME);
>$num = int(rand(1000);
>$tempfile = $num * $$;
>$tempfile .= ".tmp";
Since you base the temp file on a random number, even if you seed it
with the process ID , you invite clashes. And did you mean to seed it
with the process ID exclusive or'ed with a bareword? or is that just a
bug. Do people really want their tempfile naming convention to have
bugs? (If you seed the random number generator with the process ID and
a constant, and then using the first random number multiplied by the
process ID, you are using a fixed calculation based on the process
ID. If you meant that to be time(), then conflicts are more likely.)
Why use the random number at all? You are just making conflicts harder
to spot, not fixing them. What if your calculation matches another
programs process ID and they use that as the temp file name. What if
another appends a random number and the processes ID and that matches
your string?
--
Andrew Langmead
------------------------------
Date: Fri, 8 May 1998 19:04:29 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: how to create name for temporary file
Message-Id: <EsnJnH.35t@world.std.com>
Ala Qumsieh <aqumsieh@matrox.com> writes:
>Why bother? A file is as temporary as you want it to be!
>Just create a file (I would call it MYFILE.TEMP or whatever),
>do whatever you wanna do with it, then unlink() it!
What if two copies of your process are run (nearly) simultaneously?
And if you are going to unlink() it, (and you are running on a Unix
box) why not unlink() just after you have opened it, rather than
waiting until done. You then still have access to the file, (the disk
space is not reclaimed until the last proces closes it.)
--
Andrew Langmead
------------------------------
Date: Fri, 08 May 1998 19:31:03 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Twan Jansen <twan.jc.jansen@tip.nl>
Subject: Re: Indexing directory's on server
Message-Id: <Pine.GSO.3.96.980508122936.20271F-100000@user2.teleport.com>
On 8 May 1998, Twan Jansen wrote:
> Is there a way that i can get the titles of my Html pages in the
> directory and show in a html page with can been seen by everybody.
Probably, if you write a Perl script to do this. There are some modules
which may be useful in (for example) parsing the HTML to extract the
titles. If you get stuck, let us know how far you've gotten. Hope this
helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 08 May 1998 19:39:49 GMT
From: "Doug Wilson" <dougw@webworks.ca>
Subject: LotusNotesSQL Driver for Perl
Message-Id: <01bd7ab9$472b4b40$2f01010a@dougwilson>
I am having problems connecting to a notes database with perl using the
LotusNotesSQL ODBC driver. Here is a code snippet:
$Data_source = "DSN=someDSNname;Database=help4.nsf;Server=local";
$DB = &openODBCPipe($Data_source);
$DB->Close();
exit();
sub openODBCPipe {
my($Data_source) = @_;
my($Db_pipe);
if (! ($Db_pipe = new Win32::ODBC($Data_source))) {
exit();
}
return $Db_pipe;
}
When I run this from the command line it will run successfully several
times, and then hang. Does anyone have any exepreince using perl to connect
to a Notes database on a Domino server?
Thx,
Doug
------------------------------
Date: Fri, 8 May 1998 19:47:23 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Multiline substitution from command line in Perl 4. How?
Message-Id: <EsnLn8.Ap0@world.std.com>
Rich Reardon <reardon@maroon.tc.umn.edu> writes:
>Using Perl 4 from the command line, if I write...
>perl -pi.bak -e "s/line\nand/replacestring/;" target.txt
>it will not find the pattern, yet...
Remember that the -p switch is roughly equivalent to the loop
while(<>) {
# something
}
continue {
print;
}
and the the <> operator reads a line up until the first newline (by
default. It can be changed with the $/ varialbe or the -0 command line
switch.) There is never a single line that matches "line\nand".
Are the file small enough to slurp into memory at once?
perl -0777 -pi.bak -e 's/line\nand/replacestring/' target.txt
If not, will paragraph mode work?
perl -00 -pi.bak -e 's/line\nand/replacestring/' target.txt
The $* variable, or the /m modifier have no effect here. They only
change how the "." metacharacter is handled.
have you seen the FAQ entry "I'm having trouble matching over more
than one line. What's wrong?" <URL:http://www.perl.com//CPAN/doc/
manual/html/pod/perlfaq6/I_m_having_trouble_matching_over.html>
--
Andrew Langmead
------------------------------
Date: Fri, 08 May 1998 19:53:47 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Rich Reardon <reardon@maroon.tc.umn.edu>
Subject: Re: Multiline substitution from command line in Perl 4. How?
Message-Id: <Pine.GSO.3.96.980508124932.20271J-100000@user2.teleport.com>
On 8 May 1998, Rich Reardon wrote:
> Say I have the following lines in a text file:
>
> Here is one line
> and yet another.
>
> Using Perl 4
You should upgrade your system administrator to one who is able to install
software.
> from the command line, if I write...
> perl -pi.bak -e "s/line\nand/replacestring/;" target.txt
> it will not find the pattern, yet...
Certainly not; you're looking at one line at a time, so a pattern which
spans two lines won't be in there.
> perl -pi.bak -e "s/line\n/replacestring/;" target.txt
> WILL find the pattern and replace it.
Right; the newline is at the end of the line, so you can find that.
> In my Perl 4 files, I use $*=1, but I don't think I can add that to the
> command line code, and because it's Perl 4, I don't have the "m"
> (multiline) argument.
> Am I up the perly creek?
You may be able to use command-line arguments to read more than one line
at a time. I'm not in the mood to dig up my old Perl 4 docs to find out,
but it should be possible. I know it's possible with Perl 5, though. :-)
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 08 May 1998 19:06:50 GMT
From: frost@avanticorp.com
Subject: outputting ufsdump
Message-Id: <6ivl4a$mbj$1@nnrp1.dejanews.com>
I have written a perl script which schedules ufsdumps for multiple
workstations. As part of the script, I wish to capture the output of
ufsdump. Currently I am trying to do this (in abbreviated form):
open(STDOUT,"> foo.txt);
print system "/usr/ucb/rsh hostname ufsdump 0ubf 512 backup_host:/dev/rmt/0
/usr1","\n";
close STDOUT;
This works for all other Unix commands I have tried, such as tar, ls, etc.;
however, the output from ufsdump does not get directed to the output file.
The only way I have gotten around this is by creating a one-line shell script
which calls '"/usr/ucb/rsh hostname ufsdump 0ubf 512 backup_host:/dev/rmt/0
/usr1" >> foo.txt' and calling that script from inside of perl.
Any suggestions on how I can capture the ufsdump output without calling the
external shell script?
Thanks in advance,
Dave Horowitz
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Fri, 8 May 1998 12:04:50 -0700
From: "David M. Ransier" <david_ransier@intercept.com>
Subject: Perl 5.005 schedule update?????
Message-Id: <6ivl2m$sen$1@usenet1.interramp.com>
I haven't seen anything new on the next major release of Perl (5.005).
Any new news on the schedule?
I am anxious for the "supported" Perl/Tk release for NT and the Perl
compiler stuff I was hearing about last fall.
Thanks,
David R
-----------------------------------
David M. Ransier
Senior Consultant
Intercept Technology Inc.
David_Ransier@Intercept.com
503-692-0111 www.intercept.com
503-691-9535 - Fax
404-352-0111 - ITI Headquarters
------------------------------
Date: Fri, 8 May 1998 14:57:47 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: PErl Functions
Message-Id: <Pine.GSO.3.95.980508145707.29060E-100000@cp.pathfinder.com>
On 3 May 1998, Tom Christiansen wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, doitboo@innocent.com writes:
> :what does the Perl built in function "die" do? and what is the snytax and
> :synopsis for this function
>
> USENET is not here to read you bedtime manpages. See perlfunc.
>
> --tom
> --
> Tom Christiansen tchrist@jhereg.perl.com
> str->str_pok |= SP_FBM; /* deep magic */
> s = (unsigned char*)(str->str_ptr); /* deeper magic */
> --Larry Wall in util.c from the perl source code
>
>
Follow up:
What is perlfunc and what are the arguments to it?
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Fri, 08 May 1998 19:02:09 GMT
From: "Brackett Omensetter" <brackett@pobox.com>
Subject: Re: PErl Functions
Message-Id: <REI41.12$g9.164096@news.san.rr.com>
Andrew F. Lee wrote in message ...
>What is perlfunc and what are the arguments to it?
Are you trying to be funny, or are you just obtuse? Perlfunc is a doc page
from the Perl faq. You have it on your drive if you have Perl installed
i.e., perdoc perfunc
B.
------------------------------
Date: Fri, 8 May 1998 20:06:47 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: PErl Functions
Message-Id: <6ivl54$n44$1@plug.news.pipex.net>
>Are you trying to be funny, or are you just obtuse? Perlfunc is a doc page
>from the Perl faq. You have it on your drive if you have Perl installed
>i.e., perdoc perfunc
He was being funny. SURELY no-one could be that obtuse :)
------------------------------
Date: Fri, 08 May 1998 14:31:41 -0400
From: Jihad Battikha <jbattikha@highsynth.com>
Subject: Re: Perl NT IIS PWD
Message-Id: <35534F8D.770B6FDC@highsynth.com>
Lars Nap wrote:
> Normally when I'm executing a Perl script on a Unix machine (and a
> Netscape webserer) the path working directory (PWD) is the same as the
> directory of the perl script.
> When I'm executing a perl script on NT and IIS the PWD is not the same
> as the directory of the perl script.
> Does anyone know how to be sure that the PWD is the same as the
> directory of the perl script!
A workaround:
if($0=~/.*\\/){$pwd=$&}
OR
$pwd=$&if($0=~/.*\\/);
works for me...
~jihad
--
<>>>===========================================================<<<>
Jihad Battikha <jbattikha@highsynth.com> http://www.highsynth.com
-=< graphics . 2d/3d animation . illustration . web authoring >=-
-----------------------------------------------------------------
PGP: http://www.highsynth.com/jihad/pgp.htm
- fingerprint: 9B5E 0484 0D88 6454 380B 964D E9B7 7A58 15C0 CAD7
- expires: 1/1/1999
<>>>===========================================================<<<>
Before sending me commercial e-mail, the sender must first agree
to my LEGAL NOTICE located at: http://www.highsynth.com/sig.html.
<>>>===========================================================<<<>
------------------------------
Date: Fri, 08 May 1998 19:26:35 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Harry Rowe <hrowe@erinet.com>
Subject: Re: perl scripts dealing with /etc/passwd
Message-Id: <Pine.GSO.3.96.980508121823.20271D-100000@user2.teleport.com>
On Fri, 8 May 1998, Harry Rowe wrote:
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $contents{$name} = $value;
> }
>
> It works fine. Why would this be broken?
It doesn't follow the CGI specification, which means that it may fail in
some situations. In other words, it merely pretends to be doing the right
thing. But in some situations, it does the wrong thing.
One obvious situation where this code fails is if your form has a
"multi-select" item, in which the user may select more than a single item
at a time. But don't anyone say "it's okay, because my forms don't do
that", because that's not the only way in which this code fails.
It's not hard to fix this code to follow the specs, but why bother? There
are good modules out there, ones which are easy to use, ones which do this
for you by using code that's been debugged for your convenience.
As my pal Randal says, "Don't try to re-invent the wheel; sometimes you
end up with casters." :-)
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 08 May 1998 19:41:28 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: perl scripts dealing with /etc/passwd
Message-Id: <Pine.GSO.3.96.980508123112.20271G-100000@user2.teleport.com>
On 8 May 1998, Allan M. Due wrote:
> Is it the code that you quoted above that does not agree with the CGI
> specification , or was it code further on in the script?
That script's method of parsing the CGI parameters, which I didn't quote,
was the part that I saw violated the spec.
> Could you point me to a reference that outlines the CGI specifications?
Sure, but why? :-) Surely you don't want to implement it yourself, when
there are already good modules to do so? But here it is:
http://hoohoo.ncsa.uiuc.edu/cgi/
http://hoohoo.ncsa.uiuc.edu/cgi/interface.html
> Any idea on how likely it is that the environment variable might be set
> incorrectly?
Servers aren't likely to set it incorrectly, but your script may be called
by (say) a buggy test harness. Not that this is too likely, but why take
chances?
> Your argument for the use of modules is well made. On the other hand I
> think it is also important to understand how code is correctly written
> in order to make informed decisions about the use of modules.
True enough. That's one reason why every module on CPAN comes with
complete source code. If you (for whatever reason) don't wish to use the
module directly, you can build your own code (or module!) from the source
code given.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 8 May 1998 15:11:07 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: perl win32 - newbie help
Message-Id: <Pine.GSO.3.95.980508151011.29060F-100000@cp.pathfinder.com>
On 4 May 1998, DAVID CHEW wrote:
> hi,
> How do I call/run/execute the programs created
> on perl win32 ?
>
> Can I execute it from nescape itself
> I mean, like as though I on the internet,
> and my local computer acting as a server.
>
> As I dont regularly visit this newsgroup
> Would appreciate if replies goes direct to
> my email dcc1234@pacific.net.sg
>
Type ALT+f4 and you're flying ...
(God help me, I have been on c.l.p.m too long!)
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Fri, 08 May 1998 19:44:12 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: frederic <fredjoua@club-internet.fr>
Subject: Re: Please Help !
Message-Id: <Pine.GSO.3.96.980508124319.20271H-100000@user2.teleport.com>
On Fri, 8 May 1998, frederic wrote:
> Subject: Please Help !
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> Could anyone tell me where I can find a step by step guide that explains
> to a simple mind guy how tu use the scripts that are available on the
> web ?
> I'm especially completely lost with the instruction : chmod 755 ...
Ask your librarian to direct you to a good introductory book on Unix. Hope
this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 8 May 1998 19:32:57 GMT
From: gerd4000@mailszrz.zrz.TU-Berlin.DE (Gerd Schering)
Subject: Re: Problem with xemacs and perl syntax hilitghtning
Message-Id: <6ivml9$1lh$2@hermes.uhland.de>
In article <355301EF.E14F4C00@cetrel.lu>,
Denis DORR <dorr@cetrel.lu> writes:
>> I think many of you use (x)emacs as develloping environment, as do I.
>> Now I upgraded my old xemacs to the new 20.4.
>
> Is it very different from 19.34 ?
At my opinion not, but shurely the xemacs communnity has a different
viewpoint :-).
There are more configuration options available directly from the menu bar,
i.e. I could convince the delete key to delete the character under the
cursor without altering my .emacs. (But of course it's still there, where
this information gets stored.) So if you feel comfortable with the old
19.34 - from the Perl programming viewpoint, keep it.
>> When editing a "*.pl" file (cperl-mode get's autoloaded), perl words
>>
>> [...]
>
> I think this is done in perl-mode.el.
That's exactly where things happen. Calle Dybedahl - thanks Calle - gave
me the right hint with "M-x list-faces-display".
So I changed some entries in cperl-mode.el - I'm not shure I know what I
really did - but now it works fine.
Thanks,
Gerd
------------------------------
Date: Fri, 08 May 1998 14:11:27 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Q: Missing Last Character
Message-Id: <35534ACF.145333B9@matrox.com>
Simon Steele wrote:
[snip]
> The script parses a file called 'credits.dat' which has one piece of
> data per line:
>
> SECTION!Section 1
> PERSON!Credit 1
> PERSON!Credit 2
>
> The script returns HTML with any line beginning in SECTION as a
> section header, and any other line as a credit. The problem is that
> the script always misses the last character from the file:
>
> Section1
> ========
> Credit 1
> Credit
>
> Where the last line should read:
>
> Credit 2
>
> Please can you help me see what I've done wrong, the Perl script is:
>
> #!/usr/local/bin/perl -w
[snip]
> foreach (@lines) {
> chop;
You problem is with this chop! Apparently, the last line of your file
does not contain a line feed character (check your file!) Your file
probably ends just after the Credit 2 line. Thus, the chop is removing
the last character of your string, which is the 2.
There are two solutions:
1. Insert that missing \n .. which will then be removed by the chop
(redundant).
or
2. Use chomp() which is just like chop (in your context, since you don't
care about its return value) except that it only chops a \n from the end
of the line if there is one to chop.
Enjoy,
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Fri, 08 May 1998 18:40:56 GMT
From: phenix@interpath.com (John Moreno)
Subject: Re: QRe: == vs. eq
Message-Id: <1d8psbn.8wyodk10e6mp2N@roxboro0-034.dyn.interpath.net>
Aaron Baugher <abaugher@rnet.com> wrote:
> "Allan M. Due" <due@discovernet.net> writes:
>
> > Any suggestions for "real newsreaders" for those of us doomed to
> > operate in a Windoze environment.? Or, are we only real if we
> > have access to UNIX?
>
> Yes. :-) Seriously, though, take a look at the Good Net-Keeping Seal
> of Approval <http://http.bsd.uchicago.edu/~twpierce/news/index.html>.
> It doesn't list Outlook, but it lists a lot of newsreaders and how
> close they come to meeting the news-related RFC's. If you have a
> choice, support good Internet programming by using a program that
> performs it correctly.
That's the old version, it has been superseded.
Try: <http://www.xs4all/~js/gnksa/>. It DOES list OE (the new site has
many more evaluations), but only for the Mac. It doesn't pass (for one
thing it doesn't always include a References header) but MS has been
made aware of the results and have said they will address at least some
of the issues in the next version of Mac OE - what this means for OE for
Windows I don't know.
--
John Moreno
------------------------------
Date: Fri, 8 May 1998 14:54:43 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: Strange problem.
Message-Id: <Pine.GSO.3.95.980508145022.29060C-100000@cp.pathfinder.com>
On Sun, 3 May 1998, Bob Tate wrote:
> $filesave = 0; # reset the save indicator to off
> $filedate = substr($database_row,83,5);
> $holdline = substr($database_row,1,131);
> if ($newdir == 0)
> {
> mkdir($filedate,777); # Make the director to store the info in
> $newdir = 1;
Do you want that to be "mkdir($filedata, 0777);" ???
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: 8 May 1998 18:15:20 GMT
From: Aaron Kushner <akushner@lebeaux.cup.hp.com>
Subject: Re: Symbolic References
Message-Id: <6ivi3o$t2r$1@ocean.cup.hp.com>
So what is the best/approved way of setting a variable in a perl program
and accessing it in all of the modules. For example, if I set DEBUG=1 in
the main program, how should the modules access DEBUG?
Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
> This is the same problem as the person who thought this would work:
> package main;
> my $lfile;
> package other;
> *his = \$main::lfile;
> Somehow confusing symbol-table variables with lexical-scoped ones,
> just as you have.
> I know it's my own fault for not having explained this well enough
> in the documentation.
------------------------------
Date: 08 May 1998 12:11:27 -0600
From: Nathan Torkington <gnat@frii.com>
Subject: Re: Tip: Hash Slices
Message-Id: <5qn2cseipc.fsf@prometheus.frii.com>
Charles Margolin <cmargoli@world.northgrum.com> writes:
> > Note that we say @array[1,3,4] not $array[1,3,4] -- the former
> > is a list, so generates list context if you assign to it. The
> > latter is a normal subscript operation, extracting the 4th
> > element in @array, but it generates list context and it ignores
> > the "1,3" part of the subscript. Don't confuse 'em!
>
> You WILL confuse your readers if you say "list context" when discussing
> $array[1,3,4].
Typo. I was contrasting @array[1,3,4] (list context) with
$array[1,3,4] (scalar context), but ended up typing "list
context" twice. It's right in the book, I promise :-)
Nat
------------------------------
Date: Fri, 08 May 1998 15:12:31 -0400
From: Matt Murdock <tech@BMEi.on.ca>
Subject: Using split to return a @ without splitting on spaces
Message-Id: <3553591F.1E43F970@BMEi.on.ca.NOSPAM>
I have a user's password (/etc/passwd) entry in an array. I want the
full user name from the GECOS field.
@pwent is (as it may sound) the list containing a user's passwd entry.
@gecos SHOULD become a list, split by commas, of the GECOS field in the
passwd entry. However, when split passes on to @gecos, the result is
not what I expect. For example, the full user name from the GECOS field
should be contained in $gecos[0], but is instead contained over multiple
entities in the @gecos list. It appears as if the effect of the split
is to split both on the pattern ',' AS WELL as on whitespace.
-----------snip, snip ----------------------
@pwent = SYS_get_pwent( $http_data{ 'loginID' } );
print "Content-type: text/html\n\n";
if( defined $pwent[6] ) {
($full_name, $blah) = split /,/, $pwent[6];
@gecos = split /,/, $pwent[6];
}
else {
print "GECOS Field not found for $http_data{ 'loginID' }<BR>\n";
exit 1;
}
----------- snip, snip --------------------
If you print $full_name and $gecos[0], the result is NOT THE SAME!
$full_name will be the COMPLETE name, while $gecos[0] will be the FIRST
NAME ONLY!.
What can I do to prevent splitting on whitespace????
TIA
Matt Murdock
------------------------------
Date: 8 May 1998 17:58:55 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: WIN32 tee command
Message-Id: <6ivh4v$1ai$2@marina.cinenet.net>
Gary L. Burnore (gburnore@netcom.com) wrote:
: Tee allows the output of a command to be directed to two different places
: (input).
:
: Example: Run du into a file and see it on the screen at the same
: time:
:
: du -f | tee /dev/tty > output.file
Just out of curiosity, why not write that as
du -f | tee output.file
? It seems that would accomplish the same thing (output to output.file
and the terminal) less confusingly.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Fri, 08 May 1998 14:22:23 -0400
From: Bob Rasmussen <bobras@erols.com>
Subject: Re: Windows 95 Problem
Message-Id: <35534D5F.62F5@erols.com>
Eric Bohlman wrote:
>
> Bob Rasmussen <bobras@erols.com> wrote:
> : I just did a backup from my Windows 95 machine at work and
> : a restore on my Windows 95 machine at home. When trying
> : to execute a simple
>
> : C:\PERL5>PERL -V I receive
>
> : "Program will not run in DOS mode" Can anyone suggest why
> : I have a problem with the home system, but, not the work system?
>
> Most likely the "DOS prompt" on your home machine has the "use MS-DOS
> mode" option set, which makes the Win32 API invisible to programs run
> under it (it's a compatibility mode for DOS applications that rely on
> undocumented features that aren't supported in the standard Win95 console
> interface). If you type "exit" at your DOS prompt, does Win95 partially
> reload? If so, you've got "use MS-DOS mode" set. The solution is to
> either change the properties for your "DOS prompt" shortcut, or create
> another shortcut without "use MS-DOS mode."
Thanks, Eric...
You placed me into the right area. Actually, the problem was...
both --
"Prevent MS-DOS based programs from detecting windows" and
"Suggest MS-DOS mode as necessary" were both checked off.
After turning on "MS-DOS mode" and unchecking the two entries
above, and rebooting the system, I received a warning message
about DOS Mode. After some playing around I was able to create
a new shortcut with "Suggest MS-DOS mode as necessary."
All is now well...Perl 5.001 now runs...thanks for the help...Bob
------------------------------
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 2542
**************************************