[18268] in Perl-Users-Digest
Perl-Users Digest, Issue: 436 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 7 14:10:46 2001
Date: Wed, 7 Mar 2001 11:10:25 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983992224-v10-i436@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Mar 2001 Volume: 10 Number: 436
Today's topics:
print abstract ('blah'); # subroutine or file handle? (EED)
Re: print abstract ('blah'); # subroutine or file handl (Rafael Garcia-Suarez)
Re: print abstract ('blah'); # subroutine or file handl (Tad McClellan)
Re: Regex help required <bart.lateur@skynet.be>
Regex to quote XML attributes? (Jesse Sheidlower)
Regexp matching between <tags> content </tags> <tag@gmx.de>
Re: Regular Expression Syntax Checking nobull@mail.com
Re: RFC: FAQ3 update -- Using less memory <mjcarman@home.com>
Re: RFC: FAQ3 update -- Using less memory <dan@tuatha.sidhe.org>
Re: RFC: FAQ3 update -- Using less memory <bart.lateur@skynet.be>
Set Passwords on AIX <wessner@hps.fzk.de>
Re: Set Socket to TCP_NODELAY <mischief@velma.motion.net>
Socket and fork problem <alan.carter@flytxt.com>
Re: Some keys don't work in debugger (EED)
Re: Some keys don't work in debugger <dimitrio@perlnow.com>
Time Conversion <sylvie.noel@crc.ca>
Re: Time Conversion <godzilla@stomp.stomp.tokyo>
Re: Time Conversion nobull@mail.com
Re: Use PERL or Java? Which is faster? <djberge@uswest.com>
Re: What's wrong with (remedial)... (Anno Siegel)
Re: What's wrong with (remedial)... (Logan Shaw)
Re: What's wrong with (remedial)... (Anno Siegel)
Re: why won't "format FILEHANDLE" work?? <administrator@playauction.com>
word boundary example <plusc@freeserve.net>
Re: word boundary example (Anno Siegel)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Mar 2001 16:25:20 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: print abstract ('blah'); # subroutine or file handle?
Message-Id: <3AA652E0.5C238E5C@eed.ericsson.se>
Hi,
I've this question actually since so long
time, that I am already used to write:
print &abstract ('blah');
if I have a subroutine called "abstract"...
But if I omit the &, will perl see it as
subroutine name of as file handle? Like:
print abstract ('blah');
Regards
Alex
------------------------------
Date: Wed, 07 Mar 2001 15:36:39 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: print abstract ('blah'); # subroutine or file handle?
Message-Id: <slrn9aclbq.tqb.rgarciasuarez@rafael.kazibao.net>
Alexander Farber (EED) wrote in comp.lang.perl.misc:
> Hi,
>
> I've this question actually since so long
> time, that I am already used to write:
>
> print &abstract ('blah');
>
> if I have a subroutine called "abstract"...
>
> But if I omit the &, will perl see it as
> subroutine name of as file handle? Like:
>
> print abstract ('blah');
Just try it :
$ perl -Mstrict -wle 'sub STDOUT {$_[0]+1} print STDOUT 1'
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 07 Mar 2001 15:42:51 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: print abstract ('blah'); # subroutine or file handle?
Message-Id: <slrn9aciio.9t4.tadmc@tadmc26.august.net>
Alexander Farber (EED) <eedalf@eed.ericsson.se> wrote:
>
>I've this question actually since so long
>time, that I am already used to write:
>
> print &abstract ('blah');
>
>if I have a subroutine called "abstract"...
>
>But if I omit the &, will perl see it as
>subroutine name of as file handle? Like:
>
> print abstract ('blah');
The problem occurs because at this point in the parsing, perl
does not know of any subroutine named 'abstract'. If it did
know that you would be defining such a subroutine, then it
would do the Right Thing.
Solutions (besides using an ampersand in the call):
1) print abstract('blah'); # using "print LIST" form since a sub
# call cannot "fit" in the FILEHANDLE spot
2) move the subroutine definition before the print()
sub abstract { ... };
print abstract ('blah');
3) add a forward declaration for sub abstract:
sub abstract;
print abstract ('blah');
sub abstract { ... };
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 07 Mar 2001 18:58:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex help required
Message-Id: <7l0dat4pjo6n0at246muoma01njfp94q6e@4ax.com>
Maggie Simpson wrote:
>I've been playing around with regex's but am still having difficulty
>achieving exactly what I
>want to do. Any helpful comments would be appreciated.
>
>What I want to do is, given a string, remove certain parts of it - but the
>middle parts of the
>string will vary each time, and there will usually be more than one removal
>required. The middle
>parts (the bits that vary) will also be of different lengths.
>
>eg:
>Imagine I have the following string:
>
>"djagdajxdvAJLDKJDHGAK193731DAD - <A
>HREF=domain.com\dir\XXXXXX>STATIC</A> - bdsk
>hdakidhaodq9eyu8o- <A HREF=domain.com\dir\YYYYY>STATIC</A> - END
>OF STRING"
>
>where I need to remove all occurences of "- <A
>HREF=domain.com\dir\?????>STATIC</A> -"
>where ????? is the part which will be different each time, but where the
>description, STATIC, will
>remain the same. ie, I want to end up with a string that looks like the one
>below:
>
>"djagdajxdvAJLDKJDHGAK193731DAD bdsk hdakidhaodq9eyu8o END OF STRING"
It looks to me as rougly, you want to convert HTML to plain text. Use a
module that properly processes HTMl for you, such as HTML::Parser. For
example:
use HTML::TokeParser;
my $p = HTML::TokeParser->new(\$text);
while(my $t = $p->get_token) {
print $t->[-1] if $t->[0] eq 'T';
}
--
Bart.
------------------------------
Date: 7 Mar 2001 12:32:30 -0500
From: jester@panix.com (Jesse Sheidlower)
Subject: Regex to quote XML attributes?
Message-Id: <985rbe$618$1@panix2.panix.com>
I have a lot of data in a flavor of SGML that I need to convert
to XML so I can process it with XML::Parser. Most of the
discrepancies are trivial, and I've been able to deal with them
(for instance, the original uses "." instead of ";" as the
terminator for entity references, so I used "s/(&\w+)./\1;/g;").
But I'm having some trouble with the attributes; the original
doesn't ever quote them, so a tag could be:
<e date=2001 changed=no id=2938223>, and I need this to be
<e date="2001" changed="no" id="2938223"> or XML::Parser chokes
on it.
I've tried a few different things, and every one has either
missed some attributes or has scattered quotation marks with
abandon throughout my data. Can someone suggest a solution?
Thanks.
Jesse Sheidlower
<jester@panix.com>
------------------------------
Date: Wed, 07 Mar 2001 18:51:47 +0100
From: Toni <tag@gmx.de>
Subject: Regexp matching between <tags> content </tags>
Message-Id: <3AA67533.2F6D8B6@gmx.de>
Hy everybody,
I am trying hard to find a regexp for a CGI that matches all the
stuff between my two tags <!-- #myinclude --> and
<!-- #myincludeEnd --> . The Problem is, that it should really match
ANYTHING between those two tags, including umlauts like öäüÖÄÜß
or special characters like ,.-_#<>[]{/)\ and so on.
At first i thought this would do:
$content=~/\Q<!-- #myinclude -->\E([^<]*)\Q<!-- #myincludeEnd -->\E/mgi;
But I want <'s also to be allowed between my two tags,
so I started putting anything into my match class like this:
$content=~/\Q<!-- #myinclude
-->\E([\s\d\w\.\ä\ö\ü\Ä\Ö\Ü\ß\:\;\\]*)\Q<!-- #myincludeEnd -->\E/mgi;
But this is obviously not the best way to do it, is it ?
Do you perhaps have a clever idea how to do it ?
Thanks in advance !
Toni.
------------------------------
Date: 07 Mar 2001 17:41:33 +0000
From: nobull@mail.com
Subject: Re: Regular Expression Syntax Checking
Message-Id: <u9ofvdxyr6.fsf@wcl-l.bham.ac.uk>
"John A. Parker" <jap54@cornell.edu> writes:
> Because of the problems inherent in capturing string representations
> of regular expressions without actually treating them as such during
> the creation process, I had to resort to very ugly, temporary
> character translations,
Why the artifical constraint? Why not simply pass the string to the
built-in regular expression compiler and use eval {} to catch
exceptions.
sub is_a_valid_regex ($) { !! eval { qr/$_[0]/ } }
Or if you are on pre 5.5 (does anyone still use pre 5.5 ?) where you
don't have qr//
sub is_a_valid_regex ($) { eval { '' =~ /$_[0]/; 1 } }
> - "Package" the string so the process of passing from point to
> point and into and out of flat files can be done without the string
> being evaluated?
This is not usually an issue. Please show specimen code that suffers
from the above problem.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 07 Mar 2001 07:53:55 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <3AA63D73.F28D5BD0@home.com>
Ilmari Karonen wrote:
>
> In article <3AA56BEC.A7F9F0CD@home.com>, Michael Carman wrote:
>>
>> =item * Consider using C<eval BLOCK>
>>
>> If you need to initialize a large variable in your code, you
>> might consider doing it with an eval statement like this:
>>
>> my $large_string = eval ' "a" x 5_000_000 ';
>
> Hmm.. surely that's C<eval EXPR> rather than C<eval BLOCK>?
Oops, I said BLOCK because I was thinking to use the compile at
compile-time form instead of compile at runtime; never mind what the
example showed. :) Since one probably can't generalize to say that the
BLOCK form is always feasible I'll change the header to say simply
C<eval>.
-mjc
------------------------------
Date: Wed, 07 Mar 2001 16:02:59 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <TYsp6.13828$Ok4.1898117@news1.rdc1.ct.home.com>
In comp.lang.perl.moderated Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> undef()'ing a
> _large_ variable usually (1) causes perl to return the memory to the OS.
This is entirely dependent on your OSes memory allocator, if you're using
it. Memory will get returned on some systems in some circumstances,
generally depending on how the memory was allocated in the first place.
glibc, particularly, seems to use mmap() to get a chunk of memory in
some circumstances, and when you release a segment that was allocated
in this way it gets unmapped. (And no, I'm not sure of the size, nor
of the vintage of glibc needed for this) The Mac port of perl will
do the same thing, as will the VMS port. (Both depending on the
circumstance of the original allocations)
Ilya can chime in on whether you'll see this if you're using perl's
memory allocator or not, as I'm not certain if it ever releases
memory back to the OS.
Dan
------------------------------
Date: Wed, 07 Mar 2001 16:25:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <r1ocat4h72o70amvoff173cqopvtp4ktcm@4ax.com>
Dan Sugalski wrote:
>glibc, particularly, seems to use mmap() to get a chunk of memory in
>some circumstances, and when you release a segment that was allocated
>in this way it gets unmapped. (And no, I'm not sure of the size, nor
>of the vintage of glibc needed for this) The Mac port of perl will
>do the same thing
Heh? Maybe you're talking about the LWP tool, I'm not familiar with
those, but on an ordinary Mac, applications NEVER request more memory
from the OS, and they NEVER give anything back either, during their
life. All apps have a memory preference set, and they get a certain
amount of memory at startup, and that they have to get by with for the
rest of their life. All memory allocations and frees are within the
scope of this chunk. The Finder (OS with GUI) is the only exception to
this rule.
--
Bart.
------------------------------
Date: Wed, 07 Mar 2001 15:36:18 -0800
From: Dirk Wessner <wessner@hps.fzk.de>
Subject: Set Passwords on AIX
Message-Id: <3AA6C5F1.7F06F4A6@hps.fzk.de>
Hello there.
I know there is a module Unix::ConfigFile,
which provides Access to /etc/passwd,
/etc/group etc.
I modified it to work with /etc/shadow.
Does anyone know a module or library
to alter the passwords on Unix-Systems
that doesn't use the File /etc/shadow,
i.e. IBM-AIX and HP-UX?
Any Hints will be usefull!
Thanks a lot,
Dirk Wessner
------------------------------
Date: Wed, 07 Mar 2001 18:59:29 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Set Socket to TCP_NODELAY
Message-Id: <tad18havd38bb7@corp.supernews.com>
Heiko Brandhorst <Heiko.Brandhorst@gmx.de> wrote:
> Hallo,
> I use linux 7.0 and have some problems with a tcp server socket.
> I want to send many small messages (40 Bytes) to a Client without delay.
Wow, and I thought Linux 2.4 was recent!
> But the Socket is collecting the messages up to the socket's buffer size
> send them delayed.
> I cannot switch off the Nagel-Algorithm which is responsible for that.
> I tried:
> setsockopt <Socket>, SOL_SOCKET, 1, pack( "l", 1);
> setsockopt <Socket>, 0, 1, pack("l", 1); // for SOL_IP but
> not defined
> setsockopt <Socket> , 6, 1, pack("l", 1); // for SOL_TCP but
> not defined
> setsockopt <Socket>, SOL_SOCKET, SO_SNDBUF, pack("l", 40);
I don't see you trying to use `NO_DELAY' as a textual constant
in your calls to setsockopt. It's not een really clear to me
whether Perl's socket() goes to socket(2) or socket(7), but I'd
bet tha tit maps to socket(7). In the man page (on RedHat 6.2
anyway) for tcp(7), it says to use the textual constants.
If you haven't tried that, it may help. If you have tried it,
that wasn't clear to me from your post. I hope this helps, but
I'm not sure it will.
Chris
--
Christopher E. Stith
The purpose of a language is not to help you learn the
language, but to help you learn other things by using the
language. --Larry Wall, The Culture of Perl, August 1997
------------------------------
Date: Wed, 7 Mar 2001 17:38:27 -0000
From: "Alan Carter" <alan.carter@flytxt.com>
Subject: Socket and fork problem
Message-Id: <5hup6.347$jo4.1634@news.uk.colt.net>
Hi Peeps.
This is a section of code from a server I am writting. To put it simply. I
have a client program (written in C) that is executed 10's of times a
second. This program connects to the socket of my server and relays
parameters from a thirdparty application to the server (which then does
various things and eventualy stores this all in a dbase...).
That is it the client does nothing but that.!!!
The problem I am having is speed!
I need the client program to exit as soon as the server has received the
data from it, so that the other third party program is released in good
time.
The bottle-neck i am getting is around this section of code where the server
forks off to allow another connection.
I am not getting good enough performance here. I can runn about 7 clients a
second. I need to double that.
The really confuseing thing is that if i put a statement "sleep 1;" after
the line that reads "next unless my $connection = $listen_socket->accept;"
the clients execution time halfs????????????
ie.. It does what its supposed to do that is exit as soon as the server has
received the data..
I am useing IO::Socket but got the same results with the old style useing
bind etc...........
Please help me.........
I found this hard to describe I hope i have provided enough info.
(With this code I can handle 7 client connections per second ; Uncommenting
the sleep statement produced double the connection rate.)
while (!$quit) {
next unless my $connection = $listen_socket->accept;
#sleep 1;
my $inbound = <$connection>;
$connection->close;
die "Can't fork: $!" unless defined (my $child = fork());
if ($child ==0) {
$listen_socket->close;
my $rtrn = do_stuff($inbound, $dbh);
if ($rtrn == 1) {print "euck!! that didnt work\n";}
exit 0;
}
}
------------------------------
Date: Wed, 07 Mar 2001 16:27:23 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Some keys don't work in debugger
Message-Id: <3AA6535B.D2EFCAD4@eed.ericsson.se>
Dimitri Ostapenko wrote:
>
> Arrow keys don't work in debugger in latest Mandrake or debian and I can't
> figure why. I tried different TERM settings to no avail. Would it be 8 bit
> support?
>
> Can anybody help?
Maybe you have to install Term::Readline or some similar module -
it has helped me. I also can type Russian letters in it, but I
think it is more related to the xterm version which you are using
------------------------------
Date: Wed, 07 Mar 2001 11:18:23 -0500
From: Dimitri Ostapenko <dimitrio@perlnow.com>
Subject: Re: Some keys don't work in debugger
Message-Id: <3AA65F4F.FB26EF41@perlnow.com>
"Alexander Farber (EED)" wrote:
>
> Dimitri Ostapenko wrote:
> >
> > Arrow keys don't work in debugger in latest Mandrake or debian and I can't
> > figure why. I tried different TERM settings to no avail. Would it be 8 bit
> > support?
> >
> > Can anybody help?
>
> Maybe you have to install Term::Readline or some similar module -
> it has helped me. I also can type Russian letters in it, but I
> think it is more related to the xterm version which you are using
Thanks for the tip, I'll try it. Though I think it's term settings.
Tried all terms including xterm, gterm , eterm.. Also tried different
'TERM' settings including 'vt100', 'linux', 'xterm'.
I run Mandrake 7.2 and Debian potato with latest XF86 and all the other
good stuff.
Thing is it works on our devel machine at work, which is old redhat
--
Dimitri Ostapenko
------------------------------
Date: Wed, 07 Mar 2001 10:23:42 -0500
From: Sylvie <sylvie.noel@crc.ca>
Subject: Time Conversion
Message-Id: <3AA6527E.99EF9591@crc.ca>
Is it possible to convert human-readable time information (day, month,
year, etc.) back to the machine version?
I know you can use localtime to go from the machine's time to something
people can read, but I want to do the opposite.
I need to specify a starting date and an ending date to extract
information from a file. I have both types of date information (machine
and human-readable), and it seems a lot simpler to use the (machine)
numbers than the (human) text.
Thanks,
Sylvie
------------------------------
Date: Wed, 07 Mar 2001 09:56:05 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Time Conversion
Message-Id: <3AA67635.5EAB6F87@stomp.stomp.tokyo>
Sylvie wrote:
> Is it possible to convert human-readable time information
> (day, month, year, etc.) back to the machine version?
Semantically, no. Your "machine version" or more commonly called
machine language is not usually accessible to users. However,
you can access a local machine's user output in Epoch Seconds.
> I know you can use localtime to go from the machine's time to
> something people can read, but I want to do the opposite.
Then do so.
> I need to specify a starting date and an ending date to extract
> information from a file. I have both types of date information
> (machine and human-readable), and it seems a lot simpler to use
> the (machine) numbers than the (human) text.
You personally, do not have machine readable data. You only
have user-end data available, produced from machine language.
There are none whom can provide you with code to accomplish
your task. You have neglected to state clear parameters such
as your date / time format.
A module written by an unknown author, time.pm, is available.
It is one of very few modules which is relatively well commented
and documented. This module will convert set date formats to
Epoch Seconds. Comparing Epoch Seconds will accomplish your
task quite handsomely, in conjunction with this time.pm module.
This module and documentation for this module are available
at CPAN and mirror sites:
http://www.perl.com/CPAN-local/README.html
You will encounter a serious problem at CPAN. Finding this
module and associated documentation at CPAN may take you an
hour or more. CPAN is an extremely difficult site to negotiate.
Almost all of your search terms will yield no results. Patience
will prevail in the final outcome. A general internet search
via a search engine such as Altavista, will yield results
much quicker.
Writing your own code is a viable option as well. Relatively
simple math is involved in converting any given date to
Epoch Seconds. Nonetheless, this is a rare exception when
I will suggest using a module to accomplish a given task.
Use of this module, writing your own code, there is no
significant difference save for use of this module will
reduce your invested time and effort.
Your excessive use of parenthetical statements is unwarranted
and a violation of Writing Mechanics. You should only use
parenthetical statements to note brief topic digression.
This bad habit seems a rather popular one; I read literally
hundreds of others, using your exact parenthetical style.
Quite the coincidence, I say.
Godzilla!
------------------------------
Date: 07 Mar 2001 17:40:53 +0000
From: nobull@mail.com
Subject: Re: Time Conversion
Message-Id: <u9puftxysa.fsf@wcl-l.bham.ac.uk>
Sylvie <sylvie.noel@crc.ca> writes:
> Is it possible to convert human-readable time information (day, month,
> year, etc.) back to the machine version?
Yes there are modules on CPAN that do this. Finding them is left as
an exercise for the reader.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 07 Mar 2001 08:38:48 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <3AA647F8.D5CB404E@uswest.com>
Harri Haataja wrote:
> Terrence Brannon wrote:
> >Kenny Pearce <kenny@kennypearce.net> writes:
> >
> >> actually, I just recently read the article at Perl.com on gtk+ programming in
> >> Perl. I didn't know until I read it that you could make GUIs in perl! now that I
> >> know this, I'm not sure I'll use Java for anything other than web applets.
> >
> >But think about Perl/Tk instead of gtk+. More stable and what you
> >learn will allow you to use Tk on multiple programming languages.
>
> I have been recently wondering on what UI could I use with the perl things
> I keep as pets. =)
>
> GTK is nice and looks good and all but is an absolute pig when used over a
> network. I also don't want to use/learn/install tk. I'm looking at Motif
> (cpan: X11) now as that would seem appropriate for the sparc/HP environment.
>
> Any other views?
>
> --
> Life -- Story by Kafka, illustration by Dali
Motif? If you like writing 2-3 times as much code as you would in Java or Tk, sure
it's nice. I'll sell you my O'Reilly Motif books - cheap.
As for speed, I have *yet* to see a Java app that was as fast or faster than Perl/Tk,
or Perl in general for that matter.
Just my .02.
Regards,
Daniel Berger
------------------------------
Date: 7 Mar 2001 17:21:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What's wrong with (remedial)...
Message-Id: <985qni$9mc$3@mamenchi.zrz.TU-Berlin.DE>
According to Peter L. Berghold <peter@uboat.berghold.net>:
> On Tue, 6 Mar 2001 10:28:15 -0800,
> Brandon Thornburg <centreman_19@yahoo.com> wrote:
> >if ($in{degree1} ne "B.S."||"B.A."||"A.A."||"A.S.") {
>
> That just plain ain't gonna work....
>
> Try this instead:
>
> my %degList = (
> 'B.S.' => 1,
> 'B.A.' => 1,
> 'A.A.' => 1,
> 'A.S.' => 1
> );
>
> if ( $degList{$in{$degree1}} ) {
> --- whatever....
>
>
> There are probably (no doubt) more clever ways of doing this, but that
> is the first method that popped into my head....
A more minimalistic way of doing this is to use only the exist()ence
of the hash keys and use undefined values where you have 1s. This also
makes the code more concise:
my %deglist{ qw( B.S. B.A. A.A. A.S.)} = ();
if ( exists $deglist{ $in{ $degree1}} ) { ...
Anno
------------------------------
Date: 7 Mar 2001 11:46:40 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: What's wrong with (remedial)...
Message-Id: <985s60$npv$1@boomer.cs.utexas.edu>
In article <985qni$9mc$3@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>A more minimalistic way of doing this is to use only the exist()ence
>of the hash keys and use undefined values where you have 1s. This also
>makes the code more concise:
>
> my %deglist{ qw( B.S. B.A. A.A. A.S.)} = ();
> if ( exists $deglist{ $in{ $degree1}} ) { ...
True, but if you are testing things to see if they're in %deglist in
numerous places, then you can make it more concise by making the
definition a little more complicated and eliminating the "exists" from
all those other places:
my %deglist = map (($_ => 1), qw{ B.S. B.A. A.A. A.S. });
if ( $deglist{ $in{ $degree } }) { ...
- Logan
--
my your his her our their *its*
I'm you're he's she's we're they're *it's*
------------------------------
Date: 7 Mar 2001 18:10:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What's wrong with (remedial)...
Message-Id: <985tj7$9mc$4@mamenchi.zrz.TU-Berlin.DE>
According to Logan Shaw <logan@cs.utexas.edu>:
[hashes as sets of strings]
> True, but if you are testing things to see if they're in %deglist in
> numerous places, then you can make it more concise by making the
> definition a little more complicated and eliminating the "exists" from
> all those other places:
>
> my %deglist = map (($_ => 1), qw{ B.S. B.A. A.A. A.S. });
Ah, good way to initialize the beast with the list of keys appearing
in only one place.
> if ( $deglist{ $in{ $degree } }) { ...
Yes, that's preferable if you use it often, or when the place you
use it is cluttered. I never thought of map in this context. Nice
to have an alternative.
Anno
------------------------------
Date: Wed, 07 Mar 2001 17:04:32 GMT
From: "David Charles" <administrator@playauction.com>
Subject: Re: why won't "format FILEHANDLE" work??
Message-Id: <AStp6.328601$Pm2.4838258@news20.bellglobal.com>
Hello,
Thanks for everyone's help. I have cleaned it up a LOT, but still cannot
get it to work; Here is what it looks like now:
--==START OF CODE SNIPPET==--
$answer = "n";
while ($answer ne "y") {
system('cls');
print "Please enter the series: ";
chomp($series_name = uc(<STDIN>));
print "You entered Series: $series_name\n";
print "Press \"Y\" if this correct, or any other key to reenter the series:
";
chomp($answer = lc(<STDIN>));
}
open SERIES, "<d:\\aReport\\$series_name.txt" or die "Can't open
$series_name data file: $!";
while (<SERIES>) {
($style, @inventory) = split(/;/, $_);
$dat{$style} = "\n" . join("\n", @inventory);
}
$pic =
'@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n';
$format_declaration = "format REPORT =\n";
foreach $key (sort keys %dat) {
$output = $output
. $pic
. $key
. $dat{$key}
. "\n";
}
$ctime = localtime(time);
open REPORT, ">d:\\aReport\\print$series_name.txt" or die "Can't create
report: $!";
format REPORT_TOP =
#2345678901234567890123456789012345678901234567890123456789012345
@<<<<<<<<<<<<<<<<<<<<<<<< @||||| Page: @>>>>>
$ctime, $series_name, $%
-----------------------------------------------------------------
.
eval $format_declaration . $output . ".";
$^ = REPORT_TOP;
$~ = REPORT;
write REPORT;
close REPORT;
--==END OF CODE SNIPPET==--
Here is a few lines from an input file (named eps.txt where EPS is the
$series_name), in case anyone sees a problem with the way I am handling it:
--==START OF INPUT SNIPPET==--
024;144185
031;144106;144124
039;144118;144123;144200
052;144172;144201
054;144176;144211
055;144102;144188
077;144181
078;144125;144189
115;144107;144134
118;144159;144206
648B;144164
651B;144110;144166
--==END OF INPUT SNIPPET==--
This now at leasts prints some of the output to the file, but it isn't
formatted the way I (think I) coded it to; It should be coming out like so:
[header prints here]
024
144185
031
144106
144124
052
144172
144201
....etc...etc..
but instead it is coming out like this:
[header prints properly here]
144125 \n024
144106 \n031
144124
144172 \n052
144201
...etc...etc...
As you can see, it is printing it backwards (kind of) when there is only 1
inventory number (the 6 digit numbers after the first semicolon in the input
file), by printing the inventory number first, then (and this I REALLY don't
understand) printing the style number (the 3 digit + 1 optional letter
number that is that comes before the first semicolon in the input file)
AFTER the end of the header (which is the same length as the "picture" lines
in the format) with a "\n" prepended (having NOT been interpolated for some
reason, even though all the others were!).
I feel like my mind is going to mush. PLEASE HELP ME!!! If you know what I
am doing wrong here, please point it out! If you know of an easier way to do
it (a la TIMTOWTDI), PLEASE TELL ME!!
Thanks again to everyone who has helped,
David Charles
"Charles K. Clarkson" <c_clarkson@hotmail.com> wrote in message
news:778BD127A519EDEE.DFC3A3442DB72C2B.C8D2C1707F84E7A9@lp.airnews.net...
> David Charles <administrator@playauction.com> wrote
> : --==START OF CODE SNIPPET==--
> [SNIP]
> : sort keys %dat;
> BTW, What do you think this line does?
>
> [MORE SNIPPAGE]
> : $^ = REPORT_TOP;
> : $~ = REPORT;
> : write;
> Change this line to
>
> write REPORT;
>
> : close outREPORT;
> : --==END OF CODE SNIPPET==--
>
>
> HTH,
> Charles K. Clarkson
>
>
>
------------------------------
Date: Wed, 7 Mar 2001 16:17:37 -0000
From: "francesca" <plusc@freeserve.net>
Subject: word boundary example
Message-Id: <985n0g$nn8$1@newsg4.svr.pol.co.uk>
Could someone please give me a simple code example
to demonstrate how this word boundary checker
will identify any words repeated. thanks
if (/(\b.+\b) \1/)
{
print "Found $1 repeated\n";
}
thanks
------------------------------
Date: 7 Mar 2001 16:32:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: word boundary example
Message-Id: <985nq1$9mc$2@mamenchi.zrz.TU-Berlin.DE>
According to francesca <plusc@freeserve.net>:
> Could someone please give me a simple code example
> to demonstrate how this word boundary checker
> will identify any words repeated. thanks
>
>
> if (/(\b.+\b) \1/)
> {
> print "Found $1 repeated\n";
> }
>
> thanks
Well, try it after
$_ = "This contains a word word repeated";
If you try
$_ = "This contains a word a word repeated";
you'll notice that it detects not only repeated words but repeated
phrases. Whether this is deliberate I don't know.
Anno
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V10 Issue 436
**************************************