[10821] in Perl-Users-Digest
Perl-Users Digest, Issue: 4422 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 14 17:07:19 1998
Date: Mon, 14 Dec 98 14:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Dec 1998 Volume: 8 Number: 4422
Today's topics:
'lock' get compiler error <r28629@email.sps.mot.com>
Re: 'lock' get compiler error <Allan@due.net>
Authetication, quick 'n' dirty johnvv@hotmail.com
Re: Bug (array ref in a "void" context) (Bart Lateur)
Re: Bug (array ref in a "void" context) (Larry Rosler)
Re: Bug (array ref in a "void" context) (Tad McClellan)
Re: diagnostics <freeking@nospam.hub.ofthe.net>
fork and defunct processes <cjc@scitec.com>
How to extract emails from HTML page <philip.class@popcorn-studio.ch>
Re: length and width info from image files (Bart Lateur)
Loop Timing (Toe Jam)
Re: ls -l in perl? <kin@symmetrycomm.com>
Re: Newbie Question (Joergen W. Lang)
Re: non-blocking socket connect question <mike@CUTsinglepointsys.com>
Re: OLE referencing problem: PerlScript, ASP and CDONTS bdavis@mediaphex.com
Re: OLE referencing problem: PerlScript, ASP and CDONTS (Jan Dubois)
Re: passing multiple keyed arrays to a subroutine (Andrew M. Langmead)
pattern matching question (Cybernetic Bear)
Re: pattern matching question (Cybernetic Bear)
Re: pattern matching question (Tad McClellan)
Perl and reading from log files (Marc Haber)
Re: Perl and reading from log files <kprice@cardinal.co.nz>
Re: preserving case insensitive after splitting a strin <Allan@due.net>
Re: preserving case insensitive after splitting a strin (Andre L.)
Re: renaming an array with a number at the end (Tad McClellan)
Re: Script to Convert Text to HTML (Larry Rosler)
Sorting a Two-dimensional Numerical Array <tbriles@austin.ibm.com>
Re: sorting hashes (Tad McClellan)
Re: Writing in a file ... (Tad McClellan)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Dec 1998 13:46:15 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: 'lock' get compiler error
Message-Id: <36756B07.FC02788B@email.sps.mot.com>
Is 'lock' a keywork/function? I named a experiemental sub with 'lock'
but I am getting compiler error:
-------------------------------------------------------
DB<1> lock
Not enough arguments for lock at (eval 4) line 2, at EOF
[106] % perldoc -f lock
No documentation for perl function `lock' found
[107] % perl -v
This is perl, version 5.005_01 built for PA-RISC1.1
Copyright 1987-1998, Larry Wall
-------------------------------------------------------
Thanks.
-TK
------------------------------
Date: Mon, 14 Dec 1998 16:11:52 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: 'lock' get compiler error
Message-Id: <753vjc$r6b$1@camel18.mindspring.com>
Tk Soh wrote in message <36756B07.FC02788B@email.sps.mot.com>...
>Is 'lock' a keywork/function? I named a experiemental sub with 'lock'
>but I am getting compiler error:
>-------------------------------------------------------
> DB<1> lock
>Not enough arguments for lock at (eval 4) line 2, at EOF
>[106] % perldoc -f lock
>No documentation for perl function `lock' found
>[107] % perl -v
>This is perl, version 5.005_01 built for PA-RISC1.1
>Copyright 1987-1998, Larry Wall
>-------------------------------------------------------
>Thanks.
>-TK
Hmm, under 5.004_02 no problems. Version 5.005_02, I get the same error.
Curious. It only happens when I declare the sub after the first time I call
it, and the error goes away if I use &lock instead of lock().
AmD
------------------------------
Date: Mon, 14 Dec 1998 20:39:07 GMT
From: johnvv@hotmail.com
Subject: Authetication, quick 'n' dirty
Message-Id: <753t1b$ilo$1@nnrp1.dejanews.com>
Hello all,
I am creating an OO dataserver and up til now I have been updating overnight.
I will soon be starting to update from my CGI's and my question is, which
module is the quickest to implement this?? Security is only a minimal concern
here.
Thanks in advance, John van V. aka pres CXN,Inc. (& chief bottle washer ;)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 14 Dec 1998 19:58:00 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Bug (array ref in a "void" context)
Message-Id: <367761f1.622025@news.skynet.be>
Tk Soh wrote:
>> > $aryref ||= $updated++,[1,2,3];
>anyway, what are you trying to do in that line?
Ah, the secret life of programmers... :-)
Well, I have a project which involves converting a file, and making
translations of cells (properties of products) at the same time. The
translations are reused a lot, and are in an external table.
If a property isn't found in the table, a default is picked: for plain
translations, it's the property itself (it could be a name).
All properties are stored in a hash of anonymous arrays, each containing
the translations for a phrase in an identical structure. If a property
isn't in the hash, it has no translation, and the default is constructed
and used. That's what the ||= is for. Note that any array ref counts as
TRUE.
The changed table is saved, which makes it easier for the user to add
missing translations) but only IF it's actually changed. That's what the
$updated++ is for: this variable keeps count of the additions.
The next code works (3 plain languages) but doesn't keep a flag:
$translation{$phrase} ||= [$phrase,$phrase,$phrase];
These work too, including a flag:
$translation{$phrase} ||= do {$updated++;[$phrase,$phrase,$phrase]};
or
$translation{$phrase} ||= ($updated++,[$phrase,$phrase,$phrase]);
but not:
$translation{$phrase} ||= $updated++,[$phrase,$phrase,$phrase];
You may safely state that I was very puzzled that my code didn't work.
As I said before, the ||= appears to have a higher precedence than the
comma operator. I can't say that that makes much sense to me.
Bart.
------------------------------
Date: Mon, 14 Dec 1998 12:51:41 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Bug (array ref in a "void" context)
Message-Id: <MPG.10df1a3c42750a449898c3@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <367761f1.622025@news.skynet.be> on Mon, 14 Dec 1998 19:58:00
GMT, Bart Lateur <bart.lateur@skynet.be> says...
> >> > $aryref ||= $updated++,[1,2,3];
$aryref ||= do { $updated++; [1, 2, 3] };
> You may safely state that I was very puzzled that my code didn't work.
> As I said before, the ||= appears to have a higher precedence than the
> comma operator. I can't say that that makes much sense to me.
This has been in the C precedence rules from the beginning. For one
thing, it allows arbitrarily complex expressions (including assignment
side-effects) to be the arguments of function calls, as others have
mentioned.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 14 Dec 1998 14:51:00 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Bug (array ref in a "void" context)
Message-Id: <knt357.ek6.ln@magna.metronet.com>
Bart Lateur (bart.lateur@skynet.be) wrote:
: #! perl -w
: $aryref ||= $updated++,[1,2,3];
: ($\,$,) = ("\n","/");
: print $aryref,$updated;
: Result:
: > Useless use of scalar ref constructor in void context at voidref.t line 2.
: > 0/1
: Note that $ayref does get set to a proper array reference if you drop
: the "$updated++," part.
It is unclear to me what it is that you think is a bug.
You probably should have said what it is that you _want_ it
to do...
Looks like a precedence issue to me.
perl sees:
($aryref ||= $updated++) ,[1,2,3];
since assignment and logical opertors are higher precedence
than the comma operator.
Does this fix the "bug"?
$aryref ||= ($updated++ ,[1,2,3]);
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 12 Dec 1998 15:27:00 -0600
From: "Richard H. King" <freeking@nospam.hub.ofthe.net>
Subject: Re: diagnostics
Message-Id: <753v47$lkk$1@remarQ.com>
|How can I keep these longer diagnostic messages from
|scrolling by so I only see the bottom part?
You'll have to make STDERR funnel to STDOUT and I'm not too sure how
to do this in DOS. Did you try piping it to more?
perl myprog.pl | more
All errors (IE "warn"s) go to different a stream than normal output
(IE "print"s). This is a feature, more or less (no pun intended).
This way, when you redirect, you don't get error messages in your
outputted files (could make some big messes).
If the above doesn't work, then you'll have to do it in Perl instead
of DOS. That constitutes something like this:
*STDERR = \*STDOUT;
HTH,
-Ryan King
------------------------------
Date: Mon, 14 Dec 1998 16:14:30 -0500
From: "Crist J. Clark" <cjc@scitec.com>
Subject: fork and defunct processes
Message-Id: <36757FB6.41C67EA6@scitec.com>
I am having a fairly wicked problem with a perl script I
inherited (i.e. I'm not the perl 'expert' who authored it).
The script runs as a cron job in off-hours to do some downloads
over the Internet. After each download, it forks a process
to compress the freshly d/l'ed file. Now, the problem is that
when the compression program completes, the forked parent process
becomes a 'defunct' process on the OS, but does not go away.
These defunct processes build up, and eventually the user executing
the script runs out of processes.
Here is what I believe is the offending code fragment,
unless (fork) {
`gzip -9 $lfile`;
exit;
}
The Perl version I'm running,
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 1.7.2.2 $$Date: 1998/03/12 19:27:47 $
Patch level: 36
And my OS is IRIX 5.3.
Is there a smarter way to do this so that it works? Or an ugly kludge?
Is this expected behavior from perl/the OS? Or is something not working
as it should in perl/the OS?
I've had a look through perl manpages and tried some FAQ's but have not
been able to locate a reference to this type of problem. Thanks for any
help.
--
Crist J. Clark cjc@scitec.com
SciTec, Inc
------------------------------
Date: Mon, 14 Dec 1998 22:15:51 +0100
From: "Philip Class" <philip.class@popcorn-studio.ch>
Subject: How to extract emails from HTML page
Message-Id: <753vhk$ojf$3@bw107zhb.bluewin.ch>
Does anyone know if there's a module that extracts email-adresses from a
huge textfile or html page and stores these emailadresses in a file.
The output should be a list (file) containing all emails, that originally
have been somewhere in the html-file.
Thanks a lot for your help,
Philip
------------------------------
Date: Mon, 14 Dec 1998 20:17:50 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: length and width info from image files
Message-Id: <36767092.1366369@news.skynet.be>
J. Roy Andrada wrote:
> First of all, is it possible to extract this
> information from an image file such as GIF and JPEG?
Yes. There's a module on CPAN (goto www.perl.com if you haven't been at
CPAN before) called Image::Size. It can work, amongst others, with JPEG
and GIF. Get it. Install it, which mainly means putting the file Size.pm
in a subfolder Image, in one of your Lib roots.
> Secondly, if it is, can you please show me how to
> do this with PERL?
Well, there are some examples in the pm file.
use Image::Size;
# Get the size of globe.gif, in your current directory
($globe_x, $globe_y) = imgsize("globe.gif");
Now, $globe_x is the width in pixels, and $globe_y the height.
Bart.
------------------------------
Date: 14 Dec 1998 20:47:12 GMT
From: toejam@nirvana.net (Toe Jam)
Subject: Loop Timing
Message-Id: <753tgg$k3e@news-central.tiac.net>
I'm looking for the command or code to run a loop on a
user-defined timer, so if the user instructs the loop to run every 15
seconds, it would. Please forward any ideas or resources to
toejam@nirvana.net
Thank you.
------------------------------
Date: 14 Dec 1998 13:03:42 +0000
From: Kin Cho <kin@symmetrycomm.com>
Subject: Re: ls -l in perl?
Message-Id: <uk8zu6fkh.fsf@server3.symmetrycomm.com>
> It's not a module, but here is a reasonable approximation
> as a program:
Other than getpwuid and getgrgid, the code works well under Win32.
Thanks!
-kin
------------------------------
Date: Mon, 14 Dec 1998 21:33:30 +0100
From: jwl@worldmusic.de (Joergen W. Lang)
Subject: Re: Newbie Question
Message-Id: <1dk1q4j.187q2cgmtfygeN@host026-210.seicom.net>
Joergen W. Lang <jwl@worldmusic.de> wrote:
> and it should be working.
> you need quotes if you require() an external file like
>
> require getopt.pl;
sure, should be
require "getopt.pl"; or
require 'getopt.pl';
mea culpa :-)
Joergen
--
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
-------------------------------------------------------------------
------------------------------
Date: Mon, 14 Dec 1998 15:43:38 -0500
From: "Mike Marshall" <mike@CUTsinglepointsys.com>
Subject: Re: non-blocking socket connect question
Message-Id: <753uhg$sir@dfw-ixnews3.ix.netcom.com>
Adam,
I was recently looking for those answers myself.... A web search turned up
this sweet little article..:
http://www.hotwired.com/webmonkey/code/97/18/index2a.html
Hope that helps.
Mike
Adam Levy wrote in message ...
>I just started playing with sockets, so excuse my ignorance. What I'm
>looking to do is, in a script, connect to two servers, send some data to
>the servers as they accept, and then keep checking to see if any input has
>come in from either.
>
>I assume I'm looking to make these non-blocking because I don't want one
>connect to not allow me to make the other, but don't quite know how.
>
> 1. How do I make the socket non-blocking?
> 2. How do I then know when the connection has been made so I can send the
>data?
> 3. How do I know when its ready to be read?
> 4. And finally, how would I read it? (I read somewhere about using
>sysread when using non-blocking)
>
>Any help would be so greatly appreciated. Thank you,
> -Adam Levy
------------------------------
Date: Mon, 14 Dec 1998 21:06:37 GMT
From: bdavis@mediaphex.com
Subject: Re: OLE referencing problem: PerlScript, ASP and CDONTS.NewMail object
Message-Id: <753ukr$k9f$1@nnrp1.dejanews.com>
matt@teamamiga.org wrote:
> You can only do this on AS perl build 504 and above (so make sure you
> upgrade), and the syntax would be:
>
> $obj->Value->SetProperty('Item', 'header', 'headervalue');
>
> (I think)...
The format above dies with the message:
Can't call method "SetProperty" on an undefined value
It will compile as:
$obj->{Value}->SetProperty('Item', 'header', 'headervalue');
but does not seem to do anything useful. There are no warnings or errors
generated, but the header is not set in the resulting message.
I am using build 507 from ActiveState.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 14 Dec 1998 22:24:00 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: OLE referencing problem: PerlScript, ASP and CDONTS.NewMail object
Message-Id: <367c7f04.5204974@news3.ibm.net>
Matt Sergeant <matt@teamamiga.org_NOSPAM> wrote:
>bdavis@mediaphex.com wrote:
>>
>> I'm trying to use the CDONTS.NewMail object from the SMTP server component of
>> IIS 4 from a PerlScript driven ASP page. I've gotten the basic functionality
>> of the object mapped over to PerlScript. I can set the standard headers and
>> send the mail message. I have not however been able to set arbitrary headers.
>>
>> A method named Value is used to set arbitrary message headers. Its VBScript
>> syntax is:
>>
>> <object ref>.Value(header) = strHdrValue.
>
>This is using the SetProperty with multiple values system. It's a
>horrible horrible thing. Unfortunately MS think it's useful, so you're
>stuck with it.
What he said. :-(
>You can only do this on AS perl build 504 and above (so make sure you
>upgrade), and the syntax would be:
You need Win32::OLE version 0.10 or later.
>$obj->Value->SetProperty('Item', 'header', 'headervalue');
>
>(I think)...
I think the following is more likely:
$obj->SetProperty('Value', 'header', 'headervalue');
-Jan
------------------------------
Date: Mon, 14 Dec 1998 20:35:54 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: passing multiple keyed arrays to a subroutine
Message-Id: <F3z2Ju.49n@world.std.com>
mguz@sol.co.uk (Mark Guz) writes:
>I am trying to pass multiple keyed arrays to a subroutine, and i cant
>seem to see how to do it.
When you pass parameters to perl subroutines, it flattens all of them
into a single list @_, and then most subroutines copy their parameters
into local variables at the beginning of the subroutine. (as you are
doing.) If you want to pass multiple hashes, one choice is to create
references to them and pass scalars that contain the references.
check(\%array1, \%array2);
sub check {
my($inarray1, $inarray2) = @_;
# and now refer to each hash as $inarray1->{key}
}
--
Andrew Langmead
------------------------------
Date: Mon, 14 Dec 1998 19:03:43 GMT
From: cybear_x[nospam]@geocities.com (Cybernetic Bear)
Subject: pattern matching question
Message-Id: <36755fbc.264083643@news.webhart.net>
Hello,
I have two problems which I am hoping you can help me with. I have a
dataset that contains the following
name date quantity interval
"dave" 10/20/98 45 20
I can read in the data into seperate variables for each header (ie
$name, $date, $quantity, $interval).
What I want to do is a) remove the quotes from $name, and b) seperate
the $date field to a seperate variable for $day, $month and $year.
I assume you use the split() command, but the exact syntax for
basically #name = ($name with no quotes) confuses me to no end. I'm
sure its a simple problem, but the resources I have available to me
are at a more advanced level than I am.
Any help will be greatly appreciated.
Thanks in advance
Dave
------------------------------
Date: Mon, 14 Dec 1998 19:23:40 GMT
From: cybear_x[nospam]@geocities.com (Cybernetic Bear)
Subject: Re: pattern matching question
Message-Id: <36756599.265585189@news.webhart.net>
I managed to solve my own problem. Thanks anyways for your help
Dave
On Mon, 14 Dec 1998 19:03:43 GMT, cybear_x[nospam]@geocities.com
(Cybernetic Bear) wrote:
>Hello,
>
>I have two problems which I am hoping you can help me with. I have a
>dataset that contains the following
>
>name date quantity interval
>"dave" 10/20/98 45 20
>
>I can read in the data into seperate variables for each header (ie
>$name, $date, $quantity, $interval).
>
>What I want to do is a) remove the quotes from $name, and b) seperate
>the $date field to a seperate variable for $day, $month and $year.
>
>I assume you use the split() command, but the exact syntax for
>basically #name = ($name with no quotes) confuses me to no end. I'm
>sure its a simple problem, but the resources I have available to me
>are at a more advanced level than I am.
>
>Any help will be greatly appreciated.
>
>Thanks in advance
>Dave
------------------------------
Date: Mon, 14 Dec 1998 15:09:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: pattern matching question
Message-Id: <6qu357.o77.ln@magna.metronet.com>
Cybernetic Bear (cybear_x[nospam]@geocities.com) wrote:
: I have two problems which I am hoping you can help me with. I have a
: dataset that contains the following
: name date quantity interval
: "dave" 10/20/98 45 20
: I can read in the data into seperate variables for each header (ie
: $name, $date, $quantity, $interval).
: What I want to do is a) remove the quotes from $name,
$name =~ tr/"//d; # delete all double quote chars
: and b) seperate
: the $date field to a seperate variable for $day, $month and $year.
($day, $month, $year) = split m#/#, $data;
(though something tells me you meant to say "$month, $day and $year" ;-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Dec 1998 21:41:13 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Perl and reading from log files
Message-Id: <7540lo$4rk$3@news.rz.uni-karlsruhe.de>
Hi!
I have the following perl code (that was not written by me - it would
have perl -w and no goto in that case):
|#!/usr/bin/perl
|
|$difftime=60;
|$HUPped=0;
|
|$SIG{HUP} = sub { $HUPped++; };
|
|open(MESSAGES,"</some/log/file");
|
|seek MESSAGES,0,2;
|
|$index=0;
|
|loop:
|
|if( $HUPped )
|{
| print "HUPped\n";
| close(MESSAGES);
| open(MESSAGES,"</some/log/file");
| seek MESSAGES,0,2;
| $HUPped=0;
|}
|
|$line=<MESSAGES>;
|
|print "$line\n";
|
| # do something if $line matches something else
|
|sleep 5;
|
|goto loop;
I am mainly concerned about two things:
(1)
Will that if ($HUPped) construct work as desired and help the program
to survive rotation of the log file? Since there is more than one way
to do it [tm], is there a more elegant one?
(2)
Due to the daemon reading always at the end of file, it does not wait
for the next line to be printed, hence the sleep 5. This is very ugly.
Is there a more beautiful way to make the program wait until the next
line has been written to the log?
Any hints will be appreciated.
Greetings
Marc
--
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber | " Questions are the | Mailadresse im Header
Karlsruhe, Germany | Beginning of Wisdom " | Fon: *49 721 966 32 15
Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29
------------------------------
Date: Tue, 15 Dec 1998 10:55:58 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Perl and reading from log files
Message-Id: <3675896E.DCA4E5DB@cardinal.co.nz>
Marc Haber wrote:
>
<snip>
> (2)
> Due to the daemon reading always at the end of file, it does not wait
> for the next line to be printed, hence the sleep 5. This is very ugly.
> Is there a more beautiful way to make the program wait until the next
> line has been written to the log?
I don't know about (1), but see if you like this suggestion for (2)
open (LOGFILE, "tail -f /some/log/file|") or die "a horrible death";
while ( defined($log_message=<LOGFILE>) ) {
&do_something;
};
Needs more work, but the meat of the idea is there. (IE. tail -f
filename)
HTH
------------------------------
Date: Mon, 14 Dec 1998 15:22:05 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: preserving case insensitive after splitting a string
Message-Id: <753rnp$kq1$1@camel18.mindspring.com>
Jason Q. wrote in message <36771c83.42747338@news.cyberway.com.sg>...
>PROBLEM 1
>I have a case insensitive (?i)$string.
>If I split that string into an @array, every element no longer remain
>case insensitive.
>I manage to reverse this by placing each $array[n] in a loop which
>makes them case insensitive again but is there an easy way to force
>the element to remain case insensitive when splitting them?
Not quite sure what you are trying to do here. The much earlier post's
suggestion to just uc or lc seems best.
>**************************
>PROBLEM 2
>@array = (bird, hand, worth, bush);
>$string = "bird in hand is worth two in bush";
>
>If ($string contains every element in @array)
> {
> do this;
> }
>
Well, here is one way to do it. A little late, but I have had a busy day.
#!/usr/local/bin/perl -w
use strict;
my @array = qw (bird bush hand worth bush);
my $string = "bird in hand is worth two in bush";
$_ = $string; #saves a lot of chars in the join
my $match_string = '/\b'.join ('\b/ and /\b',@array).'/';
eval $match_string ? print "Matched": print "No match";
and you can always "do this" instead of printing. You could speed this up,
but I will leave that for another day.
AmD
------------------------------
Date: Mon, 14 Dec 1998 14:11:47 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: preserving case insensitive after splitting a string
Message-Id: <alecler-1412981411470001@dialup-441.hip.cam.org>
In article <36771c83.42747338@news.cyberway.com.sg>,
pigs_can_fly@mindless.com (Jason Q.) wrote:
> I have a case insensitive (?i)$string.
> If I split that string into an @array, every element no longer remain
> case insensitive.
A match expression can be case-insensitive, but an element of an array is
not inherently case-insensitive, it is just what it is.
[...]
> @array = (bird, hand, worth, bush);
> $string = "bird in hand is worth two in bush";
>
> If ($string contains every element in @array)
> {
> do this;
> }
Here's a "loopless" solution.
$_ = 'bird in hand is worth two in bush';
my @words = qw(Bird hANd wOrTh BUSH);
if (eval join ' && ', map { '/\b'.quotemeta().'\b/i' } @words) {
print "All the words match.\n";
}
HTH,
Andre
------------------------------
Date: Mon, 14 Dec 1998 14:36:55 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: renaming an array with a number at the end
Message-Id: <7ts357.ek6.ln@magna.metronet.com>
Jason Q. (pigs_can_fly@mindless.com) wrote:
: I have this seemingly simple task but am new to Perl so if any one
: would help...
: Within a while loop, I need to rename an array each time it goes
: through the loop. @array0 changes to @array1 changes to @array2...
It sounds to me like you are using the wrong data structure.
What you describes sounds like a list-of-lists to me.
Luckily, there is a man page included with the perl distribution
about list-of-lists data structures. It is named, appropriately:
"perllol.pod". Have a look at it.
: this is what I have but my syntax at @array[$y] is wrong. How should I
: 'phrase' it?
What you want to do (which is not what you *should* do) is called
a "Symbolic reference" see the section with that name in the
'perlref.pod' man page.
: *********************
: $y = 0;
: while (a certain condition)
: {
: @array[$y];
That isn't doing anything, even if you did have the right syntax.
All it does is make a list in a void context that is immediately
discarded.
Don't you want to _do_ something with the array elements?
Don't do this, though it will work (if I understand you correctly)
push @{"array$y"}, (1, 2, 3); # put three things in the array
: $y++;
: }
: ********************
Are you wondering yet why I keep saying to not do it the way
you appear to be trying to do it?
;-)
See:
http://www.plover.com/~mjd/perl/#varvarname
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Dec 1998 12:10:38 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Script to Convert Text to HTML
Message-Id: <MPG.10df109a2b3fd8359898c2@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <753oo7$2pv$1@gellyfish.btinternet.com> on 14 Dec 1998
19:25:59 -0000, Jonathan Stowe <gellyfish@btinternet.com> says...
> On Mon, 14 Dec 1998 11:44:36 EDT sugar@HWS.EDU wrote:
...
> print "<TD>$field</TD>\n";
...
> Of course I dont understand your data so it probably isnt as want it but
> I leave that as an exercise for the reader.
Well, if the data contain anything that might look like HTML tags, the
above line might benefit by being preceded by:
$field =~ s/</</g;
$field =~ s/>/>/g;
I *know* there is a module URI/Escape_or_whatever to do this, but you
didn't use a module to generate the HTML, so I certainly won't!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 14 Dec 1998 15:28:31 -0600
From: Tom Briles <tbriles@austin.ibm.com>
Subject: Sorting a Two-dimensional Numerical Array
Message-Id: <367582FF.EAADCABF@austin.ibm.com>
What's the best (or any!) way to sort the following array on the second
dimension (in this example 1, 2.5, and 2.5):
util[0][0]=50
util[0][1]=1
util[1][0]=45
util[1][1]=2.5
util[2][0]=60
util[2][1]=2.5
No entries are guaranteed to be unique, so I don't see a way to use a hash.
I'd also like to sort on the first dimension after sorting on the second.
TIA,
Tom
------------------------------
Date: Mon, 14 Dec 1998 14:39:28 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: sorting hashes
Message-Id: <02t357.ek6.ln@magna.metronet.com>
cnsxxx@my-dejanews.com wrote:
: How do I sort the hash to print out both the keys and values
: sorted by the values?
Perl FAQ, part 4:
"How do I sort a hash (optionally by value instead of key)?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Dec 1998 14:38:14 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Writing in a file ...
Message-Id: <mvs357.ek6.ln@magna.metronet.com>
Yoann Le Corvic (yoann.lecorvic@inrfasoft-civil.com) wrote:
: I would like for example to add a line in a table of a file
: Does anyone knows how to do this,
Perl FAQ, part 5:
"How do I change one line in a file/
delete a line in a file/
insert a line in the middle of a file/
append to the beginning of a file?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
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 4422
**************************************