[12273] in Perl-Users-Digest
Perl-Users Digest, Issue: 5872 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 3 11:07:25 1999
Date: Thu, 3 Jun 99 08:00:30 -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 Thu, 3 Jun 1999 Volume: 8 Number: 5872
Today's topics:
Re: [?] Where do Mail Robot warnings go? (Tad McClellan)
ANNOUNCE: per-function manpages <tchrist@mox.perl.com>
Re: bareface ratio <droby@copyright.com>
Re: Can anyone tell me what this command is? <gellyfish@gellyfish.com>
Re: Can anyone tell me what this command is? <tchrist@mox.perl.com>
Re: Can I do this with an "if" statement? <dms@rtp-bosch.com>
Re: Can Perl call C functions? <gellyfish@gellyfish.com>
Re: Concatenating variable names (Sam Holden)
Re: Concatenating variable names <tchrist@mox.perl.com>
Re: damn F@#$(*)@ unix (*%$#&!* pipes <tchrist@mox.perl.com>
Re: Detect the existence of a subroutine w/o calling it <Allan@due.net>
Re: Detect the existence of a subroutine w/o calling it <tchrist@mox.perl.com>
Re: Determining height and with of uploaded Graphic fil <fruffet@kaptech.com>
Re: Determining height and with of uploaded Graphic fil <gellyfish@gellyfish.com>
Re: File Reading problem... <gellyfish@gellyfish.com>
Form Values <technology@workmail.com>
Freelance Perl CGI application Writers skrana@my-deja.com
Re: Getting rid of blank lines <gellyfish@gellyfish.com>
Re: Getting rid of blank lines (Larry Rosler)
Re: Getting rid of blank lines <tchrist@mox.perl.com>
Re: Getting rid of blank lines (Tad McClellan)
Re: Help on process data in a file (Greg Bacon)
help: is there a easy way to send mail? <office@asc.nl>
Re: HELP: Regular Expressions <dgmdan@md-sites.com>
Re: HELP: Regular Expressions (Larry Rosler)
Re: HELP: Regular Expressions (Tad McClellan)
How to scramble (hide) my perl code ? <jean@laganiere.qc.ca>
Re: How to scramble (hide) my perl code ? (Greg Bacon)
Re: I pass an array to a subroutine, but that array is garthwebb@my-deja.com
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 3 Jun 1999 04:38:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [?] Where do Mail Robot warnings go?
Message-Id: <kue5j7.k0i.ln@magna.metronet.com>
Sergei Klimov (sergei_klimov@sierra.auriga.ru) wrote:
: Could you please teach me where to find warnings from e-mail robot?
We cannot tell you. It depends on your environment (_which_
e-mail robot, where does STDERR output go...).
: I wrote a script for processing incoming mail, and put
: "!/usr/bin/perl -w
: in its first line.
Perl will print the warnings to STDERR.
That is the answer to the Perl part of your problem.
: Now I would like to see those warnings but do not
: know where to find them. Please help.
You have a question about whatever "e-mail robot"
you are using, not about Perl.
i.e. Where does it send STDERR?
It is not a topic for the Perl newsgroup.
: I found answer neither in FAQ,
: nor in Camel and Llama books.
Because it is not a Perl question.
Where STDERR output goes is not controlled by perl.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Jun 1999 08:17:15 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: ANNOUNCE: per-function manpages
Message-Id: <37568e6b@cs.colorado.edu>
If you go to the What's New page at
http://language.perl.com/admin/whats_new.html
You'll see a link to split up pods plus their converted manpages for
all the functions in perlfunc. If you install these, say in,
/usr/local/perl/man/man3/
Then given the proper manpage, you can say:
man 3 split
These were created using the splitpod program included in the pod
subdirectory of the perl source kit, and then run through pod2man.
I don't understand why more people don't do this, but you should.
Some folks prefer a special extension, like 3pl, so they would
do something like
$ wget http://language.perl.com/misc/funcpods.tar.gz
$ tar zxf funcpods.tar.gz
$ cd FuncPods
$ cp *.man /usr/local/perl/man/man3/
$ cd /usr/local/perl/man/man3/
$ rename 's/man$/3pl/' *.man
--tom
--
Perle, plesaunte to prynces paye
To clanly clos in golde so clere,
Oute of oryent, I hardyly saye
Ne proued I neuer her precios pere.
------------------------------
Date: Wed, 02 Jun 1999 18:00:36 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: bareface ratio
Message-Id: <7j3rfu$pkq$1@nnrp1.deja.com>
In article <37543D13.109FD1C8@xli.com>,
Greg Bartels <gbartels@xli.com> wrote:
> just an interesting phenomenon I've noticed
> on newsgroups in general.
>
> bareface ratio:
>
> the number of people who respond
> to tell you your information is wrong
>
> versus
>
> the number of people who respond
> to your requests for information
> on the same topic.
>
> this seems to be about 3 (or more) to 1,
> depending on the topic.
>
We're just trying to keep a positive signal-to-noise ratio.
All those wrong answers tend to push it negative. Negative information,
you know.
;-)
> so, if you have a question, and no one
> is responding, you can still get the
> answer, all you have to do is make something
> up first (bareface it), and the
> corrections will flood in.
>
Your description:
Q1: How do I do X?
...long wait...no response
A1: To do X, use Y. (incorrect fake response from original querent).
A2: Wrong. use Z.
A3: Wrong. use Z.
...etc.
Better approach:
Q1: Can I use Y to do X?
A1: No. Use Z instead.
I think people are more likely to answer a question with an incorrect
proposed solution. I think this holds whether or not the incorrect
proposed solution was part of the original post or not. I have no
statistical evidence for my claim, but there you go...
I'd rather see the fake answer as part of the original post, so it at
least LOOKS like you've thought a bit yourself before posting. ;-)
--
Don Roby
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 3 Jun 1999 13:48:06 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Can anyone tell me what this command is?
Message-Id: <37567986@newsread3.dircon.co.uk>
reddogg1471@my-deja.com wrote:
> Can anyone tell me where I can find documentation on on this:
>
> GROK!THIS!
>
> I've run across this in scripts before and the attached files are
> always encoded somehow. I can't find documentation on this anywhere.
>
It is used in the perl source kit files as a string terminator in a
'here document' - generally when what is being printed out it is
another source file.
Makefile.SH:$spitshell >Makefile <<!GROK!THIS!
Makefile.SH:!GROK!THIS!
Makefile.SH: $spitshell >>Makefile <<!GROK!THIS!
Makefile.SH:!GROK!THIS!
Policy_sh.SH:$spitshell <<!GROK!THIS! >Policy.sh
Policy_sh.SH:!GROK!THIS!
Policy_sh.SH:$spitshell <<!GROK!THIS! >>Policy.sh
Policy_sh.SH:!GROK!THIS!
cflags.SH:$spitshell >cflags <<!GROK!THIS!
cflags.SH:!GROK!THIS!
config_h.SH:sed <<!GROK!THIS! >config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!'
-e 's!^#un-def!#undef!'
config_h.SH:!GROK!THIS!
makeaperl.SH:$spitshell >makeaperl <<!GROK!THIS!
makeaperl.SH:!GROK!THIS!
makedepend.SH:$spitshell >makedepend <<!GROK!THIS!
makedepend.SH:!GROK!THIS!
makedir.SH:$spitshell >makedir <<!GROK!THIS!
makedir.SH:!GROK!THIS!
myconfig:$spitshell <<!GROK!THIS!
And so forth ....
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: 3 Jun 1999 08:02:26 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can anyone tell me what this command is?
Message-Id: <37568af2@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
reddogg1471@my-deja.com writes:
:Can anyone tell me where I can find documentation on on this:
:GROK!THIS!
It's just the target string of a here document.
--tom
--
Those who do not understand Unix are condemned to reinvent it, poorly.
-- Henry Spencer
------------------------------
Date: Tue, 01 Jun 1999 13:52:34 -0400
From: Doug Seay <dms@rtp-bosch.com>
Subject: Re: Can I do this with an "if" statement?
Message-Id: <37541DE2.9988495F@rtp-bosch.com>
Mitch wrote:
>
> I would like to check to make sure that the input from the user is
> within 1-60 (integer). Can I do something like this with an if
> statement. If so how?
>
> if ($ans = [1...60]) {
> blah blah
> }
> else {
> print "out of bounds";
> }
Is this in a loop that will be called often? If so, and memory is not
an issue, you could try something along these lines. This will not win
an awards for speed, elegance, or sane use of resources, but it should
do what you want.
- doug
#!/usr/bin/perl -w
use strict
%::range = map { $_ => 1 } 1..60;
sub f($)
{
my $x = shift;
if ( exists $::range{$x} )
{ print "$x is in range\n"; }
else
{ print "$x is out-of-range\n"; }
}
f(0);
f(1);
f(10);
f(100);
------------------------------
Date: 3 Jun 1999 14:17:06 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Can Perl call C functions?
Message-Id: <37568052@newsread3.dircon.co.uk>
sbeaulieu@my-deja.com wrote:
>
>
>> Yes .. by reading the proper docs. Here are the most relevant docs in
>> random order:
>>
>> perldoc perlembed
>> perldoc perlcall
>> perldoc perlxs
>>
>
> The perlxs example 4 does exactly what I want but I can't seem to get
> it to work with Windows NT which is what I need it to work in. Any
> comments?
>
I guess advising you to change to a different OS isnt much help ;-}
Perhaps you can elucidate further "can't seen to get it to work ...".
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: 3 Jun 1999 13:08:26 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Concatenating variable names
Message-Id: <slrn7lcvia.psh.sholden@pgrad.cs.usyd.edu.au>
On Wed, 02 Jun 1999 10:15:44 GMT, stupon@my-deja.com <stupon@my-deja.com> wrote:
>I was trying to get the following to work:
>===================
>$i = 1;
>$value_{$i}=5; // This is where the problem lies
>
>print($value_1);
>===================
>It prints nothing, where as I was hoping for 5.
>It looks kindof pointless like this, but basically
>it would be in a for loop, and would make things
>much easier if it worked this way.
It can be done but a little different to that...
You don't want it however....
In a for loop surely $value[$i] = 5 is much simpler.
If $i isn't a small number then try $value{$i} = 5.
--
Sam
Any computer scientist who praises orthogonality should be sentenced to
use an Etch-a-Sketch.
-- Larry Wall
------------------------------
Date: 3 Jun 1999 08:03:38 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Concatenating variable names
Message-Id: <37568b3a@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
stupon@my-deja.com writes:
:I was trying to get the following to work:
:===================
:$i = 1;
:$value_{$i}=5; // This is where the problem lies
:
:print($value_1);
:===================
:It prints nothing, where as I was hoping for 5.
:It looks kindof pointless like this, but basically
:it would be in a for loop, and would make things
:much easier if it worked this way.
You are doing it wrong. You want a composite data structure. Perhaps
$value[$i] instead.
=head2 How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works I<sometimes>, but it is a very bad idea for two reasons.
The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether. Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.
Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash. The solution is to
use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables. This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one. Instead of
reading a string and expanding it to the actual contents of your program's
own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of course,
you don't need to use a dollar sign. You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes. For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table. This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.
In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
--
"Noalias must go. This is non-negotiable." --dmr
------------------------------
Date: 3 Jun 1999 08:00:50 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: damn F@#$(*)@ unix (*%$#&!* pipes
Message-Id: <37568a92@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, outlaw_torn <outlaw_torn@mailexcite.com> writes:
:...if you know of any general resources about unix / perl and broken
:pipes whether they be texts, web sites or FAQs, please reply.
A SIGPIPE (broken pipe signal) is sent to a process attempting to write
on a pipe, fifo, or stream socket whose remote reader has closed their
end of the connection.
% yes | head > /dev/null
[ Exit 141 ]
That "yes" process died of a sigpipe:
Exit 141 = 128 (indicates death by signal)
+ 13 (SIGPIPE)
Because "head" exited already and "yes" was still writing.
--tom
--
"SPARC" is "CRAPS" backwards --Rob Pike
------------------------------
Date: Thu, 3 Jun 1999 09:03:09 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Detect the existence of a subroutine w/o calling it
Message-Id: <7j5uas$4gh$1@nntp6.atl.mindspring.net>
Jon Connell wrote in message <37565A66.96FAFF5@arm.com>...
:Is there any way of finding out whether a subroutine exists before
:actually calling the subroutine?
:
:Why? Consider the sequence of operations ...
:
:1) Read a user-defined some-perl-code.pl which should include a
: subroutine.
:2) Do some time-consuming stuff.
:3) Call the user subroutine (which does done destructive work).
:
:It would be good to bail out at 1) when performing sanity checks
:on the user-defined code.
:
Oddly, I was just reading the following in perlfunc:
You may also use defined() to check whether a subroutine exists, by saying
defined &func without parentheses.
HTH
AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
Down that path lies madness. On the other hand, the road to hell is paved
with melting snowballs.
- Larry Wall in <1992Jul2.222039.26476@netlabs.com>
------------------------------
Date: 3 Jun 1999 08:06:36 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Detect the existence of a subroutine w/o calling it
Message-Id: <37568bec@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Jon Connell <jon.connell@arm.com> writes:
:Is there any way of finding out whether a subroutine exists before
:actually calling the subroutine?
:
:Why? Consider the sequence of operations ...
:
:1) Read a user-defined some-perl-code.pl which should include a
: subroutine.
:2) Do some time-consuming stuff.
:3) Call the user subroutine (which does done destructive work).
:
:It would be good to bail out at 1) when performing sanity checks
:on the user-defined code.
Is there something wrong with using defined(&subname) for this
the way its man page suggests?
If so, I suppose you could take a merry trip through the symbol
table and diff the old from the new. Devel::Symdump on CPAN
might help in that regard.
--tom
--
The X server has to be the biggest program I've ever seen that doesn't
do anything for you. --Ken Thompson
------------------------------
Date: Thu, 3 Jun 1999 14:55:03 +0200
From: "Fred Ruffet" <fruffet@kaptech.com>
Subject: Re: Determining height and with of uploaded Graphic files
Message-Id: <7j5tvg$b01$1@gatekeeper.ornano.kapt.com>
What graphic files ? GIFs, JPGs, BMPs, XPMs,...
Fred
mraffin@cisclub.acad.emich.edu a icrit dans le message
<7j0tnc$7ko$1@nnrp1.deja.com>...
>I need to determine the height and width of graphic files that users
>upload (via browser) to my site. Is this possible?
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
------------------------------
Date: 3 Jun 1999 14:13:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Determining height and with of uploaded Graphic files
Message-Id: <37567f78@newsread3.dircon.co.uk>
mraffin@cisclub.acad.emich.edu wrote:
> I need to determine the height and width of graphic files that users
> upload (via browser) to my site. Is this possible?
>
There is a module Image::Size available from CPAN.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: 3 Jun 1999 13:49:41 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: File Reading problem...
Message-Id: <375679e5@newsread3.dircon.co.uk>
Vincent Ridderikhoff <madvin@dds.nl> wrote:
> Hi,
>
> I need to read a line from a file, from that line I need to put
> everything that is before the ; in a variable $USER and everything after
> the ; in the variable $MAIL.
> Sins I'm new at Perl, I know how to read a line from a file and how to
> chop a variable, but know I want to divide it. I know I could just say
> to put the whole line in the two variables and than chop the $USER at
> the ; and use a repeat statement or so to delete the first characters of
> the $MAIL, but I want to know if there is a cleaner way?
>
($USER, $MAIL) = split /;/;
read about split in the perlfunc manpage.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Wed, 02 Jun 1999 15:31:02 -0700
From: Raj <technology@workmail.com>
Subject: Form Values
Message-Id: <3755B0A6.B4F3A2DD@workmail.com>
How do i pass the "multiple select" drop-down-box form values from a
CGI/perl script to another? Thanx in Advance
------------------------------
Date: Wed, 02 Jun 1999 19:19:41 GMT
From: skrana@my-deja.com
Subject: Freelance Perl CGI application Writers
Message-Id: <7j4043$rcb$1@nnrp1.deja.com>
I am looking for Freelance Perl (CGI) application writers.
Please send e-mail to rana@akr.com.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 3 Jun 1999 14:12:32 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Getting rid of blank lines
Message-Id: <37567f40@newsread3.dircon.co.uk>
themuppet@my-deja.com wrote:
> Hello,
>
> I'm trying to get rid of all the blank lines in a file that I'm parsing
> through. What kind of regexp would I use to delete a blank line? I'm
> looping through a file, and am concatenating the text together kind of
> like this:
>
> while (<>) {
>
> if !(???????) {
> $finalstring = $finalstring . $_;
> }
>
> }
>
You probably dont want to do it that way round:
while(<>)
{
next if (/^$/ );
$finalstring .= $_;
}
You can find out more about this stuff from the perlop and perlre manpages.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Thu, 3 Jun 1999 06:23:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Getting rid of blank lines
Message-Id: <MPG.11c0218c7648f1f7989b5d@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7j1r8d$4le$1@nnrp1.deja.com> on Tue, 01 Jun 1999 23:44:16
GMT, themuppet@my-deja.com <themuppet@my-deja.com> says...
...
> The question marks are where I'm looking for the regexp that will return
> true if $_ is a blank line.
/^$/ # nothing but a newline
/^\s*$/ # may have other whitespace characters
!/\S/ # same -- doesn't have a non-whitespace character
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Jun 1999 07:53:17 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Getting rid of blank lines
Message-Id: <375688cd@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, themuppet@my-deja.com writes:
:The question marks are where I'm looking for the regexp that will return
:true if $_ is a blank line.
And the perlre and perlop manpages on your system were no help?
--tom
--
'Do or do not... there is no try'
- Yoda
------------------------------
Date: Thu, 3 Jun 1999 04:56:20 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Getting rid of blank lines
Message-Id: <kvf5j7.k0i.ln@magna.metronet.com>
themuppet@my-deja.com wrote:
: I'm trying to get rid of all the blank lines in a file that I'm parsing
: through. What kind of regexp would I use to delete a blank line? I'm
: looping through a file, and am concatenating the text together kind of
: like this:
: while (<>) {
next if /^\s*$/; # skip blank lines
$finalstring .= $_;
: }
You could also replace the whole loop with (UNTESTED):
$finalstring = join '', grep ! /^\s*$/, <>;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Jun 1999 14:32:28 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Help on process data in a file
Message-Id: <7j63ls$6gs$1@info2.uah.edu>
In article <7j1u0l$5h3$1@nnrp1.deja.com>,
tvn007@my-deja.com writes:
: I am reading line by line from a file with the input as follow:
:
: SETR P:=T'LLLH';
: SETR P:=T'HXH0';
: SETR P:=T'0101';
: RUNP FOR 2;
: SETR P:=T'HLH0';
: SETR P:=T'HHHH';
: RUNP FOR 30;
:
: The output should be: (you need to repeat the previous line x time
: if you see RUNP FOR x command).
:
: R1 ddc1 LLLH;
: R1 ddc1 HXH0;
: R2 ddc1 0101;
: R1 ddc1 HLH0;
: R30 ddc1 HHHH;
[9:31] ettsn% cat try
#! /usr/bin/perl -w
use strict;
my $hold;
while (<DATA>) {
if (/^SETR\s+P:=T'([^']+)';/i) {
if ($hold) {
printf "R1 ddc1 $hold;\n";
}
$hold = $1;
}
elsif (/^RUNP\s+FOR\s+(\d+);/i) {
if ($hold) {
printf "R%-2d ddc1 $hold;\n", $1;
$hold = undef;
}
else {
die "ERROR: line $.: nothing to repeat\n";
}
}
else {
die "ERROR: line $.: unrecognized input sequence\n";
}
}
__DATA__
SETR P:=T'LLLH';
SETR P:=T'HXH0';
SETR P:=T'0101';
RUNP FOR 2;
SETR P:=T'HLH0';
SETR P:=T'HHHH';
RUNP FOR 30;
[9:31] ettsn% ./try
R1 ddc1 LLLH;
R1 ddc1 HXH0;
R2 ddc1 0101;
R1 ddc1 HLH0;
R30 ddc1 HHHH;
Greg
--
Fenster: Treat me like a criminal, I'll end up a criminal.
Hockney: You are a criminal.
Fenster: Why you gotta go and do that? I'm trying to make a point.
------------------------------
Date: Thu, 3 Jun 1999 16:21:49 +0200
From: "Bastiaan S van den Berg" <office@asc.nl>
Subject: help: is there a easy way to send mail?
Message-Id: <7j634g$pf6$1@zonnetje.NL.net>
hi
i need some code to send email from a cgi perl script ..
does anyone know how this can be done , sure , within 5/10 lines ??
tnx!
buZz
------------------------------
Date: Wed, 02 Jun 1999 21:48:14 GMT
From: dgmdan <dgmdan@md-sites.com>
Subject: Re: HELP: Regular Expressions
Message-Id: <7j48qs$ue4$1@nnrp1.deja.com>
Thanks, that was exactly the kind of answer I was looking for! =)
The _ character is included in \w as documented
on
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlre.html#Regular_E
xpressions
- dgmdan | www.md-sites.com
In article <7j37pf$i7l$1@nnrp1.deja.com>,
S Starre <sstarre@my-deja.com> wrote:
> Hi there..
>
> To force the regex to consider the entire line, use ^,$, such as
>
> /^[a-zA-Z][\w-.]+$/
>
> Also where is the '_' in the regex?
>
> -S
>
> In article <7j1sg9$530$1@nnrp1.deja.com>,
> dgmdan <dgmdan@md-sites.com> wrote:
> > I'm trying to create a script that takes $newnick and checks to see
if
> > it meets the requirements:
> > a. the first character can be *only* a letter
> > b. other than the first character, it can contain letters, numbers,
> > dashes, periods, and underscores
> >
> > If $newnick doesn't meet the requirements, I want the script to run
> the
> > sub "error". This is what I have:
> >
> > if ($newnick !~ /[a-zA-Z][\w-.]+/) { &error; }
> >
> > However, it appears as though when $newnick has a letter next to any
> of
> > the other characters, it doesn't run newnick. For example, if
> $newnick
> > is "a1!" it would see "a1" and it would not run the sub, even though
> the
> > "!" is there.
> >
> > How do I make it require that the entire string meet the
requirements,
> > not just any segment of it?
> >
> > - dgmdan | www.md-sites.com
> >
> > Sent via Deja.com http://www.deja.com/
> > Share what you know. Learn what you don't.
> >
>
> --
>
> Code not Perl Before Wine..
> -S Starre 1999
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 3 Jun 1999 06:40:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: HELP: Regular Expressions
Message-Id: <MPG.11c02583ef747987989b5e@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7j1sg9$530$1@nnrp1.deja.com> on Wed, 02 Jun 1999 00:05:35
GMT, dgmdan <dgmdan@md-sites.com> says...
> I'm trying to create a script that takes $newnick and checks to see if
> it meets the requirements:
> a. the first character can be *only* a letter
> b. other than the first character, it can contain letters, numbers,
> dashes, periods, and underscores
>
> If $newnick doesn't meet the requirements, I want the script to run the
> sub "error". This is what I have:
>
> if ($newnick !~ /[a-zA-Z][\w-.]+/) { &error; }
>
> However, it appears as though when $newnick has a letter next to any of
> the other characters, it doesn't run newnick. For example, if $newnick
> is "a1!" it would see "a1" and it would not run the sub, even though the
> "!" is there.
>
> How do I make it require that the entire string meet the requirements,
> not just any segment of it?
perldoc -f perlre
Add anchors, taking care not to match a trailing newline.
if ($newnick !~ /^[a-zA-Z][\w.-]+(?!\n)$/) { &error; }
or
if ($newnick !~ /\A[a-zA-Z][\w.-]+\z/) { &error; }
I also superstitiously moved the '-', though it doesn't have magical
powers after '\w'.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 3 Jun 1999 04:59:53 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: HELP: Regular Expressions
Message-Id: <96g5j7.k0i.ln@magna.metronet.com>
dgmdan (dgmdan@md-sites.com) wrote:
: I'm trying to create a script that takes $newnick and checks to see if
: it meets the requirements:
: a. the first character can be *only* a letter
: b. other than the first character, it can contain letters, numbers,
: dashes, periods, and underscores
: If $newnick doesn't meet the requirements, I want the script to run the
: sub "error". This is what I have:
: if ($newnick !~ /[a-zA-Z][\w-.]+/) { &error; }
: How do I make it require that the entire string meet the requirements,
: not just any segment of it?
Anchor both ends:
if ($newnick !~ /^[a-zA-Z][\w-.]+$/) { &error; }
^ ^
^ ^
But I would write it this way instead:
error() unless $newnick =~ /^[a-zA-Z][\w-.]+$/;
So that reading it sounds like "error unless newnick matches...".
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Jun 1999 09:18:19 -0400
From: Jean Laganiere <jean@laganiere.qc.ca>
Subject: How to scramble (hide) my perl code ?
Message-Id: <3756809B.D7573A6D@laganiere.qc.ca>
Hi there,
I want to distribute some perl scripts to a client and I do want them
to play with the code.
This code is using DBI:DBD and CGI modules.
Is there a tool to make the script unreadable ?
Thanks in advance.
Please reply to jean@laganiere.qc.ca.
"The nice thing about standards is that there are so many of them to
choose from" --Andrew S. Tanenbaum
------------------------------
Date: 3 Jun 1999 14:35:11 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: How to scramble (hide) my perl code ?
Message-Id: <7j63qv$6gs$2@info2.uah.edu>
In article <3756809B.D7573A6D@laganiere.qc.ca>,
Jean Laganiere <jean@laganiere.qc.ca> writes:
: I want to distribute some perl scripts to a client and I do want them
: to play with the code.
Then make it part of the license agreement. Record the md5sum of the
software as shipped. On support calls, refuse to help (or charge more!)
if the md5sum is different.
: Is there a tool to make the script unreadable ?
rm(1).
Greg
--
Bluto: My advice to you is to start drinking heavily.
Otter: Better listen to him, Flounder. He's pre-med.
------------------------------
Date: Wed, 02 Jun 1999 20:04:16 GMT
From: garthwebb@my-deja.com
Subject: Re: I pass an array to a subroutine, but that array is broken up by @_.
Message-Id: <7j42nr$s7j$1@nnrp1.deja.com>
In article <37556e42.526737874@news.sandia.gov>,
jwmoser@aragorn.sandia.gov wrote:
<snip>
> # How can I prevent my array from being broken up into seperate
> # scalars and just get the whole array out of @_ with one shift?
Rather than ask "How can I prevent my array from being broken up into
scalars" (you can't prevent it), you should ask "What other ways besides
'shift' allow access to data in '@_'?"
You should read 'perldata' and 'perlsub' and probably 'perlref' to
answer this, but here are a few examples:
# Passing a single argument that is an array.
&mysub(@foo);
sub mysub {
my @foo = @_;
...
}
# Passing many arguments, one of which is an array.
&mysub('bar', 5, @foo);
sub mysub {
my ($a, $b, @foo) = @_;
...
}
the most important thing to remeber is that:
&mysub(99, 'bar', $var, @stuff);
is exactly the same as:
push @some_args, 99;
push @some_args, 'bar';
push @some_args, $var;
push @some_args, @stuff;
&mysub(@some_args);
All arguments are put into one big array when a subroutine is called.
Garth
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
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 5872
**************************************