[22261] in Perl-Users-Digest
Perl-Users Digest, Issue: 4482 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 29 11:06:38 2003
Date: Wed, 29 Jan 2003 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 29 Jan 2003 Volume: 10 Number: 4482
Today's topics:
argument passing <slurper1234@hotmail.com>
Re: argument passing <ubl@schaffhausen.de>
Re: argument passing <josef.moellers@fujitsu-siemens.com>
Re: argument passing (Anno Siegel)
Re: argument passing <slurper1234@hotmail.com>
Re: array slicing <bart.lateur@pandora.be>
Re: array slicing (Anno Siegel)
Re: Email address RE news@roaima.freeserve.co.uk
Re: exec in windows question (Helgi Briem)
hash ordering. <spikey-wan@bigfoot.com>
Re: hash ordering. <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: hash ordering. <spikey-wan@bigfoot.com>
Re: hash ordering. <jurgenex@hotmail.com>
Re: How to close all ports ??? news@roaima.freeserve.co.uk
Re: How to search a file (newbie) (Tad McClellan)
Re: How to search a file (newbie) (Helgi Briem)
Mailing List CGI <joeljkp@tabdemo.larc.nasa.gov>
Re: Need help with sendmail routine <file attachments> <tassilo.parseval@localhost.localhost>
Next problem. <spikey-wan@bigfoot.com>
Re: Next problem. <tassilo.parseval@localhost.localhost>
Re: Next problem. <nobull@mail.com>
Re: Next problem. <spikey-wan@bigfoot.com>
Re: Next problem. (Tad McClellan)
Re: Next problem. <REMOVEsdnCAPS@comcast.net>
Re: Next problem. <jurgenex@hotmail.com>
Re: Problem checking for newline in $_ input line <JCornwall_must_remove_this_part@cox.net>
Re: Timestamps to thousandths of a second. (Jeremy Gooch)
Re: Timestamps to thousandths of a second. news@roaima.freeserve.co.uk
Re: Use and Require - Perl Modules (Richard Byers)
Re: Use and Require - Perl Modules <jurgenex@hotmail.com>
Using cgi-script to add unix user (need to modify shado (Tomas Nopp)
Re: Why doesn't perl -ex 'print 1' work on Windows? (John Ramsden)
XML parser (Flash Fan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Jan 2003 11:29:05 GMT
From: slurper <slurper1234@hotmail.com>
Subject: argument passing
Message-Id: <5WOZ9.15247$Jd.2344@afrodite.telenet-ops.be>
Can anyone point me at the man-page where passing arguments by name is
explained. Instead of relying on a particular order, i want to call
arguments by name
e.g
instead of:
sub {
my $a = shift;
my $b = shift;
print "$a versus $b";
}
and calling it like this: &sub("perl","c")
i want to call the function like this (for better maintenance)
&sub(systemlanguage="c", scriptinglanguage="perl")
sub {
print "$systemlanguage versus $scriptinglanguage";
}
or do you always have to "shift" the arguments into meaningfull names?
tx
------------------------------
Date: Wed, 29 Jan 2003 12:47:03 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: argument passing
Message-Id: <b18i7e$p5j$1@news.dtag.de>
slurper wrote:
> Can anyone point me at the man-page where passing arguments by name is
> explained. Instead of relying on a particular order, i want to call
> arguments by name
> e.g
>
> instead of:
> sub {
> my $a = shift;
> my $b = shift;
> print "$a versus $b";
> }
> and calling it like this: &sub("perl","c")
>
> i want to call the function like this (for better maintenance)
> &sub(systemlanguage="c", scriptinglanguage="perl")
>
> sub {
> print "$systemlanguage versus $scriptinglanguage";
> }
Don't use the & in suroutine calls. It most likely doesn't do what you
want. Just leave it out.
What you want can be easily achieved by passing name => value pairs to a
sub which are then assined to a hash:
person( name => "Joe User", age => 22 );
sub person {
my %paras = @_;
my $name = $paras{name} or die "missing para: name";
my $age = $paras{age};
}
This has some extra advantages:
- Parameter order is irrelevant (doesnt have to be remembered)
- Optional paras can be left out.
Hope this helps,
->malte
--
srand 108641088; print chr int rand 256 for qw<J A P H>
------------------------------
Date: Wed, 29 Jan 2003 12:51:50 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: argument passing
Message-Id: <3E37C056.96AD336F@fujitsu-siemens.com>
slurper wrote:
> =
> Can anyone point me at the man-page where passing arguments by name is
> explained. Instead of relying on a particular order, i want to call
> arguments by name
> e.g
> =
> instead of:
> sub {
> my $a =3D shift;
> my $b =3D shift;
> print "$a versus $b";
> }
> and calling it like this: &sub("perl","c")
> =
> i want to call the function like this (for better maintenance)
> &sub(systemlanguage=3D"c", scriptinglanguage=3D"perl")
> =
> sub {
> print "$systemlanguage versus $scriptinglanguage";
> }
> =
> or do you always have to "shift" the arguments into meaningfull names?
> =
> tx
Perl uses positional parameters. Period.
Having said that, you can get away with using a hash:
sub x {
my %args =3D @_;
print "$args{systemlanguage} vs $args{scriptinglanguage}\n";
}
x(systemlanguage =3D> "C", scriptinglanguage =3D> "Perl");
x(scriptinglanguage =3D> "Perl", systemlanguage =3D> "C");
C vs Perl
C vs Perl
No shift!
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 29 Jan 2003 11:57:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: argument passing
Message-Id: <b18fk4$j3a$1@mamenchi.zrz.TU-Berlin.DE>
slurper <slurper1234@hotmail.com> wrote in comp.lang.perl.misc:
> Can anyone point me at the man-page where passing arguments by name is
> explained. Instead of relying on a particular order, i want to call
> arguments by name
> e.g
>
> instead of:
> sub {
> my $a = shift;
> my $b = shift;
> print "$a versus $b";
> }
> and calling it like this: &sub("perl","c")
^
No need for "&", that's Perl 4 style. Actually, the initial "&"
makes the call special in that it suppresses prototype evaluation,
so it shouldn't be used unless you want to ignore a prototype.
The same applies to the call below.
> i want to call the function like this (for better maintenance)
> &sub(systemlanguage="c", scriptinglanguage="perl")
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
These are barewords and won't work under strict. You'd have to quote
them.
> sub {
> print "$systemlanguage versus $scriptinglanguage";
> }
>
> or do you always have to "shift" the arguments into meaningfull names?
The standard way in Perl to use named parameters is via a hash (isn't it
always?). The call syntax would be
sub( systemlanguage => "c", scriptinglanguage => "perl");
(and here the barewords are legal). In the sub, you just do
sub sub {
# %param = ( systemlanguage => "c", scriptinglanguage => "perl");
my %param = @_;
print "$param{ systemlanguage} versus $param{ scriptinglanguage}\n";
}
The commented line (when uncommented) is a way to provide defaults
for the parameters.
Anno
------------------------------
Date: Wed, 29 Jan 2003 12:45:07 GMT
From: slurper <slurper1234@hotmail.com>
Subject: Re: argument passing
Message-Id: <n1QZ9.15384$Jd.2398@afrodite.telenet-ops.be>
perfect
tx to all of you
Malte Ubl wrote:
> slurper wrote:
>> Can anyone point me at the man-page where passing arguments by name is
>> explained. Instead of relying on a particular order, i want to call
>> arguments by name
>> e.g
>>
>> instead of:
>> sub {
>> my $a = shift;
>> my $b = shift;
>> print "$a versus $b";
>> }
>> and calling it like this: &sub("perl","c")
>>
>> i want to call the function like this (for better maintenance)
>> &sub(systemlanguage="c", scriptinglanguage="perl")
>>
>> sub {
>> print "$systemlanguage versus $scriptinglanguage";
>> }
>
> Don't use the & in suroutine calls. It most likely doesn't do what you
> want. Just leave it out.
>
> What you want can be easily achieved by passing name => value pairs to a
> sub which are then assined to a hash:
>
> person( name => "Joe User", age => 22 );
>
> sub person {
> my %paras = @_;
> my $name = $paras{name} or die "missing para: name";
> my $age = $paras{age};
> }
>
> This has some extra advantages:
> - Parameter order is irrelevant (doesnt have to be remembered)
> - Optional paras can be left out.
>
> Hope this helps,
>
> ->malte
>
------------------------------
Date: Wed, 29 Jan 2003 12:42:54 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: array slicing
Message-Id: <ntif3vsagsfpqs3odam83l6737avis42qc@4ax.com>
Anno Siegel wrote:
>print "@{[grep { $_ eq 'THREE' .. !defined } @numbers]}\n";
I don't think the range operator will flop back to false at the end of
the list.
my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' );
for(\@numbers, [qw(A B C)]) {
print "@{[grep { $_ eq 'THREE' .. !defined } @$_]}\n";
}
-->
THREE FOUR FIVE
A B C
Like I said... :-)
--
Bart.
------------------------------
Date: 29 Jan 2003 14:45:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b18pe3$qpt$1@mamenchi.zrz.TU-Berlin.DE>
Bart Lateur <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> >print "@{[grep { $_ eq 'THREE' .. !defined } @numbers]}\n";
>
> I don't think the range operator will flop back to false at the end of
> the list.
>
> my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' );
> for(\@numbers, [qw(A B C)]) {
> print "@{[grep { $_ eq 'THREE' .. !defined } @$_]}\n";
> }
> -->
> THREE FOUR FIVE
> A B C
>
> Like I said... :-)
Right, another reason not to use this joke in earnest.
"!defined" is not an attempt to reset the operator. I would have
used "0" or "''" instead of "!defined" if the range operator didn't
insist in comparing a constant against $. I wanted a non-constant
expression that returns false, and nothing simpler came to mind. In
fact, it returns false only most of the time :)
Anno
------------------------------
Date: Wed, 29 Jan 2003 14:54:22 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: Email address RE
Message-Id: <uup81b.dvu.ln@moldev.cmagroup.co.uk>
Matthew Braid <mbear@uq.net.au> wrote:
> In fact, try to find a single word in the last 2
> sentences that _isn't_ a 'perfectly valid email address', other than
> "doesn't" and "you're"o
And if you include the double quotes, then those are potentially perfectly
valid email addresses, too.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Wed, 29 Jan 2003 14:19:22 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: exec in windows question
Message-Id: <3e37e2a6.2200641405@news.cis.dfn.de>
On Wed, 29 Jan 2003 02:17:57 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:
>There are two common ways to approach this:
>- either use "system" and simply start the external program in the
>background, jsut as you would do from the command line.
^^^^
You scared me there for a moment, Jürgen.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Wed, 29 Jan 2003 12:39:11 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: hash ordering.
Message-Id: <b18i35$jk5$1@newshost.mot.com>
Chaps,
Is there any way to force a hash to be in the same order as you defined it?
Currently, I have had to have an 'order' key in my hashes, and sort on it,
like this:
foreach (sort { $vars{$a}{order} <=> $vars{$b}{order} } keys %vars) {
but it keeps biting me when I forget to do it in a 'foreach', so if I could
simply force the thing to come out in the same order as I put it in, in the
first place, life would be much easier!
Please tell me it's possible.
Thanks.
R.
------------------------------
Date: Wed, 29 Jan 2003 14:10:30 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: hash ordering.
Message-Id: <ujkf3voeq2nvq9cai1j5r5mkrt38nugtne@4ax.com>
On Wed, 29 Jan 2003 12:39:11 -0000, "Richard S Beckett"
<spikey-wan@bigfoot.com> wrote:
>Chaps,
That's a bit sexist.
>Is there any way to force a hash to be in the same order as you defined it?
Check the FAQ.
perldoc -q 'remember the order'
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 29 Jan 2003 13:54:31 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: hash ordering.
Message-Id: <b18mgc$lai$1@newshost.mot.com>
"Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in
message news:ujkf3voeq2nvq9cai1j5r5mkrt38nugtne@4ax.com...
> On Wed, 29 Jan 2003 12:39:11 -0000, "Richard S Beckett"
> <spikey-wan@bigfoot.com> wrote:
>
> >Chaps,
>
>
> That's a bit sexist.
>
>
> >Is there any way to force a hash to be in the same order as you defined
it?
>
>
> Check the FAQ.
>
>
> perldoc -q 'remember the order'
>
>
>
> Cheers,
> Bernard
Thankyou madam. ;-)
R.
------------------------------
Date: Wed, 29 Jan 2003 15:33:06 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: hash ordering.
Message-Id: <SuSZ9.68$cu4.38@nwrddc02.gnilink.net>
Richard S Beckett wrote:
> Is there any way to force a hash to be in the same order as you
> defined it?
Hashes are mappings. They do not have an order. Asking for the order of a
hash is like asking for the weight of the color green.
jue
------------------------------
Date: Wed, 29 Jan 2003 14:59:53 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: How to close all ports ???
Message-Id: <99q81b.dvu.ln@moldev.cmagroup.co.uk>
David Wayne <dwayne@hotmail.com> wrote:
> But I ran it and it sat there listening but I could not get my
> client-side program to connect, eventually I aborted the script and
> now get an internal error when trying to re-run it (with no changes),
Ah. So it's a web server script? How do you know the process that's
doing the socket listening has really ended? I suspect it hasn't.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Wed, 29 Jan 2003 07:47:44 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to search a file (newbie)
Message-Id: <slrnb3fms0.9rr.tadmc@magna.augustmail.com>
Djm <dmuren@start.no> wrote:
> I also
> want to print the all text between f.eks. utv2:3 and utv2:4.
^^^^^^^
^^^^^^^
What does "f.eks." mean?
Is it a curse word?
> Anyone care to give me a hand?
Your Question is Asked Frequently.
perldoc -q between
"How can I pull out lines between two patterns that are
themselves on different lines?"
Please check the Perl FAQ *before* posting to the Perl newsgroup.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 29 Jan 2003 15:18:09 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: How to search a file (newbie)
Message-Id: <3e37f02f.2204106757@news.cis.dfn.de>
On Wed, 29 Jan 2003 07:47:44 -0600, tadmc@augustmail.com
(Tad McClellan) wrote:
>Djm <dmuren@start.no> wrote:
>> I also
>> want to print the all text between f.eks. utv2:3 and utv2:4.
> ^^^^^^^
>What does "f.eks." mean?
It means "for eksempel" in Nordic languages, which
surprise, surprise means the the same as f.ex. or
"for example" in English. The OP appears to be Norwegian.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Wed, 29 Jan 2003 07:58:38 -0500
From: Joel Konkle-Parker <joeljkp@tabdemo.larc.nasa.gov>
Subject: Mailing List CGI
Message-Id: <3E37CFFE.3020502@tabdemo.larc.nasa.gov>
I have a web site hosted by Hypermart, and I want to set up a mailing
list. Can anyone recommend a package for doing that sort of thing with
no machine access apart from my own webroot directory? I do have
Perl/CGI and sendmail access.
- Joel
------------------------------
Date: 29 Jan 2003 12:50:47 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: Need help with sendmail routine <file attachments>
Message-Id: <slrnb3fjh2.a68.tassilo.parseval@localhost.localhost>
Also sprach Janek Schleicher:
> On Wed, 29 Jan 2003 00:52:35 +0000, Tara wrote:
>> sub SendSubmission {
>> open (MAIL,"|$MailProgram -t");
>
> _Always_ check the result of an open statement:
> open MAIL, "|$MailProgram -t" or die "Couldn't open $MailProgram";
And include $!. Otherwise the above check isn't as helpful as it could
be.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 29 Jan 2003 12:22:56 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Next problem.
Message-Id: <b18h4l$jae$1@newshost.mot.com>
Hello World! :-)
I thought I understood what next does, but I obviously don't!
I had a loop like this:
foreach (keys %vars) {do a load of stuff};
and all was well. Then I added two more keys to the hash, so, if the key is
Fred, or Wilma, I don't want to do anything. I tried this...
foreach (keys %vars) {
next if ($_ eq ('Fred' || 'Wilma'));
do a load of stuff;
etc...
}
Assuming that: If the key is Fred or Wilma, the line with 'next' in it will
cause the loop to ignore the rest of the commands, and go onto the next key,
but it still does a load of stuff on Fred and Wilma. What did I do wrong?
From another thread, if I'm calling a subroutine called Barney, should I use
"&Barney;" or "sub Barney;"?
Thanks.
R.
------------------------------
Date: 29 Jan 2003 12:59:01 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: Next problem.
Message-Id: <slrnb3fk0h.a68.tassilo.parseval@localhost.localhost>
Also sprach Richard S Beckett:
> I thought I understood what next does, but I obviously don't!
It's not related to 'next' actually.
> I had a loop like this:
>
> foreach (keys %vars) {do a load of stuff};
>
> and all was well. Then I added two more keys to the hash, so, if the key is
> Fred, or Wilma, I don't want to do anything. I tried this...
>
> foreach (keys %vars) {
> next if ($_ eq ('Fred' || 'Wilma'));
Can't work. What you want is
next if $_ eq 'Fred' or $_ eq 'Wilma';
This shortcut of yours looks tempting but doesn't do what you expect.
('Fred' || 'Wilma')
will evaluate to something true (possibly 1) so you end up comparing
$_ eq 1
> do a load of stuff;
> etc...
> }
>
> Assuming that: If the key is Fred or Wilma, the line with 'next' in it will
> cause the loop to ignore the rest of the commands, and go onto the next key,
> but it still does a load of stuff on Fred and Wilma. What did I do wrong?
>
> From another thread, if I'm calling a subroutine called Barney, should I use
> "&Barney;" or "sub Barney;"?
Neither nor. You declare subroutines using 'sub', but you're not calling
them thus. As for the ampersand, drop it unless you need the special
semantics introduced by that (but you don't). Simply use parens:
Barney();
# or with arguments
Barny(@args);
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 29 Jan 2003 12:54:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Next problem.
Message-Id: <u91y2ww1z0.fsf@wcl-l.bham.ac.uk>
"Richard S Beckett" <spikey-wan@bigfoot.com> writes:
> Subject: Next problem.
Your problem has nothing to do with next.
You have a serious problem with problem partioning. You will never be
able to solve any (programming) problems unless you address this.
> next if ($_ eq ('Fred' || 'Wilma'));
Your immediate problem is in constructing an expression that is true
iff a particular variable has either one of two values. The fact that
this is in the condition of an 'if' statement qualifer and the fact
that the statement being qualified is 'next' are not releated to your
problem.
You immediate problem arrises because you have a really serious
misconception of what "or" (aka "||") means in programming languages.
Prgramming languages read like maths.
The "or" (aka "||") operator sits between two expressions that return
boolean (truth values) and returns true if either of the expressions
returns true. In some languages (including Perl) the full semantics
are more complex. The more complex sematics and vary from language to
language, but this simple explaination is a good starting point.
next if $_ eq 'Fred' || $_ eq 'Wilma';
The way you are trying to use "or", like it is used in English, is
something different entirely! The thing in Perl that has the
semantics that you are thinking of is Quantum::Superpositions::any().
# I'm feeling perverse today
use Quantum::Superpositions;
next if $_ eq any('Fred','Wilma');
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 29 Jan 2003 13:55:27 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Next problem.
Message-Id: <b18mi5$lal$1@newshost.mot.com>
Thanks, folks.
R.
------------------------------
Date: Wed, 29 Jan 2003 08:15:03 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Next problem.
Message-Id: <slrnb3fof7.9uh.tadmc@magna.augustmail.com>
Tassilo v. Parseval <tassilo.parseval@localhost.localhost> wrote:
> Also sprach Richard S Beckett:
>> next if ($_ eq ('Fred' || 'Wilma'));
[snip a correct fix]
> ('Fred' || 'Wilma')
>
> will evaluate to something true (possibly 1)
It always evaluates to 'Fred'.
> so you end up comparing
>
> $_ eq 1
But that is not correct. (I know because I made a similar mistake
here recently.)
You end up comparing:
$_ eq 'Fred'
ie. it will never check for a 'Wilma' value.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 29 Jan 2003 08:37:56 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Next problem.
Message-Id: <Xns93126252FB010sdn.comcast@216.166.71.239>
Brian McCauley <nobull@mail.com> wrote in news:u91y2ww1z0.fsf@wcl-
l.bham.ac.uk:
> # I'm feeling perverse today
> use Quantum::Superpositions;
> next if $_ eq any('Fred','Wilma');
>
Shame on you, for tossing Q:S at a newbie ;-)
--
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
------------------------------
Date: Wed, 29 Jan 2003 15:40:38 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Next problem.
Message-Id: <WBSZ9.69$cu4.24@nwrddc02.gnilink.net>
Richard S Beckett wrote:
> Hello World! :-)
>
> I thought I understood what next does, but I obviously don't!
>
> I had a loop like this:
>
> foreach (keys %vars) {do a load of stuff};
>
> and all was well. Then I added two more keys to the hash, so, if the
> key is Fred, or Wilma, I don't want to do anything. I tried this...
>
> foreach (keys %vars) {
> next if ($_ eq ('Fred' || 'Wilma'));
> do a load of stuff;
> etc...
> }
>
> Assuming that: If the key is Fred or Wilma,
I doubt that. Chances are you meant "if the key is Fred or the key is Wilma"
> the line with 'next' in
> it will cause the loop to ignore the rest of the commands, and go
> onto the next key, but it still does a load of stuff on Fred and
> Wilma. What did I do wrong?
You are mixing boolean values and text.
In ('Fred' || 'Wilma') you are applying a boolean operator to two text
strings. Those strings are not empty. That means their boolean value is TRUE
(simplifying here).
So you are computing (TRUE || TRUE) which of course is TRUE.
And then you are comparing $_ with TRUE
($_ eq TRUE)
I doubt this is what you meant.
BTW: I think if you would have used warnings then perl would have warned you
about his blunder.
jue
------------------------------
Date: Wed, 29 Jan 2003 14:26:47 GMT
From: "James F. Cornwall" <JCornwall_must_remove_this_part@cox.net>
Subject: Re: Problem checking for newline in $_ input line
Message-Id: <3E37E4A7.1BD42DC@cox.net>
Tad McClellan wrote:
>
> Sara <genericax@hotmail.com> wrote:
> > "J. F. Cornwall" <JCornwall@cox.net> wrote in message news:<jaxZ9.32353$Vh.7331@news2.central.cox.net>...
>
> >> if (s/^C\s+\*+\n//i)
>
> > You probably want to look at the "s"
>
> s///s will not change anything.
>
> The "s" option changes the meaning of the dot metacharacter, it
> has no effect (other than making the maintainer "hiccup" in
> understanding it) when there is no dot in the pattern.
>
> (I don't remember fortran ignoring case. Does it?)
>
> > and "m" switches for regexes.
>
> That one he _does_ need.
>
> s///m changes the meaning of the ^ and $ anchors.
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
A solution that works is:
if ($purpose_fg == 1) # no, are we in the PURPOSE block?
{
if (s/^C\s+\*+$//i) # detect and strip out blank comment
lines
{ $ignore_fg = 1; # set flag to ignore further input till
next keyword
$purpose_fg = 0; # unset this flag
print "</I> <BR>\n"; } # close HTML 'line'
else
{ s/^C\s+\*+\s+/ /i; # non-blank comment, strip off "C *"
and
print $_; } # print the line
}
My biggest problem was in looking for a \n after having done a chomp on
the line. Ben's suggestion to look for the $ instead did the trick.
And yes, Fortran is case-insensitive.
Thanks,
Jim
--
****************************************************
** Facilior veniam posterius quam prius capere! **
****************************************************
** James F. Cornwall, sole owner of all opinions **
** expressed in this message... **
****************************************************
------------------------------
Date: 29 Jan 2003 06:56:50 -0800
From: jeremy.gooch@axa-im.com (Jeremy Gooch)
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <723f1c02.0301290656.61c887a1@posting.google.com>
Many thanks for the replies.
I realised on the way home that it was really simple (it must have
been a long day!).
The solution I've gone for combines calls from Time::HiRes and
Date::Calc:-
# Get the timestamp (down to microseconds)
($secs_since_epoch, $microseconds) = gettimeofday();
($year, $month, $day, $hour, $min, $sec) =
Time_to_Date($secs_since_epoch);
$stamp = sprintf("%04d%02d%02d%02d%02d%02d",$year,$month,$day,$hour,$min,$sec);
$stamp = $stamp.$microseconds;
J.
------------------------------
Date: Wed, 29 Jan 2003 14:56:57 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <p3q81b.dvu.ln@moldev.cmagroup.co.uk>
Jeremy Gooch <jeremy.gooch@axa-im.com> wrote:
> I need to generate a current date/timestamp in the format
> yyyymmddhhmmssxxx where xxx are the thousandths of a second. The code
> must be portable across Solaris and NT.
Are those two platforms sufficiently accurate to be able to give you
meaningful results to that precision? Solaris on SPARC is notoriously
unreliable (unless driven by a recent version of NTP from a good
time source), and I have also heard bad things about NT's timekeeping
generally.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 29 Jan 2003 04:09:24 -0800
From: richardbyers@talk21.com (Richard Byers)
Subject: Re: Use and Require - Perl Modules
Message-Id: <22a01626.0301290409.e4dedf@posting.google.com>
Many thanks for your assistance.
You been most helpful - which is what these internet groups are all about!
(Is it not?)
Richard
------------------------------
Date: Wed, 29 Jan 2003 15:44:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Use and Require - Perl Modules
Message-Id: <BFSZ9.78$cu4.25@nwrddc02.gnilink.net>
Richard Byers wrote:
> Many thanks for your assistance.
> You been most helpful - which is what these internet groups are all
> about!
> (Is it not?)
No, not really. They are for discussions (most of them anyway), not a cheap
help desk.
And BTW; it's the Usenet. It came long before the Internet.
jue
------------------------------
Date: 29 Jan 2003 06:33:32 -0800
From: tomas@iss.se (Tomas Nopp)
Subject: Using cgi-script to add unix user (need to modify shadow file) How??
Message-Id: <da480c93.0301290633.253591a7@posting.google.com>
Hi,
we are running an application for which we on a linux system set up
new accounts by executing a perl script as a cron job. The script gets
the parameters needed from a html form.
On linux all this can be don with useradd but in this case we are
running on solaris and useradd cannot take a password as a parameter
(-p on linux)
----
my $cmd = sprintf "/usr/sbin/useradd -d /home/customers/a/%s -g
customer -k/root/template -m -p %s %s", %$href->{username}, $pwd,
%$href->{username};
----
So now I need to first set up the user then modify the shadow file to
give the user a correct password. Does anyone have an example on how
to do it? My perl skills are not so advanced.....
Regards // Tomas
------------------------------
Date: 29 Jan 2003 03:44:53 -0800
From: john_ramsden@sagitta-ps.com (John Ramsden)
Subject: Re: Why doesn't perl -ex 'print 1' work on Windows?
Message-Id: <d27434e.0301290344.432b967@posting.google.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1030128132055.34001C-100000@vcmr-64.server.rpi.edu>...
>
> [...]
>
> perl -efoobar 'print 1'
>
> is the same as
>
> perl -e 'foobar' 'print 1'
>
> which executes the code 'foobar', and puts 'print 1' in @ARGV. So the
> original code executes 'x' (which does nothing) and puts 'print 1' in
> @ARGV.
DUH! Thanks guys, and sorry to waste everyones' time. My brain cell that
formerly stored 'perl -e' must have randomly absorbed an extra character
some time during the weeks since I last used that option. But it won't
happen again, because I plan to get 'perl -e' tattood in large letters
on the back of my hand!
Cheers
John Ramsden (john_ramsden@sagitta-ps.com)
------------------------------
Date: 29 Jan 2003 07:35:36 -0800
From: flash0fan@hotmail.com (Flash Fan)
Subject: XML parser
Message-Id: <6aec3c2a.0301290735.226e28@posting.google.com>
I am using XML::Parser version 2.30 to parse the following XML. I can
get the name attributes, but the sessions are empty. Could any expert
give me any advice?
Thanks!
Fan
<name>SP 500 March,2003</name>
<sessions>
<session1 open="15:45:00" close=" 8:15:00" days="SMTWR"/>
<session2 open=" 8:30:00" close="15:15:00" days="MTWRF"/>
</sessions>
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 4482
***************************************