[22535] in Perl-Users-Digest
Perl-Users Digest, Issue: 4756 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 25 00:05:52 2003
Date: Mon, 24 Mar 2003 21: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 Mon, 24 Mar 2003 Volume: 10 Number: 4756
Today's topics:
Re: "globbing" command line args on W2K? <goldbb2@earthlink.net>
Re: "globbing" command line args on W2K? <wksmith@optonline.net>
accessing C++ heap data from embeded perl scripts, poss (Chage)
Re: Algorithm for Text Subsets <delautenschl@[nospam]@wisc.edu>
Re: Algorithm for Text Subsets <goldbb2@earthlink.net>
Any experience with Prima::Edit as an editor? <Norbert_Schmidt@DU3.MAUS.DE>
General goodness (strict, warnings and diagnostics?) <bobx@linuxmail.org>
Re: General goodness (strict, warnings and diagnostics? <goldbb2@earthlink.net>
Re: How stable is 'Magic'? <goldbb2@earthlink.net>
Looking for Sequential Image (non-banner) Rotation Scri (Andy)
Re: Looking for Sequential Image (non-banner) Rotation <SP_bhuisman@greywyvern.com_AM>
Re: Looking for Sequential Image (non-banner) Rotation <will@com.yahoo>
lwp protocol help <shane@excite.com>
Re: lwp protocol help <kkeller-spammmm@wombat.san-francisco.ca.us>
Re: lwp protocol help <shane@excite.com>
Re: Memory used by hashes <goldbb2@earthlink.net>
Module or Regexp for handling Win32 UNCs? <emarkert@netscape.net>
Re: Module or Regexp for handling Win32 UNCs? <goldbb2@earthlink.net>
Re: News posts with attachments <goldbb2@earthlink.net>
Re: pattern matching <spam@thecouch.homeip.net>
Re: pattern matching <tore@aursand.no>
Re: pattern matching <wksmith@optonline.net>
Re: Perl ODBC and SQL <mbudash@sonic.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 24 Mar 2003 21:24:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: "globbing" command line args on W2K?
Message-Id: <3E7FBDCB.A3332F18@earthlink.net>
Edwin Guenthner wrote:
>
> Hi there,
>
> I would like to start perl and to run with several
> scripts, like
>
> perl -MmyStuff xy*.pl
>
> That would work on Unix;
No, it won't.
It would run the *first* xy<something>.pl script, with the names of the
other scripts as it's arguments.
This is not the same thing as running several scripts.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Tue, 25 Mar 2003 05:01:53 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: "globbing" command line args on W2K?
Message-Id: <5pRfa.198660$b8.45214232@news4.srv.hcvlny.cv.net>
"Eric McDaniel" <ericm-NO-SPANM@vertical.com> wrote in message
--snip--
> This will work in Windows. Not sure about OS/2:
>
> for %x in (xy*.pl) do perl -Mmystuff %x
>
Is there a similar batch file solution to the more common problem of
globing file name arguments under windows?
example: mygrep -v *.pod
where mygrep is a .bat file which runs a perl script with the arguments
from the command line.
TIA,
Bill
------------------------------
Date: 24 Mar 2003 18:47:24 -0800
From: ericfcb@hotmail.com (Chage)
Subject: accessing C++ heap data from embeded perl scripts, possible?
Message-Id: <f61bf635.0303241847.5dee21ef@posting.google.com>
hiya all,
i wish to know is it possible for perl scripts that was embeded into
C++ code to access data structure that was allocated by C++?
will appreciate if anyone could help.
rgds,
chage
------------------------------
Date: Mon, 24 Mar 2003 20:03:55 -0600
From: "pooba53" <delautenschl@[nospam]@wisc.edu>
Subject: Re: Algorithm for Text Subsets
Message-Id: <b5oddm$d4u$1@news.doit.wisc.edu>
Thanks! I will give it a go tomorrow.
Your rapid response is quite appreciated
-Dan
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:b5nuqp$sid$3@mamenchi.zrz.TU-Berlin.DE...
> pooba53 <delautenschl@[nospam]wisc.edu> wrote in comp.lang.perl.misc:
> > I have a portion of a large Perl program where I have a hash with
> > multiple values associated with each key. Lets say I have the following
> > values associated with a key called "Gene":
> >
> > 1. actgattgaacca
> > 2. gattg
> > 3. actggtaaccggttaacctt
> >
> > The number of values varies from key to key, by the way.
> >
> > What I am trying to do with the above group is to eliminate any line of
> > text whose pattern is contained in another. In the above example line
> > number 2 would be removed because its pattern is found in the middle of
> > line 1.
> >
> > The problem I'm having is figuring our how you compare each line to
> > every other line, move to the next line, compare with all the rest,
> > etc., etc...
>
> Do it the other way round. First sort the strings descending by length.
> Start with an empty set of strings to keep. For each original string,
> see if it is contained in one of the strings you have already collected.
> If it isn't, add it to the collection, else drop it. In code:
>
> my @strings = sort { length $b <=> length $a }
> qw( actgattgaacca gattg actggtaaccggttaacctt);
>
> my @keep;
> for my $cand ( @strings ) {
> push @keep, $cand unless grep 1 + index( $_, $cand), @keep;
> }
>
> Note that index() returns -1 if the substring can't be found.
>
> Anno
------------------------------
Date: Mon, 24 Mar 2003 21:51:13 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Algorithm for Text Subsets
Message-Id: <3E7FC421.50762780@earthlink.net>
pooba53 wrote:
>
> I have a portion of a large Perl program where I have a hash with
> multiple values associated with each key. Lets say I have the
> following values associated with a key called "Gene":
>
> 1. actgattgaacca
> 2. gattg
> 3. actggtaaccggttaacctt
>
> The number of values varies from key to key, by the way.
>
> What I am trying to do with the above group is to eliminate any line
> of text whose pattern is contained in another. In the above example
> line number 2 would be removed because its pattern is found in the
> middle of line 1.
>
> The problem I'm having is figuring our how you compare each line to
> every other line, move to the next line, compare with all the rest,
> etc., etc...
If you don't mind the order being rearranged, then code like the
following should work:
while( my ($key, $value) = each %bighash ) {
my $keep = "";
foreach my $val (sort { length $b <=> length $a } @$values) {
($keep .= $val) .= " " if index($keep, $val) == -1;
}
@$value = split ' ', $keep;
}
If you need the kept items to be in the same order as they originally
were in (other than not having the now eliminated items), then try
something like this:
while( my ($key, $value) = each %bighash ) {
my $keep = "";
my @keep;
foreach my $index (
sort { length $$values[$b] <=> length $$values[$a] }
0 .. $#$values ) {
if( index( $keep, $$values[$index] ) == -1 ) {
($keep .= $$values[$index]) .= " ";
push @keep, $index;
}
}
@$value = @{$value}[ sort { $a <=> $b } @keep ];
}
[both untested]
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Tue, 25 Mar 2003 03:20:46 +0100
From: Norbert Schmidt <Norbert_Schmidt@DU3.MAUS.DE>
Subject: Any experience with Prima::Edit as an editor?
Message-Id: <r4ev7v0chfpkpcj1e0r31l4ti00le0tv9m@4ax.com>
Hello,
I just discovered the package "Prima"
<URL:http://search.cpan.org/modlist/User_Interfaces> =>
<URL:http://search.cpan.org/search%3fmodule=Prima>.
It sounds quite promising to me. But before I put much work in
building a program editor/IDE around "Prima::Edit", I'd like to know
if someone has any experience with this module concerning stability,
flexibility and maybe support.
Regards, Norbert
------------------------------
Date: Tue, 25 Mar 2003 02:35:10 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: General goodness (strict, warnings and diagnostics?)
Message-Id: <yfPfa.6231$FN.3378476@news2.news.adelphia.net>
I am just starting to really get into Perl. I currently always use "strict"
and "warnings". I have been reading a bit on "diagnostics" as well. Is
adding that to the other two overkill? Should I use one over the other? Or
should I juse use "diagnostics" when I want a clearer message of the
problem?
Thanks!
Bob
------------------------------
Date: Mon, 24 Mar 2003 22:59:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: General goodness (strict, warnings and diagnostics?)
Message-Id: <3E7FD431.23AE8717@earthlink.net>
Bob X wrote:
>
> I am just starting to really get into Perl. I currently always use
> "strict" and "warnings".
Good!
> I have been reading a bit on "diagnostics" as well. Is
> adding that to the other two overkill? Should I use one over the
> other? Or should I juse use "diagnostics" when I want a clearer
> message of the problem?
Everything that diagnostics.pm produces comes straight from the perldiag
page. If you understand the meanings of the messages produced by strict
and warnings, then there's no especial advantage of 'use diagnostics'.
If you find perl producing some message which you *don't* understand,
then there are four possible things you can do:
1/ Run "perldoc perldiag", and find the message.
2/ Send the error to a file, then run "splain" on that file.
3/ add "use diagnostics" to the program which produced the message.
4/ set the PERL5OPT environment variable to -Mdiagnostics.
These are all roughly equivilant... of course, (5) memorize the meanings
of all of the messages perl is likely to produce, is best in the long
run. (There's no need to do that *now*, though :) you'll learn them all
*eventually,* and in the meantime, there's perldiag and diagnostics and
splain.)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 24 Mar 2003 21:02:48 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How stable is 'Magic'?
Message-Id: <3E7FB8C8.54D84541@earthlink.net>
Asfand Yar Qazi wrote:
> Benjamin Goldberg wrote:
> > Abigail wrote:
> > [snip]
> >
> >>Is there a garantee the API will never change? Nope. But I don't
> >>think it will ever be marked as "this is never going to change". If
> >>perl6 goes to production, both the language and the API will have
> >>changed radically.
> >
> >
> > Perl6 won't be written in C, as perl5 is. To say "will have changed
> > radically" is a ridiculous understatement.
>
> Let me guess.. is it going to be written in 'Parrot'?
Correct. Well, actually, it's designed to be compiled to Parrot
assembly language. The current Perl6 to Parrot Assembly compiler is
written in perl5, but I'm sure that there will eventually be a Perl6
compiler written in Perl6 (after all, C compilers are written in C, and
Java compilers are written in Java, so Perl6 will surely be able to
bootstrap itself, too).
The Parrot bytecode interpreter is written in C.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 24 Mar 2003 17:04:41 -0800
From: cabaretfest@yahoo.com (Andy)
Subject: Looking for Sequential Image (non-banner) Rotation Script
Message-Id: <44405957.0303241704.244b4090@posting.google.com>
My client wants to employ a rotating image script which will load one
of a series of five images of varying sizes sequentially each time the
user reloads the page.
I've found lots of scripts that will display a different image each
time the page reloads, but none that will do so sequentially.
I've found lots of scripts that will display a sequential slide show
of images, but the client is adamant that the image change only when
the page reloads.
I'd rather not get into a heavy duty banner rotation script, since
this only involves a short series of non-banner images and no ads,
urls, sponser messages, etc.
Thanks,
Andy
------------------------------
Date: Mon, 24 Mar 2003 21:00:13 -0500
From: GreyWyvern <SP_bhuisman@greywyvern.com_AM>
Subject: Re: Looking for Sequential Image (non-banner) Rotation Script
Message-Id: <oprmkiinhfv0in9v@news.ican.net>
On 24 Mar 2003 17:04:41 -0800, Andy <cabaretfest@yahoo.com> wrote:
> My client wants to employ a rotating image script which will load one
> of a series of five images of varying sizes sequentially each time the
> user reloads the page.
>
> I've found lots of scripts that will display a different image each
> time the page reloads, but none that will do so sequentially.
>
> I've found lots of scripts that will display a sequential slide show
> of images, but the client is adamant that the image change only when
> the page reloads.
>
> I'd rather not get into a heavy duty banner rotation script, since
> this only involves a short series of non-banner images and no ads,
> urls, sponser messages, etc.
Web pages are inherently static, and when you load one page, it has
essentially no memory of the last page you were on. What you're asking
requires information to be passed between pages and based upon the
interactions at the user end.
This being said, you could either use cookies, which would require no
storage space on your part; or record a database of who has visited by IP
and serve different images based on that. I'd use cookies, but then again,
if the client refuses them, there goes your script.
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollory that nothing is rediculous.
- http://www.greywyvern.com - Forward compatible only.
------------------------------
Date: Tue, 25 Mar 2003 03:03:31 GMT
From: w i l l <will@com.yahoo>
Subject: Re: Looking for Sequential Image (non-banner) Rotation Script
Message-Id: <1mhv7vkiscabddruikrhbuo3rg7afpgg9q@4ax.com>
have you tried using cookies?
- w i l l
On 24 Mar 2003 17:04:41 -0800, cabaretfest@yahoo.com (Andy) wrote:
>My client wants to employ a rotating image script which will load one
>of a series of five images of varying sizes sequentially each time the
>user reloads the page.
>
>I've found lots of scripts that will display a different image each
>time the page reloads, but none that will do so sequentially.
>
>I've found lots of scripts that will display a sequential slide show
>of images, but the client is adamant that the image change only when
>the page reloads.
>
>I'd rather not get into a heavy duty banner rotation script, since
>this only involves a short series of non-banner images and no ads,
>urls, sponser messages, etc.
>
>Thanks,
>
>Andy
------------------------------
Date: Mon, 24 Mar 2003 16:35:14 -0800
From: "shane mos" <shane@excite.com>
Subject: lwp protocol help
Message-Id: <v7v8nc2liujvf0@corp.supernews.com>
I have a multi-homed system and I want to specify an IP when using LWP
useragent to fetch web pages. How do I do that? Thanks.
------------------------------
Date: Mon, 24 Mar 2003 17:14:01 -0800
From: Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us>
Subject: Re: lwp protocol help
Message-Id: <pgao5b.rv6.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In article <v7v8nc2liujvf0@corp.supernews.com>, shane mos wrote:
> I have a multi-homed system and I want to specify an IP when using LWP
> useragent to fetch web pages. How do I do that? Thanks.
The same way you specify a domain name.
- --keith
- --
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
public key: http://wombat.san-francisco.ca.us/kkeller/kkeller.asc
alt.os.linux.slackware FAQ: http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj5/rVkACgkQhVcNCxZ5ID9TKQCfTyIZuwPv5FfKhE4k1IKGY848
WcAAoIm0VdV2C57ls4He7RaNDiKW0h9D
=MFhF
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 24 Mar 2003 17:38:27 -0800
From: "shane mos" <shane@excite.com>
Subject: Re: lwp protocol help
Message-Id: <v7vcdsrpb21910@corp.supernews.com>
I am sorry maybe you misunderstood. I want to specify what IP to use as a
client not what the ip of the page i want to fetch....
"Keith Keller" <kkeller-spammmm@wombat.san-francisco.ca.us> wrote in message
news:pgao5b.rv6.ln@goaway.wombat.san-francisco.ca.us...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> In article <v7v8nc2liujvf0@corp.supernews.com>, shane mos wrote:
> > I have a multi-homed system and I want to specify an IP when using LWP
> > useragent to fetch web pages. How do I do that? Thanks.
>
> The same way you specify a domain name.
>
> - --keith
>
> - --
> kkeller-mmmspam@wombat.san-francisco.ca.us
> (try just my userid to email me)
> public key: http://wombat.san-francisco.ca.us/kkeller/kkeller.asc
> alt.os.linux.slackware FAQ: http://wombat.san-francisco.ca.us/cgi-bin/fom
>
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iEYEARECAAYFAj5/rVkACgkQhVcNCxZ5ID9TKQCfTyIZuwPv5FfKhE4k1IKGY848
> WcAAoIm0VdV2C57ls4He7RaNDiKW0h9D
> =MFhF
> -----END PGP SIGNATURE-----
------------------------------
Date: Mon, 24 Mar 2003 20:56:12 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Memory used by hashes
Message-Id: <3E7FB73C.9173F60A@earthlink.net>
Mike Hunter wrote:
> On Fri, 21 Mar 2003 23:29:43 GMT, Steve Grazzini wrote:
[snip]
> > On i686-linux 'ints' and 'doubles' take up 28 and 36 bytes.
>
> Ugh.
>
> I'm in a bit of a similar situation, in that I have a hash storing a
> lot of scalar values and I end up using a lot of memory. Regarding
> the packing suggestion, one has to chose the data type to pack into,
> and thus has to assert an upper limit on the data size. 32 bit
> integers aren't big enough for me, and I don't want to lose precision
> with doubles.
When you store a number in a perl scalar, and 'use integer' isn't in
effect, then your numbers *are* doubles already.
Packing with "d" won't lose you any precision.
Well, if you've been using Math::BigInt objects (which are the only way
to truly avoid loss of precision with large values) for your numbers,
then packing with "d" will lose you precision, but it doesn't sound like
you've been doing that.
> Last but not least, my perl install wasn't compiled
> with "Q", so I can't get 64 bit ints. Haven't been motivated enough
> to recompile perl, but somehow I am motivated enough to mindlessly
> complain on the news group :)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Tue, 25 Mar 2003 03:47:59 GMT
From: Me <emarkert@netscape.net>
Subject: Module or Regexp for handling Win32 UNCs?
Message-Id: <3E7FD0A7.6070103@netscape.net>
Before I spend time trying to come up with a regexp of my own I thought
I'd check to see if a module, or regexp, exists for parsing valid Win32
UNCs.
I have a program that I created that cleans up home directories and
shares - basically, it makes sure that each shared directory matches an
NT domain account.
At a bare minimum I need to parse the UNC to get the remote host name
------------------------------
Date: Mon, 24 Mar 2003 23:06:42 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Module or Regexp for handling Win32 UNCs?
Message-Id: <3E7FD5D2.21565109@earthlink.net>
Me wrote:
>
> Before I spend time trying to come up with a regexp of my own I
> thought I'd check to see if a module, or regexp, exists for parsing
> valid Win32 UNCs.
Uhh, File::Spec ?
> I have a program that I created that cleans up home directories and
> shares - basically, it makes sure that each shared directory matches
> an NT domain account.
>
> At a bare minimum I need to parse the UNC to get the remote host name
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 24 Mar 2003 21:38:12 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: News posts with attachments
Message-Id: <3E7FC114.4CE78ECB@earthlink.net>
Bigus wrote:
>
> Hi
>
> If I download the message body of a news post, using NNTPClient
> module, and it has an attachment - for example a JPG image file or an
> M$ Word document, how can I turn the attachment back into a proper
> file?
That depends -- if the attachment is done using a MIME multipart
document, then obviously you'll need a MIME parser... the most
recommended one is in the MIME-tools-5.411a distribution from CPAN.
If the attachment is done with uuencoding (which your example is), then
you could probably do:
my @attachments = map unpack("u", $_),
$message =~ m[^begin [0-7]+ .*+\n(.*?)^end\n]mg;
If you want to keep the names as well as the bodies of the attachments,
then:
my %attachments;
while( $message =~ m[^begin [0-7]+ (.*+)\n(.*?)^end\n]mg ) {
$attachments{$1} = unpack("u", $2);
}
[snip]
> I presume there must be some generic way of doing it, since a
> newsreader can't possibly have filters for every type of file in
> existance and yet any type of file attached to a message will show as
> an attachment, if you see what I mean.. is it somehow converting the
> file back into a binary format?
The newsreader identifies uuencoded attachments using the 'begin ...
end' markers that surround them. It then uses either the filename of
the attachment, or else the first few bytes of it, to identify what type
of file it is, and either displays it (if it's an image), or shows a
link, which would be used to save the attachment to a file.
> How could I do that in Perl?
See above.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 24 Mar 2003 18:32:55 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: pattern matching
Message-Id: <JAMfa.22386$f91.387272@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Arun Harnoor wrote:
>
> I am a newbie to perl...I have an array of words - and I need to do a
> pattern match/substitution of these words on this line...something like:
> for($i=0;$i<Num_words;$i++)
> {
> $line=~s/$word[$i]/$newword[$i]/;
> }
>
> I know that the above line won't work-- but it conveys best, what I want.
> essentially my pattern is a variable....can someone help?
You really should make use of perl's hashes here. Here's an example:
%opposites = (
"white" => "black",
"red" => "green",
"blue" => "orange",
);
$line = "The white bear wore a red and blue outfit";
foreach (keys %opposites) {
$line =~ s/$_/$opposites{$_}/gi;
}
print $line, "\n";
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+f5WpeS99pGMif6wRAvgCAJ93XHbkHhoCEBR1uM4Apc1mQzr22gCg+7+o
0yTrUj6bOV9BWyWWUu8oD+s=
=cCwS
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 25 Mar 2003 01:12:16 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: pattern matching
Message-Id: <pan.2003.03.24.22.43.43.901943@aursand.no>
On Mon, 24 Mar 2003 13:37:50 -0800, Arun Harnoor wrote:
> I am a newbie to perl...I have an array of words - and I need to do a
> pattern match/substitution of these words on this line...something like:
> for($i=0;$i<Num_words;$i++)
> {
> $line=~s/$word[$i]/$newword[$i]/;
> }
This code _should_ work. However, try to do it the Perl way;
for ( @words ) {
...
}
}
> I know that the above line won't work--
How do you know that?
--
Tore Aursand
------------------------------
Date: Tue, 25 Mar 2003 03:56:53 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: pattern matching
Message-Id: <9sQfa.198485$b8.45020006@news4.srv.hcvlny.cv.net>
"Arun Harnoor" <harnoor@seas.ucla.edu> wrote in message
news:Pine.GSO.4.44.0303241331360.13672-100000@riverside...
>
>
> I am a newbie to perl...I have an array of words - and I need to do a
> pattern match/substitution of these words on this line...something
like:
> for($i=0;$i<Num_words;$i++)
> {
> $line=~s/$word[$i]/$newword[$i]/;
> }
>
> I know that the above line won't work-- but it conveys best, what I
want.
It conveys what you want well because it is valid except for the missing
'$' which use warnings would have told you. It should have worked
correctly for most lines (unless the same substitution was needed more
than once within a single line.)
> essentially my pattern is a variable....can someone help?
BTW, the "Perl Cookbook" Recipe 1.17 (Program fixstyle) provides
several other solutions to this problem along with suggestions on how to
choose the best one for you application.
Enjoy
Bill
------------------------------
Date: Mon, 24 Mar 2003 23:53:48 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Perl ODBC and SQL
Message-Id: <mbudash-D984CD.15534724032003@typhoon.sonic.net>
In article <pan.2003.03.24.22.39.05.514413@aursand.no>,
"Tore Aursand" <tore@aursand.no> wrote:
> On Mon, 24 Mar 2003 17:42:55 +0000, Michael Budash wrote:
> > my $sth = $dbh->prepare('SELECT *
> > FROM userstable
> > WHERE user = ' . $dbh->quote($nickname) . '
> > ORDER BY thedate DESC');
>
> Warning: bind()'ing parameters is a _far_ better method! :)
i agree, i merely wanted to note that there *is* another way. plus,
since not all drivers support placeholders and bind values, it's nice to
have another tool in the box...
--
Michael Budash
------------------------------
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 4756
***************************************