[22385] in Perl-Users-Digest
Perl-Users Digest, Issue: 4606 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 22 14:05:49 2003
Date: Sat, 22 Feb 2003 11:05:07 -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 Sat, 22 Feb 2003 Volume: 10 Number: 4606
Today's topics:
Re: Also religious: brackets <ubl@schaffhausen.de>
Change a variable (Lt.)
Re: Change a variable <mbudash@sonic.net>
Re: Change a variable <jurgenex@hotmail.com>
Re: Change a variable <tore@aursand.no>
Re: Chucking up text on word boundaries? (Robert Nicholson)
Re: Chucking up text on word boundaries? (Robert Nicholson)
Re: Creating a variable from 3 other variables <tore@aursand.no>
Re: Creating a variable from 3 other variables <tassilo.parseval@post.rwth-aachen.de>
Crypt Question <will@com.yahoo>
date::calc <will@com.yahoo>
FAQ proposal: Why can't I compare two strings using == <jurgenex@hotmail.com>
Re: join or .= -- which is faster? <ubl@schaffhausen.de>
Re: LWP Requests <mbudash@sonic.net>
Re: Mail::POP3Client password <ubl@schaffhausen.de>
Re: map two lists <barryk2@SPAM-KILLER.mts.net>
Re: map two lists <mpapec@yahoo.com>
Re: map two lists <johannes.fuernkranz@t-online.de>
Re: map two lists <ubl@schaffhausen.de>
Re: parens () <jurgenex@hotmail.com>
Problems comparing strings <PleaseDontThrowSpam@Me.com>
Re: Problems comparing strings <tore@aursand.no>
Re: Problems comparing strings <jurgenex@hotmail.com>
Re: Problems comparing strings <PleaseDontThrowSpam@Me.com>
Re: Problems comparing strings <mbudash@sonic.net>
Questions about perl. <mail@annuna.com>
Re: Questions about perl. <mbudash@sonic.net>
Re: Questions about perl. <abigail@abigail.nl>
Re: Reading tab delimited files into a hash. <tore@aursand.no>
Re: Religious question: commenting <cwilbur@mithril.chromatico.net>
sorting multidimensional arrays on one subkey <jd142@hotmail.com>
Re: sorting multidimensional arrays on one subkey <NoSpamPleaseButThisIsValid@gmx.net>
Re: Use or not to use modules <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 22 Feb 2003 17:31:21 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Also religious: brackets
Message-Id: <b38brr$9cm$1@news.dtag.de>
Ryan Shondell wrote:
> Malte Ubl <ubl@schaffhausen.de> writes:
>
>
>>Ryan Shondell wrote:
>>
>>>"Peter Cooper" <newsfeed2@boog.co.uk> writes:
>>>>$debug && print $variable;
>>>
>>>Wow, that's almost a carbon-copy example of what perlstyle says _not_
>>
>>>to do, because it hides the main point of the statement.
>>
>>No it doesn't, because here you got the very import C<$debug> as the
>>first word on the line. I prefer the written C<and> though.
>
>
> The part from perlstyle that I am refering to is:
>
> ... On the other hand
>
> print "Starting analysis\n" if $verbose;
>
> is better than
>
> $verbose && print "Starting analysis\n";
>
> because the main point isn't whether the user typed -v
> or not.
Actually, Larray and me are in less contradiction than you might think.
I said "because here you got the very import C<$debug>". So I put it in
front. Larry says "because the main point isn't whether the user typed
-v or not.". We both made a deliberate decision based on the context.
*verbose* is very different from *debug*. If I see C<$debug and...> in
my code I can say "This line is irrelevant for normal program execution"
at first glance. I don't have to read all of the line to get that
information.
The point of perlstyle is: If you _know_ why you're doing something,
then you it that way.
->malte
------------------------------
Date: 22 Feb 2003 15:37:24 GMT
From: LTZ@wewantmore.com (Lt.)
Subject: Change a variable
Message-Id: <b385fk$t80$1@slb2.atl.mindspring.net>
My apologies, I am very new to this.
I am trying to stip out the first two
characters in a variable which is supplied
in a web form. Example:
$Form{'refid'} would return a value of HK1234567
I would like to strip out the HK, or the first two
characters, the result would create another variable,
and use the new variable for the rest of my script.
How do I do this?
Sorry to be such a newbie.
--
LTZ
------------------------------
Date: Sat, 22 Feb 2003 16:07:50 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Change a variable
Message-Id: <mbudash-6CF2E4.08075122022003@typhoon.sonic.net>
In article <b385fk$t80$1@slb2.atl.mindspring.net>,
LTZ@wewantmore.com (Lt.) wrote:
> My apologies, I am very new to this.
>
> I am trying to stip out the first two
> characters in a variable which is supplied
> in a web form. Example:
>
> $Form{'refid'} would return a value of HK1234567
> I would like to strip out the HK, or the first two
> characters, the result would create another variable,
> and use the new variable for the rest of my script.
>
> How do I do this?
>
> Sorry to be such a newbie.
>
> --
> LTZ
>
perldoc -f substr
my $newvar = substr($Form{'refid'}, 2);
hth-
------------------------------
Date: Sat, 22 Feb 2003 16:18:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Change a variable
Message-Id: <IpN5a.8655$_J5.6176@nwrddc01.gnilink.net>
Lt. wrote:
> My apologies, I am very new to this.
I guess 'this' includes Usenet? :-{
I just replied to exactly the same question of yours in the other NG.
_DO_NOT_MULTIPOST_!
jue
------------------------------
Date: Sat, 22 Feb 2003 18:19:22 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Change a variable
Message-Id: <pan.2003.02.22.17.18.24.498677@aursand.no>
On Sat, 22 Feb 2003 15:37:24 +0000, Lt. wrote:
> $Form{'refid'} would return a value of HK1234567
> I would like to strip out the HK, or the first two
> characters, the result would create another variable,
> and use the new variable for the rest of my script.
my $var = substr( $Form{'refid'}, 2 );
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: 22 Feb 2003 06:51:55 -0800
From: robert@elastica.com (Robert Nicholson)
Subject: Re: Chucking up text on word boundaries?
Message-Id: <24a182bd.0302220651.754c9db5@posting.google.com>
This is what I have that's not currently working.
#$Text::Wrap::columns = 150;
#@bodyLines = split(/\n/,$Body);
#@lines = wrap('','',@bodyLines);
#$partIndex = 1;
#foreach $line (@lines) {
# &emailPart($line,$partIndex);
# $partIndex++;
#}
when I debug this $line the first time through the foreach is the same as $Body
don't ask me why.
------------------------------
Date: 22 Feb 2003 07:03:57 -0800
From: robert@elastica.com (Robert Nicholson)
Subject: Re: Chucking up text on word boundaries?
Message-Id: <24a182bd.0302220703.607ab51d@posting.google.com>
Well it's amazing how a Saturday morning makes one think properly.
I now understand that this thing returns a string that I have to split
again by newlines and then I will be given the array I'm looking for.
I haven't checked the source but I thought if you called wrap in a
list context that it would return an array.
------------------------------
Date: Sat, 22 Feb 2003 15:28:39 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Creating a variable from 3 other variables
Message-Id: <pan.2003.02.22.14.07.51.955659@aursand.no>
On Sat, 22 Feb 2003 13:10:28 +0000, Mikey wrote:
> If I try the following, I will get errors:
> my $date = "$year$month$day";
Try this:
my $date = $year . $month . $day;
Looks prettier, too! :) Although you might have a problem here (actually
more than _a_ problem). I'm almost certain that you want your dates to be
in one format, and one format only (ie. with padded 0's where it should
be).
my $date = sprintf( "%4d%02d%02d", $year, $month, $day );
In addition, you should check to make sure that:
a) The year is valid. What happens if $year is a 2-digit number
expressing years after 2000? Hmm. Better check for that and
add 2000.
b) The final date is valid. What use have you got for an invalid
date? Hmm. No use, I guess.
Happy dating! :)
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: 22 Feb 2003 17:28:58 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Creating a variable from 3 other variables
Message-Id: <b38c0q$760$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Mikey:
> I'd like to create a variable from 3 other variables.
>
> The following will do this:
> my $date = "$year $month $day";
>
> BUT
>
> $date will include two spaces. I do not want spaces.
>
> If I try the following, I will get errors:
> my $date = "$year$month$day";
No, you wont. Have you tried it?
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: Sat, 22 Feb 2003 18:59:46 GMT
From: w i l l <will@com.yahoo>
Subject: Crypt Question
Message-Id: <5ief5v4u2c63q66dppl0o2op46d510icbg@4ax.com>
I'm looking for a module, or technology that would allow me to Encrypt
some string data with a key, and then to decrypt with a different
Decrypt key.
Is PGP what I want? If so, how do i go about getting it?
thanks for your help.... this is a bit OT, but i'd appreciate any
help.
-W i l l
------------------------------
Date: Sat, 22 Feb 2003 18:59:46 GMT
From: w i l l <will@com.yahoo>
Subject: date::calc
Message-Id: <ghhf5vk039ah0cuvfohcej8q6ljld8a9p6@4ax.com>
Is there a way of using date::calc or some other module to get the
time format 20030215 (YYYYMMDD) into Feb 15 2003 ?
TIA!!!!!!!!!!!!!!!!
------------------------------
Date: Sat, 22 Feb 2003 15:34:23 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3MM5a.8267$_J5.4846@nwrddc01.gnilink.net>
One of the most frequently asked questions is
"Why can't I compare two strings using == ?"
Suggested answer:
The operator "==" compares the numerical values of its operands.
Chances are you want to compare the textual values in which case you should
use the operator "eq" instead. For further details please check "perldoc
perlop".
jue
------------------------------
Date: Sat, 22 Feb 2003 17:12:30 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: join or .= -- which is faster?
Message-Id: <b38aog$665$1@news.dtag.de>
Cristian Gutierrez wrote:
> Malte Ubl posteo' asi':
>
>
>>As far as I know C<$var += 3> is faster than C<$var = $var + 3> because,
>>the first is operating on existing memory while the second is doing an
>>extra copy. This is of course for numbers where no extra memory has to
>>be allocated, but I could still imagine the same to be true for strings.
>
>
>>I would think that while C<$var = $var."something" > probably compiles
>>to a join, that C<$var .= "something"> compiles to some kind of string
>>append function.
>
>
> Premature optimization... yadda yadda..
unless you know in advance that $var will be 3 Mega Million Byte big.
:)
------------------------------
Date: Sat, 22 Feb 2003 15:58:48 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: LWP Requests
Message-Id: <mbudash-1E91A8.07584922022003@typhoon.sonic.net>
In article <v5elafall1sea8@corp.supernews.com>,
"Smiley" <smiley@uvgotemail.com> wrote:
> > you're not telling us enough... elaborate a little and perhaps we can
> > help...
>
> Well, I've explained some of this in my earlier post. The website is set up
> with a searchable database which I would like to grab information from. The
> online script only accepts Post, and uses form buttons using Post to take
> users to the Next and Previous screens in the search results.
>
> I'm using LWP to grab that information, putting in the necessary variables
> via Post, and this works for the first screen of the search results.
> However, I can't seem to retrieve the subsequent pages. It seems that the
> first page keeps repeating and I'm not sure what I need to change in order
> to correct that.
>
> The first page of the results is actually not the same script as for the
> second page. It links to a new script called results.asp, and ads a new
> variable for each page called intCurrentpage and also Action=Next+Items.
>
> I've got my Perl script set up to loop through the number of pages in the
> results and change intCurrentpage each time. At the end of the loop it
> changes $req to point to results.asp, changes the content, and updates $res
> appropriately (variable names taken from perldoc)
>
> Yet it's still pulling in the same data from the same page at each loop.
>
> Is that enough information for you?
it could be any number of things, including but not limited to:
- the remote page 2 script may expect GET params and you're using POST,
or vice versa (you don't say which)
- the remote page 2 script may be set up to recognize that a fake
browser is being used (lwp) by its user agent signature
etc.
what url are you trying to reach?
------------------------------
Date: Sat, 22 Feb 2003 16:30:01 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Mail::POP3Client password
Message-Id: <b3888q$q7j$1@news.dtag.de>
Veera Venkataramani wrote:
> use Mail::POP3Client;
> $pop = new Mail::POP3Client( USER => "me",
> PASSWORD => "mypassword",
> HOST => "pop3.do.main" );
> for( $i = 1; $i <= $pop->Count(); $i++ ) {
> foreach( $pop->Head( $i ) ) {
> /^(From|Subject):\s+/i && print $_, "\n";
> }
> }
> $pop->Close();
>
>
> However, if I dont replace "mypassword" with my cleartext password,
> this doesnt work. I dont think this is how people use this
> package. How do I use this without having my password in cleartext in
> a script file?
turn
PASSWORD => "mypassword",
into
PASSWORD => $password_from_whatever_source,
->malte
------------------------------
Date: Sat, 22 Feb 2003 08:15:18 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: map two lists
Message-Id: <MPG.18c141ee1f93beb398970c@news.mts.net>
In article <b37uvi$9an$01$1@news.t-online.com>, =?ISO-8859-
1?Q?Johannes_F=FCrnkranz?= (johannes.fuernkranz@t-online.de) says...
> Hi,
>
> I frequently have the following problem:
> I would like to run a map over two lists that are aligned, i.e.,
> something like:
>
> @result = map2 { function($1,$2} } @list1, @list2;
>
> This, of course, doesn't work, but maybe there is something similar?
> ($1 and $2 are meant to refer to corresponding arguments in the two lists).
>
> I also thought of the possibility of first forming a combined list,
> i.e., a list that consists of references of two-element lists, one from
> each original list. This list should look like:
>
> @combined = ( [ $list1[0], $list2[0] ],
> [ $list1[1], $list2[1] ],
> ...
> );
>
> Then I could call
>
> @result = map { function($_->[0],$_->[1]) } @combined;
>
> But again, I don't know how to efficiently construct @combined.
>
> [ I do know how to construct it with a for-loop and push, but I keep
> thinking there must be a more elegant and more efficient way to do this,
> preferrably in a single statement. ]
>
> thanks, Juffi
>
>
@result = map { &function($list1[$_],$list2[$_]) } (0..$#list1);
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Sat, 22 Feb 2003 15:15:40 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: map two lists
Message-Id: <cf1f5vsdsrcnr3h69486bmufiv3b5j30oq@4ax.com>
X-Ftn-To: Johannes Fürnkranz
Johannes Fürnkranz <johannes.fuernkranz@t-online.de> wrote:
>Hi,
>
>I frequently have the following problem:
>I would like to run a map over two lists that are aligned, i.e.,
>something like:
>
>@result = map2 { function($1,$2} } @list1, @list2;
how about using indices?
@result = map2 { function($list1[$_],$list2[$_]) } 0 .. $#list1;
>This, of course, doesn't work, but maybe there is something similar?
>($1 and $2 are meant to refer to corresponding arguments in the two lists).
>
>I also thought of the possibility of first forming a combined list,
>i.e., a list that consists of references of two-element lists, one from
>each original list. This list should look like:
>
>@combined = ( [ $list1[0], $list2[0] ],
> [ $list1[1], $list2[1] ],
> ...
> );
@combined = map { [$list1[$_],$list2[$_]] } 0 .. $#list1;
or if you want references to original array values:
@combined = map { [\$list1[$_],\$list2[$_]] } 0 .. $#list1;
>@result = map { function($_->[0],$_->[1]) } @combined;
>
>But again, I don't know how to efficiently construct @combined.
>
>[ I do know how to construct it with a for-loop and push, but I keep
>thinking there must be a more elegant and more efficient way to do this,
>preferrably in a single statement. ]
foreach can be very effective and even faster then perlish map or grep since
they are usually used with curly braces which slows them down.
push @combined, [$list1[$_],$list2[$_]] for 0 .. $#list1;
--
$_=$2.$1,s sg s sgmx,$/.=$_,while q mnagdaLrrgysiHgsihgca
ek r=m=~m m(. ) (. ) mmxg;print"There is only one God,$/"
------------------------------
Date: Sat, 22 Feb 2003 15:25:30 +0100
From: =?ISO-8859-15?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: map two lists
Message-Id: <b3818u$dhq$06$1@news.t-online.com>
Barry Kimelman wrote:
>
> @result = map { &function($list1[$_],$list2[$_]) } (0..$#list1);
Yep, I guess it can't get any shorter than this, and probably not more
efficient either.
Thanks!
Juffi
------------------------------
Date: Sat, 22 Feb 2003 16:12:54 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: map two lists
Message-Id: <b3878n$mnl$1@news.dtag.de>
Johannes Fürnkranz wrote:
> Hi,
>
> I frequently have the following problem:
> I would like to run a map over two lists that are aligned, i.e.,
> something like:
>
> @result = map2 { function($1,$2} } @list1, @list2;
How about this:
use strict;
use warnings;
use Carp;
our($_1,$_2);
sub map2(&\@\@) {
my($sub,$array1,$array2) = @_;
local($_1,$_2);
my $i = 0;
foreach my $ele (@$array1) {
($_1,$_2) = ($ele,$array2->[$i]);
$sub->();
$i++;
}
}
sub map3 (&@) {
my($sub,@rest) = @_;
croak "need an even sized list as second parameter" if @rest % 2;
my $half = int($#rest / 2);
foreach my $i (0 .. $half) {
my $second = $i + $half + 1;
($_1,$_2) = ($rest[$i], $rest[$second]);
$sub->();
}
}
# Example
my @array1 = (1,1);
my @array2 = (2,2);
my @result = map2 { print "1 -> $_1, 2 -> $_2\n" } @array1, @array2;
@result = map3 { print "1 -> $_1, 2 -> $_2\n" } (1,1), (2,2);
Note, the map2 will only work on arrays. You won't be able to iterate
over lists with this approach without assigning them to arrays. map3
will work on list if you are willing to accept the subtle bugs which can
happen if you use lists of different sizes.
->malte
--
srand 108641088; print chr int rand 256 for qw<J A P H>
------------------------------
Date: Sat, 22 Feb 2003 15:18:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: parens ()
Message-Id: <5xM5a.8128$_J5.1256@nwrddc01.gnilink.net>
Robert Krueger wrote:
> Why does this work:
> print (( 2 * 3 ) * 8 );
>
> and this doesn't?
> print ( 2 * 3 ) * 8;
Please define "doesn't work".
Both of them work just fine for me (I don't get any error message or such).
However perl warns about
Useless use of integer multiplication (*) in void context at ...
So it would be cleaner to write the second line as without the obscure "*
8":
print (2*3);
jue
------------------------------
Date: Sat, 22 Feb 2003 14:22:20 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Problems comparing strings
Message-Id: <b38100$t7m$1@wisteria.csv.warwick.ac.uk>
Hi,
I'm storing names into variables and then trying to compare them. Some
example names are:
Mikey Jones
Jimmy Beef
Donald H Samuel
Sarah A Girl
Unfortunately, the following code does not work:
if ($name1 == $name2) {
print "Names are the same\n";
}
It gives the error:
"Argument "Donald H Samuel" isn't numeric in numeric eq (==)"
For your information: these names are read in from a dat file.
How can I compare these names?
Thank-you very much,
Mikey
------------------------------
Date: Sat, 22 Feb 2003 15:50:48 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Problems comparing strings
Message-Id: <pan.2003.02.22.14.43.29.83738@aursand.no>
On Sat, 22 Feb 2003 14:22:20 +0000, Mikey wrote:
> "Argument "Donald H Samuel" isn't numeric in numeric eq (==)"
You are trying to compare _strings_, right? Well. You are dealing with
strings, but are trying to compare them as numbers. Won't help you very
much in this case.
Try using 'eq' (as in 'equal') for comparing strings, and _please_ read
the documentation on Perl's operators;
'perldoc perlop'
In addition: What if names are slightly misspelled? That may happen, and
in that case you should take a closer look at these modules:
String::Approx
Text::Soundex
You'll find them on CPAN:
<url:http://www.cpan.org/>
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Sat, 22 Feb 2003 15:27:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Problems comparing strings
Message-Id: <rFM5a.6953$ep5.35@nwrddc02.gnilink.net>
Mikey wrote:
> Hi,
>
> I'm storing names into variables and then trying to compare them. Some
> example names are:
>
> Mikey Jones
> Jimmy Beef
> Donald H Samuel
> Sarah A Girl
>
> Unfortunately, the following code does not work:
>
> if ($name1 == $name2) {
> print "Names are the same\n";
> }
>
> It gives the error:
>
> "Argument "Donald H Samuel" isn't numeric in numeric eq (==)"
That's not an error, that is a warning. And it is justified? "Donald H
Samual" is not a number, isn't it?
But Perl will do the right thing and just use the numerical values instead.
So your code should read
if ($name1 == $name2) {
print "Names have the same numerical value\n"; }
You may want to switch off warnings for this block though, to avoid the
warning.
> How can I compare these names?
If you want to compare them textually then use the compare operator for
text: eq
if ($name1 eq $name2) {
print "Names are the same\n"; }
For further details see "perldoc perlop"
On a side note: this must be the most frequently asked question. I think
it's not in the FAQ (I may be wrong here).
Is there a chance to add it to the FAQ?
jue
------------------------------
Date: Sat, 22 Feb 2003 16:06:07 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Re: Problems comparing strings
Message-Id: <b3872j$3b0$1@wisteria.csv.warwick.ac.uk>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:rFM5a.6953$ep5.35@nwrddc02.gnilink.net...
> Mikey wrote:
> > Hi,
> >
> > I'm storing names into variables and then trying to compare them. Some
> > example names are:
> >
> > Mikey Jones
> > Jimmy Beef
> > Donald H Samuel
> > Sarah A Girl
> >
> > Unfortunately, the following code does not work:
> >
> > if ($name1 == $name2) {
> > print "Names are the same\n";
> > }
> >
> > It gives the error:
> >
> > "Argument "Donald H Samuel" isn't numeric in numeric eq (==)"
>
> That's not an error, that is a warning. And it is justified? "Donald H
> Samual" is not a number, isn't it?
> But Perl will do the right thing and just use the numerical values
instead.
> So your code should read
> if ($name1 == $name2) {
> print "Names have the same numerical value\n"; }
> You may want to switch off warnings for this block though, to avoid the
> warning.
Is it possible to switch off warnings for a single block? How so?
> > How can I compare these names?
>
> If you want to compare them textually then use the compare operator for
> text: eq
>
> if ($name1 eq $name2) {
> print "Names are the same\n"; }
>
> For further details see "perldoc perlop"
>
> On a side note: this must be the most frequently asked question. I think
> it's not in the FAQ (I may be wrong here).
> Is there a chance to add it to the FAQ?
>
> jue
>
Thank-you
------------------------------
Date: Sat, 22 Feb 2003 16:13:06 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Problems comparing strings
Message-Id: <mbudash-3CC57E.08130722022003@typhoon.sonic.net>
In article <b3872j$3b0$1@wisteria.csv.warwick.ac.uk>,
"Mikey" <PleaseDontThrowSpam@Me.com> wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:rFM5a.6953$ep5.35@nwrddc02.gnilink.net...
[snip]
> >
> > if ($name1 == $name2) {
> > print "Names have the same numerical value\n"; }
> >
> > You may want to switch off warnings for this block though, to avoid the
> > warning.
>
> Is it possible to switch off warnings for a single block? How so?
>
one way:
{
no warnings;
if ($name1 == $name2) {
print "Names have the same numerical value\n";
}
}
hth-
------------------------------
Date: Sat, 22 Feb 2003 11:54:38 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Questions about perl.
Message-Id: <3E57B95E.3050502@annuna.com>
I picked up a book on c++. It is very intersting but seems like it is
rather cumbersome to program next to perl. C++ has objects and classes?
Does perl have simmilar functions?
------------------------------
Date: Sat, 22 Feb 2003 18:39:42 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Questions about perl.
Message-Id: <mbudash-8C6D1C.10394322022003@typhoon.sonic.net>
In article <3E57B95E.3050502@annuna.com>, Joe Creaney <mail@annuna.com>
wrote:
> I picked up a book on c++. It is very intersting but seems like it is
> rather cumbersome to program next to perl. C++ has objects and classes?
> Does perl have simmilar functions?
>
yes, the concepts exist in perl. but you don't have to use them! 8^)
hth-
------------------------------
Date: 22 Feb 2003 18:42:39 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Questions about perl.
Message-Id: <slrnb5fh4v.a7b.abigail@alexandra.abigail.nl>
Joe Creaney (mail@annuna.com) wrote on MMMCDLXII September MCMXCIII in
<URL:news:3E57B95E.3050502@annuna.com>:
\\ I picked up a book on c++. It is very intersting but seems like it is
\\ rather cumbersome to program next to perl. C++ has objects and classes?
Yes.
\\ Does perl have simmilar functions?
What similar functions are you refering to? Objects and classes
aren't functions.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: Sat, 22 Feb 2003 15:28:40 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <pan.2003.02.22.14.01.33.484446@aursand.no>
On Sat, 22 Feb 2003 04:42:27 -0800, Charles R. Thompson wrote:
> I constantly find myself reading tab delimited files into a hash in a
> method similar to below.
I really don't see a problem using a hash to structure a file content. I
guess it depends on how you're supposed to deal with the data later in
your program. If you feel that the hash structure suits you, stick with
it.
However;
> while ($hostsfile =~ s/^CLIENT:(.*)\t(.*)\t(.*)\t[snip]\n//)
> {
> # insert into hash
> }
This can be done in a better way:
my @lines = split("\n", $hostsfile);
foreach ( @lines ) {
my @fields = split( /\t+/ );
}
It can be done even easier, too, but this should get you on the right
track. Have a look at 'perldoc -f split' for more information about the
'split' function.
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Sat, 22 Feb 2003 17:15:22 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Religious question: commenting
Message-Id: <87u1ew6yc4.fsf@mithril.chromatico.net>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
I'm going to respond to both of these at once.
AS> Tony L. Svanstrom <tony@svanstrom.com> wrote in
AS> comp.lang.perl.misc:
>> For many of us we are the maintainer, which makes it very
>> important for us to adopt a style of coding which will remain
>> more or less the same over time (which in turn makes it
>> important for us to know our tools as well as possible).
>>
>> The thinking behind that is pretty simple, if you end up with a
>> problem with your own code you can almost always guess where
>> what code is and what it might look like; even if there are
>> no/few comments.
>>
>> Which brings us back to why it's ok that people commented on
>> his code and not only on the style of commenting; the code is
>> the ultimate comment, sort of. =)
Oh, I think it's entirely appropriate that people commented on his
code. After all, if the code is terrible, comments aren't going to
improve it much.
But I well aware that I won't be the only one maintaining my code;
right now I work in a company where there are about a half-dozen
people who regularly use Perl, and I've had to read and understand all
of their code to modify it. I've also been in situations where I took
a job and had to maintain Perl code, and in situations where I left a
job having written nearly 10,000 lines of Perl code.
AS> In any case comments are only one tool in making code
AS> understandable. Asking people to restrict the discussion to
AS> only one aspect is silly.
I agree with the former, but not the latter. Profitable discussions
can be had of all aspects of programming.
AS> One reason why comment-writing is unpopular among programmers
AS> is that it is hard to do right. It requires you to put
AS> yourself in the place of someone who doesn't know what you're
AS> up to and to forget "for the moment" all the intricacies of
AS> the code you're struggling with. The mental effort of viewing
AS> your work from outside is disruptive, but if it isn't made,
AS> the resulting comment is likely to be unhelpful. It is far
AS> easier to just write down what goes through your head at the
AS> moment, so this happens a lot, but (like in Usenet subject
AS> lines), the result is mostly unsatisfactory. We have all
AS> puzzled over comments that look like radio messages from Mars.
But this is an argument against *bad* commenting, not against
commenting in general. I don't find the mental effort of viewing my
work from outside at all disruptive; it's roughly the same as writing
a paper in which you know all the other sources and the audience does
not. Instead of just writing the code for the computer and the
maintainer, you're writing the comments for the maintainer as well.
A similar argument could be made for sensible variable names and
coding conventions as well; they require other considerations beyond
simply telling the computer what to do, forgetting the code you're
struggling with and considering the maintainer and yourself. We've
all puzzled over variable names that are opaque and unhelpful; does
this mean we should give up on trying to create clear variable names?
Charlton
------------------------------
Date: 22 Feb 2003 12:01:15 -0600
From: Bob <jd142@hotmail.com>
Subject: sorting multidimensional arrays on one subkey
Message-Id: <pfef5v8cc38skkigdinov5ovd4sm6i6ahj@4ax.com>
Hi,
I'm hoping someone can help me, I've been trying to figure out how to
do this and just running into a brick wall.
I have an array structure like this:
$arr[$i][0] = sum of array[$i][1..endofarray]
So I might have data like this:
$arr[0][0]=10; ##10 = 3 +2+3+1+2
$arr[0][1]=3;
$arr[0][2]=2;
$arr[0][3]=3;
$arr[0][4]=1;
$arr[0][5]=2;
$arr[1][0]=15; ##15= 1+9+1+1+1+2
$arr[1][1]=1;
$arr[1][2]=9;
$arr[1][3]=1;
$arr[1][4]=1;
$arr[1][5]=1;
$arr[1][6]=2;
$arr[2][0]=5; ## 5 = 3+2
$arr[2][1]=3;
$arr[2][2]=2;
and so forth. I want to order them by their length, $arr[$i][0]
so that if I do this
$mylength = @arr;
$q = 0;
while ($q < $mylength)
{
print "$arr[$q][0]\n";
}
I get :
5
10
15
Eventually what I want to do is keep the top N arrays and throw the
rest away, which I can do once I order them.
I know I may not be doing this the most efficient way possible, but
I'm doing it in a way I can understand. It's been awhile since I've
worked with multidimensional arrays in perl, shoot, it's been awhile
since I've worked with perl.
I'd appreciate any help.
Thanks,
Bob
------------------------------
Date: Sat, 22 Feb 2003 19:33:26 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid@gmx.net>
Subject: Re: sorting multidimensional arrays on one subkey
Message-Id: <3E57C276.E3911485@gmx.net>
Bob wrote:
>
> Hi,
>
> I'm hoping someone can help me, I've been trying to figure out how to
> do this and just running into a brick wall.
>
> I have an array structure like this:
>
> $arr[$i][0] = sum of array[$i][1..endofarray]
>
> So I might have data like this:
>
> $arr[0][0]=10; ##10 = 3 +2+3+1+2
Isn't 3+2+3+1+2=11?
> and so forth. I want to order them by their length, $arr[$i][0]
@arr = sort { $a->[0] <=> $b->[0] } @arr;
See
perldoc -f sort
Wolf
------------------------------
Date: Sat, 22 Feb 2003 16:10:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Use or not to use modules
Message-Id: <liN5a.193$V42.108@nwrddc03.gnilink.net>
Gunnar Hjalmarsson wrote:
> "Steffen Beyer" <Steffen.Beyer@de.bosch.com> wrote in message
> news:<b34itt$hn8$1@ns2.fe.internet.bosch.com>...
>> But in general, it is of course a good idea not to re-invent
>> the wheel and to use modules wherever possible.
>
> I don't agree on "wherever possible".
I think that depends on your personal definition of "possible".
I prefer "feasible", but I guess that's just playing with definitions.
> I started to write my first Perl/CGI program about three years ago
> with (almost) no programming experience. I applied the "learning by
> doing" approach. Don't we all, btw? ;-)
>
> Anyway, personally I like to really understand what I'm doing.
That is a noble goal, but learning is different from actual programming.
Case in point: parsing HTML correctly is a surprisingly complicated task and
I wouldn't trust anyone without extended experience in computer languages
and compiler construction to get it right.
Now, if you goal is to learn how to parse HTML then by all means write your
own parser. But consider it to be a student's project without any practical
value.
If you goal is to actually parse HTML then _please_ use the module that was
written for that purpose by people who know how to do it.
> I
> believe that most often, when people use modules, they don't care to
> learn how they really work.
Yes, that is actually one of the main purposes of modules. I do not need to
know all the details about how to write a tokenizer, how to write a parser,
and how to structure a syntax tree just to get my 10 lines of HTML parsed. I
can trust that people who are experts in their fields did the right thing.
If I would have to learn all the nifty-grifty details about how the cellular
phone net works and how the call is routed to a satellite for a cross
Atlantic call then I would never be able to call my mum.
Modules provide abstraction, that's what they are for. All I as a user need
to know is that I have to pick up the receiver and to punch the right
numbers on the keypad.
> Another aspect is that some modules are
> very large, and require quite some effort before you can use them and
> still feel reasonably comfortable.
But do you really believe that if the module interface is already large and
complex that you as a novice in this particular application field would be
able create a simpler an smaller solution?
> Consequently, in order to be in control and more rapidly increase my
> own Perl/CGI knowledge, I prefer to "re-invent the wheel", before
> using modules, for tasks that I consider to be *simple enough*.
Very well said! For learning about an application area: yes. For actual
production programming: please use modules whenever feasible.
> Nevertheless, I often study modules without using them, and sometimes
> I copy methods from them.
> I Guess I'm expressing a slightly provocative view here. But am I
> really that wrong?
No, I would say it's neither provocative nor wrong. For learning of course
you write your own code. I mean, there is a reason why students are assigned
the same old projects year after year.
There is also a reason why code from those student projects is never used in
production.
Of course, when it comes to production programming then being able to
recognize the big picture and to know when not to reinvent the wheel makes
the difference between a mediocre programmer (who's mind model is stuck in
'programming-in-the-small') and a good programmer of even project lead (who
know how to apply 'programing-in-the-large' and how to leverage it).
jue
------------------------------
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 4606
***************************************