[9265] in Perl-Users-Digest
Perl-Users Digest, Issue: 2860 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 12 19:08:09 1998
Date: Fri, 12 Jun 98 16:00:49 -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, 12 Jun 1998 Volume: 8 Number: 2860
Today's topics:
Re: "no blank line" error from all WinPerl scripts (Jonathan Stowe)
A Simple Question! <cmeena@hotmail.com>
Re: accessing a:\ (Todd Lehman)
Re: Command line substitution thru subdirectories (Jason Turner)
GnuHoo Perl directory (Greg Bacon)
Re: goto in Perl debugger? <psdspss@execpc.com>
Re: Have we got a good free Perl manual? <dak@mailhost.neuroinformatik.ruhr-uni-bochum.de>
How do I limit the number of rows in sql query using Wi <pan@part.net>
How do I make 'Active State PerlEx' Reload scripts? <alba@ix.netcom.com>
Re: I want threads, threads and more threads! <thoellri@tobias.corp.adobe.com>
Re: Is this insane? (Daniel Grisinger)
Re: McCabe complexity analysis (Todd Lehman)
Re: null value checking with numbers (Charles DeRykus)
Re: pass the gravy and the hashref, please -- solved (Kevin Reid)
perl and NT Registrary access (Jahan K. Jamshidi)
Re: Puzzle challenge (Craig Berry)
Re: Puzzle challenge (John Stanley)
Re: Puzzle challenge (Michael J Gebis)
Re: Puzzle challenge <gnat@frii.com>
Re: Recursive help <probavm@cat.com>
Re: Recursive help (Kevin Reid)
Re: Regex Help! <psdspss@execpc.com>
Re: Regex Help! <danboo@negia.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 12 Jun 1998 22:03:51 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: "no blank line" error from all WinPerl scripts
Message-Id: <35819cbb.11676176@news.btinternet.com>
On Thu, 11 Jun 1998 04:22:31 GMT, Dewey Williams wrote :
>On Wed, 10 Jun 1998 22:22:08 GMT, Gellyfish@btinternet.com (Jonathan
>Stowe) wrote:
>
>>On Wed, 10 Jun 1998 20:11:32 GMT, williams wrote :
>>
>>>All the WinPerl scripts I have tried give this error when I access
>>>them with my browser (Netscape):
>>>
>>>Message: CGI output from D:/WebSite/cgi-shl/ filename
>>>contained no blank line separating header and data (most
>>>likely a broken CGI program)
>
>>Yep those nice folk over at comp.infosystems.www.authoring.cgi
>>probably have a very good FAQ they can point you to .
>>
>>A clue: \n\n
>
>I have browsed this newsgroup some and have come to the conclusion
>that many of the Perlites here are hostile, arrogant and downright
>unhelpful to the new user trying to learn Perl.
>
I have browsed this newsgroup some amd have come to the conclusion
that every once in a while someone who posts a question that is
downright unhelpful to anyone who is trying to determine a Perl answer
will get upset that that the regular users of this newsgroup have no
powers of prognostication.
>This answer I received was uninformative, sconfusing (in that it
>hinted the problem was not in my Perl script) and WRONG!
>
There was no hint that the problem was not in your little Perl script
but there was a big hint that it might not be a Perl problem. More
often a CGI problem *is* a CGI problem and not a Language problem at
all. I didnt see any *Perl Code* at all in your posting and the error
message certainly isnt described in perldiag (unless of course you
have access to some version I am not party to)
>The error message I received from my browser is apparently a generic
>one, indicating tht the Perl script is broken. After receiveing this
>error continuously on various scripts I managed to run the same
>scripts at the command line.
>
The error message you received from your browser has nothing to do
with Perl whatsoever. However by inference I took it to mean that you
had committed a common error among neophyte CGI scripters that is
ommiting the new lines between the header and the body of your output
hence :
>>A clue: \n\n
I am glad that you finally realized that it is possible to check your
script by running it at the command line but of course if you had paid
attention here you would have tried that in the first place before you
made a useless post here,before I answered in a manner that would
suggest that posting here in the manner you did was inappropriate,
before you got out of your pram and started whining, before I rebutted
your idiotic whinging and before you have to come back and defend your
deflated sense of honour blah blah blah.
>Behold! All the errors accompanying my script were revealed. Once
>fixed, no more browser error, no more Perl error (at least not in this
>instance).
>
Of course you're going to share the results of your labours for other
benighted CGI'ers experiencing a similar problem.
>Those of you that know Perl, please try to be a bit more forgiving
>toward those of us that don't. We are all beginners in some
>things.....
>
Its not a matter of knowing Perl or not - its a matter of knowing what
is a Perl question or CGI question or a needlework question ...
>
>
>Dewey Williams
>If you are not part of the solution....
> You are part of the precipitate.
>
Perhaps we are all a little dis-solute
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Fri, 12 Jun 1998 14:02:03 -0500
From: Meena Chockalingam <cmeena@hotmail.com>
Subject: A Simple Question!
Message-Id: <35817B2B.27B3D09B@hotmail.com>
Is there a way I can check if a directory is empty before trying to list
it? See the following code...
IfErrorDir = "/home/CRC";
open(IN, "$IfErrorDir") || die "could not open $IfErrorDir\n";
while (<IN>) {
chop;
$theFile = $_;
open(LS, "ls $IfErrorDir/$theFile/*.ifErrors|") || die "could not
list the $IfErrorDir/$theFile\n";
while (<LS>) {
..............
}
close(LS);
}
close(IN);
With this method, when one of the directory is empty, trying to do ls
produces an error saying
"/home/CRC/*.ifErrors: No such file or directory".
I tried different file test operations like -z, -d, -e etc... nothing
worked.
Any help would be appreciated.
Thanks,
Meena
------------------------------
Date: Fri, 12 Jun 1998 22:08:00 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: accessing a:\
Message-Id: <4Fhg1.1041$bj2.4770663@ptah.visi.com>
Larry Rosler <lr@hpl.hp.com> writes:
> 2. Tom C offered a "visual semantics" distinction that I have found
> extremely attractive: Use && and || for logical (con|dis)junction within
> a compound predicate; use 'and' and 'or' to introduce the consequent
> (which often involves assignment or change of flow). [...]
I like that. I also use C<or> for assertions,
$self->{FILENAME} or die "no filename ($self)";
and in places where it seems clearer to me than C<if> or C<unless>,
-f $self->{FILENAME} or $mode = '+>';
$self->{TIE} or $self->ExternalTie('<');
$v ne $v1 or return undef;
-d $home or mkdir($home, 0777) or die "$! ($home)";
and for certain types of error unwinding:
Lock(*FH, $TieModes{$mode}{lock})
or close(FH),
untie(%{$self->{DISK}}),
die "$! ($self, $mode, $self->{FILENAME})";
--Todd
------------------------------
Date: Fri, 12 Jun 1998 21:20:10 GMT
From: jason.turner@btinternet.com (Jason Turner)
Subject: Re: Command line substitution thru subdirectories
Message-Id: <35a38364.137148026@news.btinternet.com>
On Thu, 11 Jun 1998 21:48:20 GMT, Jonathan Stowe posted
<358048a2.14857542@news.btinternet.com>:
>dir /s /b *.htm | perl -ne "print qq%perl -i.old -p -e "s/foo/bar/g"
>$_%" > enmase.bat
Indeed, much neater. You deserve the A-Team theme more than I.
If I had one I'd send you it <g>
Dos 7 has a broken pipe though, and if you're gonna use 'dir' it's safer
to quote the filename due to
"pointy clicky users hate of the underscore.htm"
dir /s/b *.htm > f.tmp
perl -ne "chop; qx!perl -i.old -pe "s/foo/bar/g" \"$_\"!" f.tmp
Tested OK.
Anyway, I'm going back to lurking now.
Jason, who really just came here to read about Perl.
------------------------------
Date: 12 Jun 1998 20:56:33 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: GnuHoo Perl directory
Message-Id: <6ls4m1$18$1@info.uah.edu>
There's a new Perl resource available at
<URL:http://www.gnuhoo.com/Computers/Programming_Languages/Perl/>
It's the same concept as Yahoo, but they're trying to get lots and lots
of people involved instead of a paid few. I've been dubbed editor of
the Perl area, so please feel free to direct complaints or suggestions
my way. Let's make this a high-quality resource!
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Fri, 12 Jun 1998 16:19:21 -0500
From: Deva Seetharam <psdspss@execpc.com>
Subject: Re: goto in Perl debugger?
Message-Id: <35819B59.4113F0E4@execpc.com>
Tim Morse wrote:
> Is there a 'goto <linenumber>'-like command for the perl debugger?
> I'd like to be able to change the flow of control when I debug
> my perl scripts but can't figure out how to do it.
>
> I can't find any likely commands in the debugger and I've looked
> at the FAQs and newsgroup archives with no luck. It seems like
> I must be missing something obvious. Any help would be appreciated,
> thanks.
>
> Tim Morse
what about c [line] ?
Have a look at Camel book's Chapter 8 ["Other Oddments"].
Hope this helps.
------------------------------
Date: 12 Jun 1998 23:36:33 +0200
From: David Kastrup <dak@mailhost.neuroinformatik.ruhr-uni-bochum.de>
Subject: Re: Have we got a good free Perl manual?
Message-Id: <m290n2nvz2.fsf@mailhost.neuroinformatik.ruhr-uni-bochum.de>
lehman@visi.com (Todd Lehman) writes:
> [dak:]
> >
> > This is nonsense. It is a loss to the community period. If they were
> > under some cosmic obligation, the community would not encounter any
> > loss because it could sue them for providing the stuff. As they are
> > not under an obligation, it is a loss to the community for good.
>
> Aren't you confusing loss with non-gain? Was the documentation sold
> to O'Reilly once freely available? If so, then you could consider it a
> loss. If not, then to call it a loss is to presume that it would have
> and should have been contributed to the community all along, and that is
> up to the authors and -no one- else.
No, that it *could* have been contributed to the community. Once you
have signed over your marketing rights exclusively to some publisher,
this option is gone.
--
David Kastrup Phone: +49-234-700-5570
Email: dak@neuroinformatik.ruhr-uni-bochum.de Fax: +49-234-709-4209
Institut f|r Neuroinformatik, Universitdtsstr. 150, 44780 Bochum, Germany
------------------------------
Date: Thu, 11 Jun 1998 16:51:30 -0600
From: "Eric Pan" <pan@part.net>
Subject: How do I limit the number of rows in sql query using Win32::ODBC?
Message-Id: <35805ef6.0@news.slc.bfp.net>
I have an ODBC connection to MS SQL Server and would like to retrieve the
first ten rows from the query result. Then, I would like be able to retrieve
the next 10.
Is this possible? Please help. Thanks.
------------------------------
Date: Fri, 12 Jun 1998 22:06:23 GMT
From: Bill Weede <alba@ix.netcom.com>
Subject: How do I make 'Active State PerlEx' Reload scripts?
Message-Id: <6ls8oo$mod@dfw-ixnews10.ix.netcom.com>
I am using Active State PerlEX on my NT server.
PerlEx pre-compiles Perl scripts and then stores them in memory so that the scripts are not
compiled again at each user request. (I don't really understand the benefits of this 'feature' for
one thing.) I can make each script 'reload' by using the command 'PerlEx::Reload' from within a
script. Although it's an easy solution for myself, I don't want my users to have to worry about
it.
How can I make it so that the scripts compile each time without the 'PerlEx::Reload' line having
to be put in each actual script?
Thank you for your help,
Bill
bill@steppenstones.com
------------------------------
Date: 12 Jun 1998 11:23:28 -0700
From: Tobias Hoellrich <thoellri@tobias.corp.adobe.com>
Subject: Re: I want threads, threads and more threads!
Message-Id: <yjzwwamv5r3.fsf@tobias.corp.adobe.com>
"Gabriele R. Fariello" <gabriele@kollwitz.doit.wisc.edu> writes:
> Here is what I came up with:
>
> 1) Open n number of child processes that do something, each with it's
> separately associated filehandle (so that STDIN of the child is printed to
^^^^^ you mean STDOUT - don't you?
> a filehandle that the parent has). This I can do, but I do not know which
> child will finish first, so in order to optimize this process, I have to
> check each file handle to see if there is anything to read, if not skip,
> if so, read, reap the child, close the filehandle, and spawn a new child
> if need be. And I have to be in a loop while doing this, so the main
> process is forced to stay in a loop until all the children die. I don't
> like the fact that I have to waste so much processing power on what will
> eventually be 5,000+ spawned children, having to check each filehandle
> (oh, by the way, I don't spawn 5,000 right away, I do 6 to 12 at a time
> and wait for output), and have the main process not do anything else
> (which it could be doing) until all the input has been gathered. So I no
> like this.
Sound like you want to take a look at IO::Select. Instead of
constantly checking for available data you just record all the
STDOUT-filehandles, add them to your set:
$s = IO::Select->new();
$s->add($some_handle);
and wait for data to become available:
@ready = $s->can_read($timeout);
Oh, you have to something else in your "main"? Well, the timeout
allows you wait only for a specified time and you can do something
else, if no data is available.
Make sure that you remove ($s->remove()) your child's filehandle for
the group, in case your child dies without having returned any
information (you have a SIGCHLD-handler in place, don't you?).
> 2) Open n number of children and have them all write to one file, use a
> sig handler (SIGCHLD) and each time a child finishes, read one line from
> the file. Problem: I don't know which child croaked, I just know that one
> passed away, and, well, can I be sure that if file output buffering is on,
> the children will not stomp all over each other's output in the file (e.g.
> at 0 milliseconds child A starts writing and at 1 ms child B does the same
> and I end up with "hello whoerllldo" or "hello hello world world" or
> something like that?) - (yes I could use flock, I suppose I should, so
> scratch that last one, but I'd still like to know). So will wait() reap
> the most recently died child, or will it wait for all children? Or is
> there a way to know the PID of the process that sent a SIGCHLD?
Yuck - don't do that unless you use file locking, you can (and I have)
run into situations where something like the "HHeelloo WWoorrlldd"
ends up in the output.
I've done the stuff mentioned under 1 for a (less than 15000 lines)
project and it works just fine.
Hope this helps
Tobias
------------------------------
Date: Fri, 12 Jun 1998 22:08:09 GMT
From: dgris@perrin.dimensional.com (Daniel Grisinger)
Subject: Re: Is this insane?
Message-Id: <6ls8f7$f62$1@perrin.dimensional.com>
In article <199806121531.XAA08685@opera.iinet.net.au>,
Steve Vertigan <steve@vertigan.iinet.net.au> wrote:
> It occurred to me that one way would be to compile the Perl code
>into C using the compiler and then to compile that C using the GNU compiler
>for win32.
Perhaps I'm missing something, but wouldn't it be easier to get the perl
source and just compile that with gcc for win32.
>--Steve
Daniel
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Fri, 12 Jun 1998 22:34:05 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: McCabe complexity analysis
Message-Id: <x1ig1.1042$bj2.4787653@ptah.visi.com>
Preston L. Bannister <preston@home.com> writes:
> In article <6ljrb5$6l1$3@justus.ecc.lu>, Stefaan.Eeckels@ecc.lu (Stefaan
> A Eeckels) wrote:
> > Why do even respected authors (and many more programming
> > standards documents) state that you should write (in 'C'):
> >
> > handle = fopen(file_name, mode);
> > if (handle == NULL) return -1;
>
> Actually I would recommend:
>
> handle = fopen(file_name, mode);
> if (NULL == handle) {
> return -1;
> }
Isn't it funny how disgusting C code can get sometimes?
You can't say
handle || return -1;
and you can't even say
return -1 if !handle;
and god help you if you want to write
(handle = fopen(file_name, mode)) || return -1;
Long live Perl.
--Todd
------------------------------
Date: Fri, 12 Jun 1998 20:54:56 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: null value checking with numbers
Message-Id: <EuGI3K.9r9@news.boeing.com>
In article <6lrsu7$efg$1@news.ccit.arizona.edu>,
Irene Barg <barg@nickel.as.arizona.edu> wrote:
>Hello,
>
>I need to check if a numeric value is null (or not defined), but
>don't want to use 'defined' because I get unpredictable results.
>What I've tied is shown below:
>
>#!/home/sybase/bin/perl
>
># source the subroutines
>use lib '/home/sybase/bin';
>require "archive_subs.pl";
>
>$dt = "Dec 9 1997 7:41:39:000PM";
>$vallist = "";
>
>$value = matchfoc($dt);
>if ($value eq "ERR") {
> print "Error: rel focus = $value\n";
> exit(-1);
>}
>print "value = $value\n";
>
>if ($value == "") {
> $vallist .= "null,";
>} else {
> $vallist .= "$value,";
>}
>print "vallist = $vallist\n";
>exit(0);
>
>When I run 'test.pl', I get:
>
>value = 0
>vallist = null,
>
>In this case, zero is a valid value, but it still gets reset as 'null'.
>
Presuming $value gets set intially to "", why not just
use string comparison, i.e.,
if ($value eq "") {
$vallist .= "null,";
...
}
That way as soon as $value is set to a numeric
value, the string comparison will fail.
HTH,
--
Charles DeRykus
------------------------------
Date: Fri, 12 Jun 1998 17:27:40 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: pass the gravy and the hashref, please -- solved
Message-Id: <1daiqcw.1ohlf613qlptcN@slip166-72-108-197.ny.us.ibm.net>
Scott Englehart <sengle1@umbc.edu> wrote:
> But yet another problem.
>
> Why does this work:
>
> foreach $key (@keys){
> print $this->{'stopped_content'}->{$key};
> }
>
> But this:
>
> while ( ($k, $v) = each $this->{'stopped_content'}->{} ){
> print $v;
> }
>
>
> does not run:
>
> syntax error at STOP_COUNT.pm line 89, near "{}"
> BEGIN failed--compilation aborted at simple line 16.
while ( ($k, $v) = each %{$this->{'stopped_content'}} ){
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Fri, 12 Jun 98 20:47:15 GMT
From: JahanJ@yahoo.com (Jahan K. Jamshidi)
Subject: perl and NT Registrary access
Message-Id: <6ls48c$gho@rap.SanDiegoCA.NCR.COM>
I need to run a perl script to gather information about the NT status and its
registery values. Does anybody know how to access the registery values from
perl. I don't need to change any value, just read them and save them for
later diagnostics.
Thankx in advance. Please send your responses to
Jahan@pricecut.com
- J
------------------------------
Date: 12 Jun 1998 20:52:23 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Puzzle challenge
Message-Id: <6ls4e7$i9c$1@marina.cinenet.net>
Greg Bacon (gbacon@cs.uah.edu) wrote:
: In article <EuG1os.J04@ig.co.uk>,
: Tim.Bunce@ig.co.uk (Tim Bunce) (Tim Bunce) writes:
: : The problem is that the messengers quite often, say 70%, miss out one
: : or more names and occasionally, say 10%, get the order wrong.
:
: What if they all forget the same name? Doesn't the fact that this is
: possible make it impossible to recover the original list in all cases?
Ditto the ordering problem; if the original is (a b c d) and all but one
courier misremember it as (d a b c), while one gets it right, any
'rational' algorithm will decide that (d a b c) is correct. What this
really comes down to is:
1. Find the spanning set of all names mentioned.
2. Use a statistical analysis of the couriers'
reported orderings to order them.
Names forgotten by all couriers are guaranteed to be missing, and the
chance of this happening to any given name is
(chance of a courier forgetting a name)^N
and the ordering confidence is also based on the number of couriers and
the chance of a misordering error from each courier.
---------------------------------------------------------------------
| 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: 12 Jun 1998 21:30:31 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Puzzle challenge
Message-Id: <6ls6ln$dsl$1@news.NERO.NET>
In article <EuG1os.J04@ig.co.uk>,
Tim Bunce) (Tim Bunce <Tim.Bunce@ig.co.uk> wrote:
>The problem is that the messengers quite often, say 70%, miss out one
>or more names and occasionally, say 10%, get the order wrong.
If you're using the proper commands to run messengers from perl, but
the messengers don't cooperate, then it's the messengers' fault. If
you're not using the proper commands, then it's your fault. If you
aren't sure about the proper commands, you should read the messenger's
documentation. If you've read it and you're still not sure, you should
ask in a newsgroup about messengers.
Hope this helps!
------------------------------
Date: 12 Jun 1998 22:19:23 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Puzzle challenge
Message-Id: <6ls9hb$m6j@mozo.cc.purdue.edu>
Tim.Bunce@ig.co.uk (Tim Bunce) (Tim Bunce) writes:
}The problem is that the messengers quite often, say 70%, miss out one
}or more names and occasionally, say 10%, get the order wrong.
}Names are never added, repeated or changed, only missed or reordered.
}The messengers always think they've got it right.
} Original list: foo bar baz boo
} Messenger A says: foo bar boo
} Messenger B says: bar boo baz
} Messenger C says: foo bar baz boo
} Messenger D says: boo foo bar baz
} Messenger E says: foo bar baz
} Messenger F says: foo baz boo
Suggested algorithm:
Find the most common first element. It's the first.
Remove all occurences from the list.
Repeat until there's nothing left.
Confusing? Here's the example:
A says: foo bar boo
B says: bar boo baz
C says: foo bar baz boo
D says: boo foo bar baz
E says: foo bar baz
F says: foo baz boo
Most common first element? foo.
Now, the lists that remain are:
A says: bar boo
B says: bar boo baz
C says: bar baz boo
D says: boo bar baz
E says: bar baz
F says: baz boo
Most common first element? bar.
A says: boo
B says: boo baz
C says: baz boo
D says: boo baz
E says: baz
F says: baz boo
Whut-oh, ambiguity. But looking at the original data, I'm not sure
you have a better choice. Feel free to prove me wrong.
So, the original order is either (foo,bar,boo,baz) or
(foo,bar,baz,boo).
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: 12 Jun 1998 16:55:00 -0600
From: Nathan Torkington <gnat@frii.com>
Subject: Re: Puzzle challenge
Message-Id: <5qsola6xiz.fsf@prometheus.frii.com>
Tim.Bunce@ig.co.uk (Tim Bunce) (Tim Bunce) writes:
> The problem is to find the full list of names and the original order.
You INSTALL a FULL SET OF TOOLS, like THE LORD GOD ALMIGHTY intended.
REPENT, ye PRISONER of BILL! The DAY of JUDGEMENT is AT PERL! Your
MESSENGERS are obviously just POOR substitutes for RELIABLE PIPE
COMMUNICATION which you'd have if you had a REAL OPERATING SYSTEM
and not a SCURRILOUS PIECE OF TOOL-CHALLENGED COPROPHILIA!
Tom^WNat
:-)
------------------------------
Date: Fri, 12 Jun 1998 16:22:39 -0500
From: "Vincent M. Probasco" <probavm@cat.com>
Subject: Re: Recursive help
Message-Id: <35819C1E.3EDFCB96@cat.com>
Christian try to think through this...
You want to output the "test start" before you call the recursive
function. Then read in and output
the "test end" after the recursive function call.
HTH
vince
------------------------------
Date: Fri, 12 Jun 1998 17:27:45 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Recursive help
Message-Id: <1daiqqo.1bs0mb81plmtd8N@slip166-72-108-197.ny.us.ibm.net>
Cristian Pavel <cpavel@nortel.ca> wrote:
> sub PrintInterface
> {
> my ($buffer, $line, $type);
>
> unless(open(INPUT, "< $_[0]"))
> {
> print "Cannot open $_[0] file: $!";
> exit;
> }
You need to localize the filehandle:
sub PrintInterface
{
my ($buffer, $line, $type);
local *INPUT;
unless(open(INPUT, "< $_[0]"))
{
print "Cannot open $_[0] file: $!";
exit;
}
Also, instead of unless, print & exit, you should use or & die:
open INPUT, "< $_[0]" or die "Can't open $_[0]: $!";
Here is my version of your program:
#!/usr/bin/perl -w
use strict;
PrintInterface('recursive.1');
print "Done\n";
sub PrintInterface {
my ($file) = @_;
local *INPUT;
open INPUT, "< $file" or die "Can't open $file: $!";
while (<INPUT>) {
chomp;
my ($type, $buffer) = /^(.),(.*)$/;
# type: t - text line; f - file name
if ($type eq 'f') {
PrintInterface($buffer);
} else {
print "$buffer\n";
}
}
close INPUT;
}
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Fri, 12 Jun 1998 15:08:56 -0500
From: Deva Seetharam <psdspss@execpc.com>
Subject: Re: Regex Help!
Message-Id: <35818AD8.2DA750BA@execpc.com>
Jim Bowlin wrote:
> clay@crawlspace.com wrote:
> >
> > Hello --
> >
> > I could use some help with a regex that's kicking my inexperienced butt ...
> > Here's some sample input:
> >
> > Database: mysql
> > +--------+
> > | Tables |
> > +--------+
> > | db |
> > | func |
> > | host |
> > | user |
> > +--------+
> >
> > Database: dngr
> > +-------------+
> > | Tables |
> > +-------------+
> > | dngr_comics |
> > | dngr_images |
> > | dngr_links |
> > | dngr_rev |
> > | poll |
> > +-------------+
> >
> > Database: hotdogs
> > +---------------------+
> > | Tables |
> > +---------------------+
> > | hotdogs_with_cheese |
> > | mustard_dogs |
> > | relish_dogs |
> > +---------------------+
> >
> > I've got an array containing all these lines (fed in from a mysqlshow
> > command), and I need to get rid if all pipe characters, blank spaces, plus
> > and dash symbols and the word "Tables" ... so that I'm left with only the
> > table names.
> >
> > Also, I don't want the "Database: <name>" line either. The amount of white
> > space varies depending on the output, as shown in the examples ..
> >
> > Can anyone lend a hand on this? So far, I've got this going:
> >
> > $tab =~ s/^....[ \-].*//g;
> > $tab =~ s/ [\|] //g;
> > $tab =~ s/[*\|]//g;
> > $tab =~ s/\s//g;
> >
> > But, that's not working. : ) It's getting rid of most pipes, but leaving a
> > mess behind.
>
> Assuming @text contains the lines, this will fill @out with
> what you want.
>
> my @out;
> foreach (@text) {
> tr/[a-zA-Z0-9_://dcs;
> !$_ or /^Database:/ or /^Tables$/ or push @out, $_;
> }
>
> HTH -- Jim Bowlin
Nothing really significant.
I guess Jim Bowlin made a typo in tr.
It should have a closing "]".
So, it would be
tr/[a-zA-Z0-9_:]//dcs;
Deva
------------------------------
Date: Fri, 12 Jun 1998 17:29:42 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Regex Help!
Message-Id: <35819DC6.260E1D14@negia.net>
Deva Seetharam wrote:
>
> Jim Bowlin wrote:
>
> > clay@crawlspace.com wrote:
> > >
> > > Hello --
> > >
> > > I could use some help with a regex that's kicking my inexperienced butt ...
> > > Here's some sample input:
> > >
> > > Database: mysql
> > > +--------+
> > > | Tables |
> > > +--------+
> > > | db |
> > > | func |
> > > | host |
> > > | user |
> > > +--------+
[snip]
> >
> > Assuming @text contains the lines, this will fill @out with
> > what you want.
> >
> > my @out;
> > foreach (@text) {
> > tr/[a-zA-Z0-9_://dcs;
> > !$_ or /^Database:/ or /^Tables$/ or push @out, $_;
> > }
> >
> > HTH -- Jim Bowlin
>
> Nothing really significant.
>
> I guess Jim Bowlin made a typo in tr.
> It should have a closing "]".
> So, it would be
> tr/[a-zA-Z0-9_:]//dcs;
actually, i don't even think he needed the first square bracket.
remember, 'tr' does not operate with regexes. so specifying a
character class is not needed.
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: 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 2860
**************************************