[12528] in Perl-Users-Digest
Perl-Users Digest, Issue: 6128 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 25 15:07:21 1999
Date: Fri, 25 Jun 99 12:00:27 -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, 25 Jun 1999 Volume: 8 Number: 6128
Today's topics:
Re: "$?" variable in NT <vishal@ngenie.com>
Re: 'tr/ / /s; myfile.txt won't work (Larry Rosler)
Re: 'tr/ / /s; myfile.txt won't work <rootbeer@redcat.com>
Re: 'tr/ / /s; myfile.txt won't work <cassell@mail.cor.epa.gov>
Re: 'tr/ / /s; myfile.txt won't work <dgrisinger@exactis.com>
alphabetical sorting <amwalker@gate.net>
Beginner's Question <edenkers@ktis.net>
Re: Beginner's Question <jdporter@min.net>
Re: Beginners Question: How to jump in and out subdirec <cassell@mail.cor.epa.gov>
Re: Calculating weekday given year, month and day (Martin Vorlaender)
Re: Can't retain a directory change from within a scrip <juex@my-dejanews.com>
compiling byteperl rlw_ctx@my-deja.com
Conveting plain-text username and password files <kjcox@vii.com>
copying files from the web <marlon@soda.CSUA.Berkeley.EDU>
Re: Cross-platform spawn required <cassell@mail.cor.epa.gov>
Re: Keeping trake of file postion <rootbeer@redcat.com>
Re: Kicking off remote program <demonic_hobo@my-deja.com>
Newbie - Using Perl & Digital Teamlinks (Darren Millin)
Re: Newbie can't delete file <cassell@mail.cor.epa.gov>
Re: Perl Alphanumeric Sort? (Randal L. Schwartz)
Re: preventing echo during user input <hove@ido.phys.ntnu.no>
Re: Printing to file / sed and diff <cassell@mail.cor.epa.gov>
Re: Problem with regular expression <rootbeer@redcat.com>
Re: Problem with regular expression <tis5miwa@fht-esslingen.de>
Re: Question about hashes and lists (Larry Rosler)
Re: Question about hashes and lists <rootbeer@redcat.com>
Re: Question about hashes and lists <stampes@xilinx.com>
Re: Regex question (i think) <upsetter@ziplink.net>
Re: Regex question (i think) (Randal L. Schwartz)
Re: syntax check without execution (Larry Rosler)
Re: syntax check without execution <dgrisinger@exactis.com>
Re: syntax check without execution <rootbeer@redcat.com>
Re: syntax check without execution <cassell@mail.cor.epa.gov>
Re: The Perlfaq Man Can! (was: problems with chmod func <cassell@mail.cor.epa.gov>
trapping "severe warnings"? <agianni@acsu.buffalo.edu>
unbuffered read, getc? <msoulier@americasm01.nt.com>
Unix CGI > Win/Mac (Thomas Fischer)
Re: validating a regexp from a CGI form (Randal L. Schwartz)
Re: Viral matters [completely off-topic] <cassell@mail.cor.epa.gov>
Re: Where is sendmail on NT using Perl <vishal@ngenie.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Jun 1999 23:58:15 +0530
From: "Vishal Doshi" <vishal@ngenie.com>
Subject: Re: "$?" variable in NT
Message-Id: <7l0j8s$cgd$2@fu-berlin.de>
under 4dos(a command shell) on NT you can use
'%?' to get the return code of the last process....
Try that!
Vishal
( I am currently using Win98, so I can't test it. It does not work under the
command.com shell)
John Paopeng <ppjohn@ncs.com.sg> wrote in message
news:37560CBE.C99AE57A@ncs.com.sg...
> Hello to all.
>
> In Unix "$?" will return 0 if the job is done and success.
> My Perl script in Unix can regconize that too.
> What about NT???
> Seems that my "$?" always return 0 even though the job is fail.
>
> Any help will be very appreciated.
> John
> --
> =========================================================================
> mailto:ppjohn@ncs.com.sg
> PGP key: http://www.nai.com/products/security/public_keys/lookup_key.asp
> Home page: http://www.geocities.com/TheTropics/Island/5251/
> ==========================================================================
------------------------------
Date: Fri, 25 Jun 1999 10:21:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: 'tr/ / /s; myfile.txt won't work
Message-Id: <MPG.11dd5a87e5b44c55989c47@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7l09p5$87s$1@nnrp1.deja.com> on Fri, 25 Jun 1999 16:12:32
GMT, j_a_p@my-deja.com <j_a_p@my-deja.com> says...
> I have written a search engine that looks into a textfile and finds
> prints out the results if found. However my problem is that since I
> converted the text file from excell there are a lot of empty spaces
> after my delimeter (::). I need to remove these spaces but not the
> spaces between the words.
> For Example
>
> text:: text :: text:: text text:: text text text::
> ^ ^ ^ ^ ^
> | | | | |
> remove remove remove remove
> I need to remove all of these spaces. I tried using
> perl -ne 'tr/ / /s;' myfile.txt, but this isn't working. Does anyone
> know what I am doing wrong?
You are using tr (incorrectly) where only a regex will do. 'tr' handles
single characters, with no surrounding context. You could use
tr/ //d;
which would delete all spaces, not just those after '::'.
To do what you want, simply:
s/:: +/::/g;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 25 Jun 1999 10:35:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: 'tr/ / /s; myfile.txt won't work
Message-Id: <Pine.GSO.4.02A.9906251034020.6929-100000@user2.teleport.com>
On Fri, 25 Jun 1999 j_a_p@my-deja.com wrote:
> text:: text :: text:: text text:: text text text::
> ^ ^ ^ ^ ^
> | | | | |
> remove remove remove remove
> I need to remove all of these spaces. I tried using
> perl -ne 'tr/ / /s;' myfile.txt, but this isn't working. Does anyone
> know what I am doing wrong?
You're using tr/// when you need something like a pattern match. Try split
and join, or s///, perhaps. Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 11:13:17 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: 'tr/ / /s; myfile.txt won't work
Message-Id: <3773C6BD.1A9D2427@mail.cor.epa.gov>
j_a_p@my-deja.com wrote:
> [snip]
> text:: text :: text:: text text:: text text text::
> ^ ^ ^ ^ ^
> | | | | |
> remove remove remove remove
> I need to remove all of these spaces. I tried using
> perl -ne 'tr/ / /s;' myfile.txt, but this isn't working. Does anyone
> know what I am doing wrong?
Yes. While tr/// is faster than s///, it doesn't have the
flexibility of regular expressions. You want to use regexen
to match only those cases preceded or followed by :: .
One way:
$string =~ s/::\s+/::/g;
$string =~ s/\s+::/::/g;
This can be done in one line, but that won't be as clear.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 25 Jun 1999 12:15:31 -0600
From: Daniel Grisinger <dgrisinger@exactis.com>
Subject: Re: 'tr/ / /s; myfile.txt won't work
Message-Id: <m3zp1oi1to.fsf@dhcp70.corp.merc.com>
lr@hpl.hp.com (Larry Rosler) writes:
> > text:: text :: text:: text text:: text text text::
> > ^ ^ ^ ^ ^
> > | | | | |
> > remove remove remove remove
<snip>
> To do what you want, simply:
>
> s/:: +/::/g;
You'll need another pass to catch any spaces preceding ::.
I'd write this like so-
s/\s*::\s*/::/g;
dgris
--
Daniel Grisinger dgrisinger@exactis.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Fri, 25 Jun 1999 14:26:47 -0400
From: Aaron Walker <amwalker@gate.net>
Subject: alphabetical sorting
Message-Id: <3773C9E7.82D04F7@gate.net>
hello,
I have two perl CGI scripts and one data file (add.pl, members.pl, and
members.dat). I have a html form that calls add.pl, which writes the
form data to members.dat. members.pl then retrieves the data from
members.dat and prints it out in a table. I would like to sort the
names of the members alphabetically by their first name.
For example:
in the html, I want to have anchors for each letter of the alphabet.
How would I go about sorting the data file and then putting each member
name under the appropriate anchor?
thanks in advance for your help,
Aaron Walker
------------------------------
Date: Fri, 25 Jun 1999 12:08:42 -0500
From: "Erik Denkers" <edenkers@ktis.net>
Subject: Beginner's Question
Message-Id: <7l0cpp$g33$1@dumber.ktis.net>
I understand how to define/create scalar variables/arrays. I understand how
to define/create references to variables/arrays. Why would you create and
use
references when you could just call the variable by it's original name?
Sorry if I'm being anal!
Erik
edenkers at kits.net
------------------------------
Date: Fri, 25 Jun 1999 18:33:41 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Beginner's Question
Message-Id: <7l0i25$bs5$1@nnrp1.deja.com>
In article <7l0cpp$g33$1@dumber.ktis.net>,
"Erik Denkers" <edenkers@ktis.net> wrote:
> I understand how to define/create scalar variables/arrays. I
understand how
> to define/create references to variables/arrays. Why would you create
and
> use
> references when you could just call the variable by it's original
name?
One obvious benefit comes from being able to have references to
variables that don't have names. I can create a reference to an
array -- an anonymous array -- like this:
$arrayref = [ 9, 42, 666 ];
What is the "name" of that array? It doesn't have one.
And since references are scalars, you can put them wherever you
can put a number or a string (almost), such as the value of an
array element, or the value of a hash entry. Consider:
$things[5] = [ 9, 42, 666 ];
Then you have (as you'll discover by printing),
$things[5][0] = 9;
$things[5][1] = 42;
$things[5][2] = 666;
In short, references are what make complex data structures in Perl
possible. Read prelref, perllol and perldsc for more info.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 25 Jun 1999 10:23:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Beginners Question: How to jump in and out subdirectories?
Message-Id: <3773BAF6.2F18D394@mail.cor.epa.gov>
Pollus Fornerod wrote:
> [snip]
> But now: If I find the jpegs in a subdirectory and I have the name of
> that subdirectory in a variable $subdir I want to jump into that
> directory using the shell's `cd "$subdir"` to run my old thumbnail.pr
> script there nothing happens! It seems I cannot change directories from
> within the script using the shell command `cd`.
>
> Am I trying to do something extremely stupid here?
No, just a little inexperienced. When you use the shell's 'cd' you
spawn off a subprocess which does the cd, then returns. But the
environment of the child doesn't get passed back to the parent
[your Perl program]. So just do the cd using the built-in Perl
function chdir(), instead of using the shell.
BTW, two more points:
[1] It is considered poor style to use `` in void context.
You normally would use system() in such a case. [But not here!]
[2] You might look at the File::Find module as a better tool for
searching through a directory tree.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 25 Jun 1999 16:57:58 +0200
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Calculating weekday given year, month and day
Message-Id: <377398f6.524144494f47414741@radiogaga.harz.de>
Gregory Snow (snow@biostat.washington.edu) wrote:
: This algorythm works for any
: date after october 15, 1582 (it wouldn't be to hard to fix that if you
: really needed to),
Of course, this is just a offset of ten days. But: Different countries
started applying the Gregorian calendar at different times (as late as
1917 in Russia's case). So I wouldn't go back too far...
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
VMS is today what | work: mv@pdv-systeme.de
Microsoft wants | http://www.pdv-systeme.de/users/martinv/
Windows NT 8.0 to be! | home: martin@radiogaga.harz.de
------------------------------
Date: Fri, 25 Jun 1999 10:25:55 -0700
From: "J|rgen Exner" <juex@my-dejanews.com>
Subject: Re: Can't retain a directory change from within a script!
Message-Id: <7l0e1s$1g@news.dns.microsoft.com>
Paul D Enderson <techsup@datascan.co.uk> wrote in message
news:MPG.11dd7459dbc11893989681@news.demon.co.uk...
[...]
> I want to have the program change directory when it has found a match.
> The problem I am having is that when I change directory from within the
> script, and then exit the script, the directory change has been lost. I
> think this is caused by Perl spawning a new shell to run the script (or
> something similar) :)
Close. It's not Perl, it's the shell who is starting perl in a new process
(as it would do with any other program, too).
And there is nothing you can do about it. Children can not change
environment variables of the parent process.
jue
--
J|rgen Exner
------------------------------
Date: Fri, 25 Jun 1999 17:05:26 GMT
From: rlw_ctx@my-deja.com
Subject: compiling byteperl
Message-Id: <7l0csd$9i5$1@nnrp1.deja.com>
I have just downloaded perl-5.00503 (stable.tar.gz) from CPAN.
I am running RedHat Linux 6.0 on a Pentium II box.
When I built Perl 5.00503, the program byteperl was not also
built. Following the instructions in the README file, I tried
to build byteperl. This resulted in several dozen syntax errors
being reported.
Before I spend a lot of time trying to compile it, has anyone
suceded in building and running byteperl - either under RedHat
6.0 (on Intel or SGI) or under IRIX 6.4 (on SGI)?
Thanks in advance.
--
Ron Wilson
Connectex, LLC
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 25 Jun 1999 17:14:39 +0000
From: "Kerry J. Cox" <kjcox@vii.com>
Subject: Conveting plain-text username and password files
Message-Id: <3773B8FF.3C581E85@vii.com>
I'm assisting in helping some users go from plain-text username and
password files to Linux. Currently, all the users on this sytem (over
1000) have their login names and passwords in a simple flat-file
format. I need to provide some way to enter all these users onto a
Linux system without doing it by hand.
Does anyone know of a simple script that would go through a flat
file database and would then enter all the usernames and passwords onto
a Linux system? It would be RedHat 6.0.
Thanks. Please email me as well as I don't always have the time to
check these newsgroups.
KJ
--
.-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
| Kerry J. Cox Vyzynz International Inc. |
| kjcox@vii.com Systems Administrator |
| (801) 596-7795 http://www.vii.com |
| ICQ# 37681165 http://quasi.vii.com/linux/ |
`-------------------------------------------------------'
------------------------------
Date: Fri, 25 Jun 1999 11:54:38 -0700
From: marlon <marlon@soda.CSUA.Berkeley.EDU>
Subject: copying files from the web
Message-Id: <Pine.BSF.3.96.990625115144.19964A-100000@soda.CSUA.Berkeley.EDU>
given a URL like www.domain.com/foo.gif how do I copy the file
to a local dir. I know how to create requests with LWP and
parse line by line but this doesn't seem like the wrong thing
for a gif. Also FILE::Copy looks usefull but how do I tell it that the
source is a URL? Thanks!
_
------------------------------
Date: Fri, 25 Jun 1999 10:43:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Cross-platform spawn required
Message-Id: <3773BFDA.DB21C748@mail.cor.epa.gov>
donath@my-deja.com wrote:
>
> What is really needed is a Spawn module that will behave identically
I think Todd MacFarlane has that name already trademarked. :-)
> when run in Unix and NT. The underlying code will use the proper system
> libraries on whatever OS it's running for performing the task, but the
> results would be the same. It should return a PID, handle pipes,
> simulate forking on NT, all the functionality that make forking on Unix
> so powerful. Does anyone know of such a on-going project, or is it time
> to start one???
Well, in the immortal words of Tom Christiansen, 'patches are
welcome'. :-)
You may be interested to know that Microsoft has funded
ActiveState to get fork() working on win32. That would solve
a lot of problems. The p5p folks have probably discussed this
at length too.
BTW, how would you propose to do Spawn on a legacy system like
a pre-windows MS-DOS system? We still get requests here for
Perl for those babies...
just wondering,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 25 Jun 1999 10:18:33 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Keeping trake of file postion
Message-Id: <Pine.GSO.4.02A.9906251017230.6929-100000@user2.teleport.com>
On Fri, 25 Jun 1999, Shaddy International Ltd. wrote:
> I want to be able to output 20 hits at a time. (Kinda like yahoo and
> all the other search engines out there, but I can't figure out how it
> keep track of my position in the file and restart from that position.
I think you could use the methods in one of Randal's Web Techniques
columns. Enjoy!
http://www.stonehenge.com/merlyn/WebTechniques/
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 16:52:21 GMT
From: Chris Wilkes <demonic_hobo@my-deja.com>
Subject: Re: Kicking off remote program
Message-Id: <7l0c40$972$1@nnrp1.deja.com>
In article <MSwc3.1020$qX3.14388@typhoon.nycap.rr.com>,
"SfpcC" <scrosby1@nycap.rr.com> wrote:
> Newbie post (got several programs running and am greatly impressed
with Perl
> & its community):
>
> I want to be able to kick off either a .bat job or .pl program from
one NT
> server to another (also WinNT).
Here's a quick little program that I've found useful to start a remote
program on an NT machine. It finds the time on the remote computer and
then creates an AT job a minute in the future.
The program can be modified to schedule commands at various times
throughout the day. I might work on it as sometimes I have to schedule
a job to run every 10 minutes and I couldn't find a switch with AT to
do so.
Chris
#!c:\perl\bin\perl
# script to run the command in the next minute on a remote machine
# can handle going from AM to PM, but I won't do it after midnight
# also you can create an output file
# syntax:
# soon.pl cs17 "d:\path\zipit.bat" ["d:\errorpath\error.txt"]
my $machine = shift;
my $line = shift;
my $output = shift;
my $sm = "\\\\$machine"; # "slashed machine"
$time_temp = `net time $sm`;
($time) = $time_temp =~ /$machine is \S+\s+(.*)/;
$time =~ s/\s+//g;
($hour, $min, $ampm) = $time =~ /^(\d+):(\d+)(AM|PM)$/;
$hour_n = ($min == 59) ? $hour++ : $hour;
$min_n = ++$min % 60;
$min_n = "0$min_n" if (length($min_n) < 2);
if ($hour_n == 12 && $min_n == "00") {
$ampm = ($ampm =~ /PM/) ? "AM" : "PM";
}
$command = "at $sm $hour_n:$min_n$ampm cmd \/c \"$line";
$command .= " > $output" if ($output);
$command .= "\"";
print "$command\n";
`$command`;
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 25 Jun 1999 17:38:35 GMT
From: D.Millin@BTInternet.com (Darren Millin)
Subject: Newbie - Using Perl & Digital Teamlinks
Message-Id: <3773bccc.2084395@news.btinternet.com>
I am trying to write a script that will allow me to send e-mail to
accounts on held on a Digital Teamlinks system. As far as
i am aware, this system uses x400 mail. Can anyone give
me some pointers to resources, modules or docs that would
help ?
I have looked throught the FAQ's, CPAN, RFC's and 'Learning Perl'.
These cover the use SMTP and sendmail, but I did not see
anything on linking to any e-mail system other than
POP & SMTP.
Thanks
Darren Millin
BTW I am using ActiveState 516.
------------------------------
Date: Fri, 25 Jun 1999 10:10:15 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie can't delete file
Message-Id: <3773B7F7.E8B684B5@mail.cor.epa.gov>
TRG Software : Tim Greer wrote:
> [snip of poster's question]
> This question has already been answered in a prior threat in regards to
^^^^^^
Tim, I think your Freudian slip is showing. :-)
> your specific question/post earlier.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 25 Jun 1999 11:54:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl Alphanumeric Sort?
Message-Id: <m13dzgdsak.fsf@halfdome.holdit.com>
>>>>> "Jason" == Jason Larke <jlarke@uu.net> writes:
Jason> jlarke@anthem ~% perl
Jason> @letter_nums = ("A4","A2","A1","A3");
Jason> sub by_values
Jason> {
Jason> ($a cmp $b)
Jason> }
Jason> @temp1 = sort by_values (@letter_nums);
Jason> print @temp1 , "\n";
Jason> A1A2A3A4
Jason> Works for me. You might want to post the full code you're using.
You may want to use a dataset that includes both "A11" and "A2", like
the original data. In that case, yours fails, sorting A11 before A2.
print "Just another Perl hacker,"
--
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@teleport.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: 25 Jun 1999 20:16:16 +0200
From: Joakim Hove <hove@ido.phys.ntnu.no>
Subject: Re: preventing echo during user input
Message-Id: <k0naetono27.fsf@ido.phys.ntnu.no>
resark@my-deja.com writes:
> I need to prevent what is being input by the user from being echoed (a
> password in a login prompt)
>
> I know is it possible with a system call (stty -echo), but I know there is a
> better way that does not involve system calls. I was pointed to the
> Term::ReadLine module, but have been unable to find information on how to
> make it work in this way.
Well, I have never done this myself, but I have the "Perl Cookbook"
which says :
<Perl Cookbook page 529:>
use Term::ReadKey;
ReadMode('noecho');
$password = ReadLine(0);
</Perl Cookbook>
Good luck,
Joakim
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / 352 GF | Skxyensgate 10D #
# N - 7034 Trondheim hove@phys.ntnu.no | N - 7030 Trondheim #
=====================================================================
------------------------------
Date: Fri, 25 Jun 1999 10:55:06 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: cmbnews@my-deja.com
Subject: Re: Printing to file / sed and diff
Message-Id: <3773C27A.D5021A6F@mail.cor.epa.gov>
[courtesy cc to poster]
cmbnews@my-deja.com wrote:
>
> I have a section of code that looks similar to the following:
>
> print "before the sed and diff\n";
> system("sed \"$preprocess\" $file1 > $tmpfile");
> system("sed \"$preprocess\" $file2 | diff $tmpfile -");
> print "after the sed and diff\n";
>
> The problem is that if I redirect the output of my program to a file
> the order of the print lines in relation to the output from the system
> commands is not guaranteed.
> I get the same problem if I explicitly open a file and print to it for
> the print lines and redirect to the file using >> for the system lines.
You need to autoflush. Read the perlvar section about $|, so
you'll know why you want to say:
$|=1;
before your print() statements.
> Is there anything I can do to guarantee that my output goes to file in
> the correct order, or is there anyway I can use sed and diff within
> perl instead of using system commands, as this would ensure the correct
> order.
sed is easy to do in Perl. In fact, there's an s2p [sed-to-Perl]
script which can translate a sed script to a Perl script [although
not optimally in all cases].
diff is a bit harder.
But you don't actually *have* to do the whole diff routine here.
Perl has a $. variable which tracks the 'line' number of the file
you're reading in [it tracks newlines, or whatever you told Perl
to use as the input record separator]. You could just use
Perl regexes to make your changes, and retain the values of the
lines where the changes have been made, as well as the
before-and-after values. that way you don't have to write diff
from scratch, or shell out to use it.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 25 Jun 1999 10:39:17 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Problem with regular expression
Message-Id: <Pine.GSO.4.02A.9906251036210.6929-100000@user2.teleport.com>
On Fri, 25 Jun 1999, Michael Wahl wrote:
> Now the regexp should find the strings but only if it doesn't contain
> the word "Paper".
Are you asking for a pattern which will match any string which does not
contain 'Paper'? Maybe you want to simply negate the result of /Paper/ .
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 19:55:03 +0200
From: Michael Wahl <tis5miwa@fht-esslingen.de>
Subject: Re: Problem with regular expression
Message-Id: <3773C277.1D857730@fht-esslingen.de>
Yes thats exactly what I search for.
I search for a regexp which will match any string which does not contain
'Paper'.
Tom Phoenix wrote:
> On Fri, 25 Jun 1999, Michael Wahl wrote:
>
> > Now the regexp should find the strings but only if it doesn't contain
> > the word "Paper".
>
> Are you asking for a pattern which will match any string which does not
> contain 'Paper'? Maybe you want to simply negate the result of /Paper/ .
>
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 10:31:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question about hashes and lists
Message-Id: <MPG.11dd5cab4306b346989c48@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <37733f03.79107039@24.0.3.71> on Fri, 25 Jun 1999 16:37:45
GMT, Joan Richards <richj@home.com> says...
> I'm trying to do some stuff with hashes of lists. i am able to easily
> create the hash of lists. but, i can't seem to delete an entry. i am
> creating an entry into the hash by doing - push @{ $hash{$list} },
> $parm; and then i try to delete an entry from the list by doing -
> delete $hash{$list}{parm}. however, this doesn't seem to remove the
> entry from the list.
'delete' deletes entries from a hash, not an array. To remove an entry
from an array, you must use 'shift', 'pop', 'splice', or 'grep' (or even
'map'), naming the array as you did above for 'push'.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 25 Jun 1999 10:41:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Question about hashes and lists
Message-Id: <Pine.GSO.4.02A.9906251039290.6929-100000@user2.teleport.com>
On Fri, 25 Jun 1999, Joan Richards wrote:
> i am creating an entry into the hash by doing - push @{ $hash{$list}
> }, $parm;
So, you have a hash of arrayrefs.
> and then i try to delete an entry from the list by doing -
> delete $hash{$list}{parm}.
So you're using it as if it's a hash of hashrefs. Maybe you meant to do
something like $hash{$list}{parm}++ in the first place.
Have fun with Perl!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 25 Jun 1999 17:50:38 GMT
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: Question about hashes and lists
Message-Id: <7l0fhe$9p1@courier.xilinx.com>
Joan Richards <richj@home.com> wrote:
: I'm trying to do some stuff with hashes of lists. i am able to easily
: create the hash of lists. but, i can't seem to delete an entry. i am
: creating an entry into the hash by doing - push @{ $hash{$list} },
: $parm; and then i try to delete an entry from the list by doing -
: delete $hash{$list}{parm}. however, this doesn't seem to remove the
: entry from the list.
: what am i doing wrong?
For starters, you aren't providing us with real code examples.
You also aren't using -w, use strict, or paying attention to the
error messages perl is generating for you.
But that's not the real problem....the real problem is you don't
understand HoL enough.
In step one, you are pushing a value onto an array.
In step two you are attempting to delete a value from a hash.
main::(-e:1): 1
DB<1> %hash = ()
DB<2> $hash{array} = []
DB<3> push @{$hash{array}}, 'element'
DB<4> x %hash
0 'array'
1 ARRAY(0x2db6a8)
0 'element'
DB<5> delete $hash{array}{element}
Not a HASH reference at (eval 12) line 2.
You just can't do that. To do what you want, you really need a
hash of hashes:
main::(-e:1): 1
DB<1> %hash = ()
DB<2> $hash{array}{element} = 1
DB<3> x %hash
0 'array'
1 HASH(0x303ee4)
'element' => 1
DB<4> delete $hash{array}{element}
DB<5> x %hash
0 'array'
1 HASH(0x303ee4)
empty hash
reread perllol and perldsc for more information, and perlref for
syntax that may be easier on the eyes if you can grok refs.
-Jeff
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Fri, 25 Jun 1999 17:07:35 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Regex question (i think)
Message-Id: <rHOc3.248$Of3.57785@news.shore.net>
Tom Phoenix <rootbeer@redcat.com> wrote:
: But you could also see what fred and barney think about having more than
: one at-sign in e-mail addresses. Here's their address.
: <"fred@barney"@redcat.com (Yes, "fred@barney" is correct!)>
I tend to doubt that he's got any email addresses like that in his real
data.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: 25 Jun 1999 11:45:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Regex question (i think)
Message-Id: <m1bte4dsq1.fsf@halfdome.holdit.com>
>>>>> "Scratchie" == Scratchie <upsetter@ziplink.net> writes:
Scratchie> I tend to doubt that he's got any email addresses like that
Scratchie> in his real data.
But how do you know? Why are you being a "simple email address" snob?
There are people out there that still have weird gateway addresses.
Others have "+" suffix addresses, like
"address+qualifier@this.host.here".
RFC822 has the format of an address. Get used to it. It's been
around for 17 years, and still holding up fine.
print "Just another Perl hacker,"
--
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@teleport.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: Fri, 25 Jun 1999 10:07:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: syntax check without execution
Message-Id: <MPG.11dd57142da987ed989c46@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <3773987C.EA5197A0@xli.com> on Fri, 25 Jun 1999 10:55:56 -
0400, Greg Bartels <gbartels@xli.com> says...
> is there a way to syntax check a file
> with perl code in it without actually
> executing it. is there a hook into
> 'eval' or something
> that would let me do this?
perl -c file...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 25 Jun 1999 11:07:26 -0600
From: Daniel Grisinger <dgrisinger@exactis.com>
Subject: Re: syntax check without execution
Message-Id: <m39098jjjl.fsf@dhcp70.corp.merc.com>
Greg Bartels <gbartels@xli.com> writes:
> is there a way to syntax check a file
> with perl code in it without actually
> executing it.
Do you need something beyond perl -cw file?
dgris
--
Daniel Grisinger dgrisinger@exactis.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Fri, 25 Jun 1999 10:15:59 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: syntax check without execution
Message-Id: <Pine.GSO.4.02A.9906251009180.6929-100000@user2.teleport.com>
On Fri, 25 Jun 1999, Greg Bartels wrote:
> is there a way to syntax check a file with perl code in it without
> actually executing it.
Maybe you want the -c command-line option. See the perlrun manpage for
more information on that.
> is there a hook into 'eval' or something that would let me do this?
Maybe you want the Safe module. Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 25 Jun 1999 11:07:40 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: syntax check without execution
Message-Id: <3773C56C.989878EB@mail.cor.epa.gov>
Greg Bartels wrote:
>
> is there a way to syntax check a file
> with perl code in it without actually
> executing it. is there a hook into
> 'eval' or something
> that would let me do this?
Do you mean the -c command-line option, or are
you looking for something deeper?
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 25 Jun 1999 11:19:38 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: The Perlfaq Man Can! (was: problems with chmod function)
Message-Id: <3773C83A.3AE17C0F@mail.cor.epa.gov>
Tom Christiansen wrote:
> [snip]
>
> Who can take your question
> Check for something new
> Cover with with answers
> And a bit of pod or two?
>
> The Perlfaq Man!
> The Perlfaq Man can!
> The Perlfaq Man can 'cause he mixes it with docs
> And makes your Perl taste good!
>
> [snip of more great verses]
Bravo! Encore!
"Tom Christiansen IS Gene Wilder!" - Rex Reed
"I laughed. I cried. I watched the movie twice!" - Roger Ebert
"I'm sorry I missed it." - the late Gene Siskel
"I particularly loved the part where Tom pushes the newbie
into the chocolate river and lets him get sucked up that skinny
pipe." - Gene Shalit
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 25 Jun 1999 14:29:22 -0400
From: Andrew S Gianni <agianni@acsu.buffalo.edu>
Subject: trapping "severe warnings"?
Message-Id: <3773CA82.F1C9B614@buffalo.edu>
I'm writing a cgi app that tries to do an require on a few files. The
requires are wrapped in an eval{} and it catches problems, but whenever
I get a "severe warning" it always just spits it out. For example if I
get a:
syntax error at /some/file/name line 4, near "some_random_string"
(a "fatal error") it catched it and it never come out on the page that's
generated (I generate an error page if I can't do all the requires)
However, I occasionaly get a:
String found where operator expected
kind of error (a "severe warning") and I can't trap it, and it just ends
up printing it out before the top of the html document (or causing an
internal server error if I don't set $| to a non-zero value). Any
suggestions of things I could do to catch this so it doesn't show up on
the page?
TIA...
Andrew
--
Andrew Gianni - Developer "You are about to be told one
UNIX Guy/Juggler Extraordinaire more time that you are America's
SUNY at Buffalo ACS/CIT most valuable natural resource...
ph:(716)645-3587x7009 Have you seen what they do to
fx:(716)645-3588 valuable natural resources?"
agianni@buffalo.edu -Utah Phillips
http://www.cs.buffalo.edu/~agianni/
------------------------------
Date: Fri, 25 Jun 1999 13:13:01 -0400
From: "Soulier, Michael [SKY:1Z22:EXCH]" <msoulier@americasm01.nt.com>
Subject: unbuffered read, getc?
Message-Id: <3773B89D.8EBA3969@americasm01.nt.com>
Kay, if I wish to read from a filehandle in a completely unbuffered
fashion, one character at a time, how do I do it? The Perl Cookbook
suggests that you can read character by character to get around
buffering problems, but it doesn't say how (that I have seen).
Is there a way to flush the buffer without closing it (I'm not the one
doing input to it, so I can't send a newline)?
Can I use the FileHandle->setvbuf() method to set it to _IONBF to use
unbuffered input?
Anything?
Code samples please, and email would be appreciated.
Thanks very much. I've run into a bit of a wall here and nothing is
working.
Mike
--
Michael P. Soulier
1Z22, SKY
Tel: 613-765-4699 (ESN: 39-54699)
Email: msoulier@nortelnetworks.com
Carrier Packet Solutions
Nortel Networks Corporation
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."
-Harley Hahn, A Student's Guide to UNIX
------------------------------
Date: Fri, 25 Jun 1999 15:58:12 GMT
From: tfischer@deakin.edu.au (Thomas Fischer)
Subject: Unix CGI > Win/Mac
Message-Id: <3773a63e.289927884@news.deakin.edu.au>
Hi,
I want my cgi to output an HTML containing a
form/textarea with some plain text in it. The perl
script knows the user's platform and now I want
to convert the linefeeds in the text for the
textarea to the platform specific format:
\n -> \r\n for win
\n -> \r for mac
all my attempts fail. How can this be done??
Thomas
------------------------------
Date: 25 Jun 1999 11:50:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: validating a regexp from a CGI form
Message-Id: <m17losdsii.fsf@halfdome.holdit.com>
>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:
Bart> Try eval(). Actually, try something like:
Bart> $sub = eval "sub { /$regexp/ }";
I wouldn't do that. What if $regexp is "/; system 'rm -rf /'; /" ?
print "Just another Perl hacker,"
--
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@teleport.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: Fri, 25 Jun 1999 10:38:44 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Viral matters [completely off-topic]
Message-Id: <3773BEA4.58DD1F39@mail.cor.epa.gov>
Philip 'Yes, that's my address' Newton wrote:
>
> Don't dare. For one, I've never seen any code directly[1] and can't
> comment on the quality -- I've just gained the strong impression (from
> reading this newsgroup) that the quality is not very good.
>
> [1] Except, of course, for "How to misparse a CGI query string", again
> and again.
And the 'how to totally munge date info returned from localtime()'
bit, which I think Jonathan posted from Matt's wwwboard script.
And the get_date [dys]function.
And the...
Oh, I don't have all day. But there are a lot. I'm somewhat
surprised that the ActiveStaters aren't so swamped with lame
requests to patch those scripts that they've already yanked
that bit from the win32faq.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 23 Jun 1999 23:42:28 +0530
From: "Vishal Doshi" <vishal@ngenie.com>
Subject: Re: Where is sendmail on NT using Perl
Message-Id: <7l0j8a$cgd$1@fu-berlin.de>
I have heard of a program called 'Blat' for NT which kinda emulates
sendmail;
Search for it on Altavista or something!
Vishal
RG <roland@oco.net> wrote in message news:375F070F.F1FFB064@oco.net...
> My sysop is out of town , but is not real familiar with perl, and I need
> to know where to point my formmail.pl script's tag to "sendmail" on the
> NT server. I believe the right path would be d:/perl/lib/sendmail
>
> $mailprog="d://perl//lib//sendmail";
> or
> $mailprog="d:/perl/lib/sendmail";
>
> Both of these do not work, as the form doesnt get sent to my email
> address. I do not get an error message, though.
>
> Thanks in advance
> Roland
> Radiowave Internet
> roland@oco.net
>
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 6128
**************************************