[19817] in Perl-Users-Digest
Perl-Users Digest, Issue: 2012 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 25 18:10:41 2001
Date: Thu, 25 Oct 2001 15:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004047816-v10-i2012@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 25 Oct 2001 Volume: 10 Number: 2012
Today's topics:
Re: Printing Images in a Web browser <bart.lateur@skynet.be>
problem with break... <tanathos21@yahoo.com>
Re: problem with break... <wolfram.pfeiffer@bigfoot.com>
Re: problem with break... <uri@sysarch.com>
Re: problem with break... <tanathos21@yahoo.com>
Re: problem with break... <uri@sysarch.com>
Re: problem with break... <tanathos21@yahoo.com>
Regex to swap HTML tags (Barry Krusch)
Re: Regex to swap HTML tags (Logan Shaw)
replacing bad old FormMail <yahoo_com@francis.uy>
String Substitution (Urgent) (Saurabh Goyal)
Re: String Substitution (Urgent) <vmurphy@Cisco.Com>
Re: String Substitution (Urgent) <lmoran@wtsg.com>
Re: String Substitution (Urgent) <mjcarman@home.com>
Re: String Substitution (Urgent) <darkon@one.net>
Re: String Substitution (Urgent) (John J. Trammell)
Re: String Substitution (Urgent) <uri@sysarch.com>
Re: String Substitution (Urgent) (John J. Trammell)
Re: Stripping Duplicates From Arrays <joeg@optonline.net>
Re: Telnet client in perl <news@scottbell.org>
VVP:making a string=string. (vivekvp)
Re: VVP:making a string=string. (John J. Trammell)
Re: What's wrong with File::Find <nospam-abuse@ilyaz.org>
Re: What's wrong with File::Find <nospam-abuse@ilyaz.org>
Re: Win32 Perl book/software suggestions? <tsee@gmx.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Oct 2001 21:48:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Printing Images in a Web browser
Message-Id: <932httstcs04n60qat442p91nclvcs1ikn@4ax.com>
Mina Naguib wrote:
>> # What I got from the the db is the images in a scalar.
That's the raw data?
>However for a quick fix to see if that IS your problem, try this:
>
>print "Content-type: image/gif\n\n";
>print img{src => $image};
No... rather:
print "Content-Type: image/gif\n\n";
binmode STDOUT;
print $image;
--
Bart.
------------------------------
Date: Thu, 25 Oct 2001 16:01:39 -0400
From: "Jerome" <tanathos21@yahoo.com>
Subject: problem with break...
Message-Id: <vd_B7.6379$cE2.259030@weber.videotron.net>
Hi, here is a piece of code I am working on, and I'm not sure that the
function break works the same way in perl than in C. Take a look at this:
#!/usr/bin/perl
open (DB, "< originaltext.txt");
@lines = <DB>;
close (DB);
open (RESULT, ">> results.txt");
for ($num = 0; $lines[$num]; ){
$isone = 0;
for ($x = 0; ; $x++){
$tempdata[$x] = $lines[$num];
$num++;
if ($tempdata[$x] eq "\n"){
break;
}
}
for ($y = 0; $tempdata[$y]; $y++){
if ($tempdata[$y] eq "print this block\n"){
$isone = 1;
}
}
if ($isone == 1){
for ($z = 0; $tempdata[$z]; $z++){
print RESULT "$tempdata[$z]\n";
}
}
}
close (RESULT);
What I want to do with this code is take a text database that has separate
block of informations all separated by empty lines. I want to go through the
block and see if a certain information is present, and if it is, print the
whole block to the result file. But break seems not to work for me. Is there
another command in perl that is the equivalent of break in C? Thanks for the
help.
Jerome
------------------------------
Date: 25 Oct 2001 20:17:35 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: problem with break...
Message-Id: <9r9s0v$kep$2@news.rz.uni-karlsruhe.de>
Jerome <tanathos21@yahoo.com> wrote:
> Hi, here is a piece of code I am working on, and I'm not sure that the
> function break works the same way in perl than in C. Take a look at this:
[ code snipped ]
> What I want to do with this code is take a text database that has separate
> block of informations all separated by empty lines. I want to go through the
> block and see if a certain information is present, and if it is, print the
> whole block to the result file. But break seems not to work for me. Is there
> another command in perl that is the equivalent of break in C? Thanks for the
> help.
I suggest setting $/ to "\n\n" (perldoc perlvar for details).
This way you can slurp each complete block of information at once, so
you can probably get rid of this ugly construct with break and the
$isone flag completely.
Wolfram
--
Does anyone know the syntax for creating self-decrypting archives with GPG?
-- zchaggs, alt.unix.wizards
------------------------------
Date: Thu, 25 Oct 2001 20:36:18 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: problem with break...
Message-Id: <x71yjr318v.fsf@home.sysarch.com>
>>>>> "J" == Jerome <tanathos21@yahoo.com> writes:
J> Hi, here is a piece of code I am working on, and I'm not sure that the
J> function break works the same way in perl than in C. Take a look at this:
J> #!/usr/bin/perl
no -w, BAD!
it would have told you something about break.
no strict, BAD.
J> open (DB, "< originaltext.txt");
J> @lines = <DB>;
J> close (DB);
J> open (RESULT, ">> results.txt");
no checking the results of open, BAD.
J> for ($x = 0; ; $x++){
you have c stylitis. learn perl style and you will have cleaner and
better code.
J> if ($tempdata[$x] eq "\n"){
J> break;
J> }
FYI: break is not a keyword in perl. see my -w comment above. so it
can't work like in c as it doesn't exist.
read perlsyn for how to exit a loop.
J> What I want to do with this code is take a text database that has
J> separate block of informations all separated by empty lines. I want
J> to go through the block and see if a certain information is
J> present, and if it is, print the whole block to the result
J> file. But break seems not to work for me. Is there another command
J> in perl that is the equivalent of break in C? Thanks for the help.
your code didn't reflect that requirement in the least.
first, you can read paragraphs at a time which might be a good idea
here. read perlvar and look at the $/ variable.
the rest is fairly easy once you have paragraphs.
here is an untested oneliner for you:
perl -000ne 'print if /print this block/' infile > outfile
behold, the power of perl!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 25 Oct 2001 17:02:37 -0400
From: "Jerome" <tanathos21@yahoo.com>
Subject: Re: problem with break...
Message-Id: <B6%B7.6964$cE2.288380@weber.videotron.net>
Hello Uri,
thanks for the insights:) I am not a perl programmer, or a programmer at
all:) I've learned some basics in perl, c and php for fun, and didn't to use
that in a professional program, but for a one time job on a big chunk of
text:) Could you enlight me a little on this line of code?:
perl -000ne 'print if /print this block/' infile > outfile
Where do I put the code I am looking for in that command? that would be nice
to know a one line command to do the job I want to do:) And if you could
explain me what -000ne means, that would be great:) And to use that, do I
still have to modify the $/ variable? Thanks for all those infos.
Jerome
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x71yjr318v.fsf@home.sysarch.com...
> >>>>> "J" == Jerome <tanathos21@yahoo.com> writes:
>
> J> Hi, here is a piece of code I am working on, and I'm not sure that
the
> J> function break works the same way in perl than in C. Take a look at
this:
>
> J> #!/usr/bin/perl
>
> no -w, BAD!
>
> it would have told you something about break.
>
> no strict, BAD.
>
> J> open (DB, "< originaltext.txt");
> J> @lines = <DB>;
> J> close (DB);
> J> open (RESULT, ">> results.txt");
>
> no checking the results of open, BAD.
>
> J> for ($x = 0; ; $x++){
>
> you have c stylitis. learn perl style and you will have cleaner and
> better code.
>
> J> if ($tempdata[$x] eq "\n"){
> J> break;
> J> }
>
> FYI: break is not a keyword in perl. see my -w comment above. so it
> can't work like in c as it doesn't exist.
>
> read perlsyn for how to exit a loop.
>
> J> What I want to do with this code is take a text database that has
> J> separate block of informations all separated by empty lines. I want
> J> to go through the block and see if a certain information is
> J> present, and if it is, print the whole block to the result
> J> file. But break seems not to work for me. Is there another command
> J> in perl that is the equivalent of break in C? Thanks for the help.
>
>
> your code didn't reflect that requirement in the least.
>
> first, you can read paragraphs at a time which might be a good idea
> here. read perlvar and look at the $/ variable.
>
> the rest is fairly easy once you have paragraphs.
>
> here is an untested oneliner for you:
>
> perl -000ne 'print if /print this block/' infile > outfile
>
> behold, the power of perl!
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture and Stem Development ------
http://www.stemsystems.com
> Search or Offer Perl Jobs --------------------------
http://jobs.perl.org
------------------------------
Date: Thu, 25 Oct 2001 21:15:10 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: problem with break...
Message-Id: <x7wv1j1kvo.fsf@home.sysarch.com>
>>>>> "J" == Jerome <tanathos21@yahoo.com> writes:
first off, learn to NOT top post. notice how i will comment below the
quoted text of your post and edit out stuff that is not needed.
J> thanks for the insights:) I am not a perl programmer, or a
J> programmer at all:) I've learned some basics in perl, c and php for
J> fun, and didn't to use that in a professional program, but for a
J> one time job on a big chunk of text:) Could you enlight me a little
J> on this line of code?:
secondly, you should get a good beginner book on coding and perl. try
elements of programming in perl which is good to learn both
with. learning perl and teach yourself perl in 24 hours are good too.
J> perl -000ne 'print if /print this block/' infile > outfile
J> Where do I put the code I am looking for in that command? that
J> would be nice to know a one line command to do the job I want to
J> do:) And if you could explain me what -000ne means, that would be
J> great:) And to use that, do I still have to modify the $/ variable?
J> Thanks for all those infos.
what code are you talking about? in your code you looked for the string
'print this block' so that is what i looked for. you need to be more
specific about which paragraphs you want to print.
for the command line options, read perlrun. the -n and -e options are
very useful and common in one liners. -n creates a implied loop around
the input lines. -e is the perl code you want to execute. -0 sets $/
from the command line and 00 means it is in paragraph mode. read perlvar
for more about that.
<SNIP of entire and useless quoted post>
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 25 Oct 2001 17:18:35 -0400
From: "Jerome" <tanathos21@yahoo.com>
Subject: Re: problem with break...
Message-Id: <vl%B7.7054$cE2.297954@weber.videotron.net>
Thanks Uri, all those infos were pretty precious:) Could have taken me days
to just learn what you showed me in a few minutes:) I now know a lot more
stuff about perl than I used to:) Sorry for posting all the replies with my
messages, but i'm new to newsgroups, so I didn't really know. I'll go find
that book and try to get a better knowledge of perl, could come in handy
pretty often:)
Thanks
Jerome
------------------------------
Date: 25 Oct 2001 14:39:47 -0700
From: bkrusch@yahoo.com (Barry Krusch)
Subject: Regex to swap HTML tags
Message-Id: <c6b407df.0110251339.79216e67@posting.google.com>
I want to convert these:
<b><li>
<i><li>
to these:
<li><b>
<li><i>
Basically, I want to swap the tags. Is there a fast regex that can do this?
P.S. The first tag always has 3 characters.
------------------------------
Date: 25 Oct 2001 16:57:42 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Regex to swap HTML tags
Message-Id: <9ra1sm$ma3$1@charity.cs.utexas.edu>
In article <c6b407df.0110251339.79216e67@posting.google.com>,
Barry Krusch <bkrusch@yahoo.com> wrote:
>I want to convert these:
>
> <b><li>
> <i><li>
>
>to these:
>
> <li><b>
> <li><i>
Do they always occur adjacent to each other? Do you only want to swap
those particular pairs of tags?
If so, just do this:
$foo =~ s/<b><li>/<li><b>/;
$foo =~ s/<i><li>/<li><i>/;
If you want to take an three-character tag that occurs before an "<li>"
and put it after, then do this:
$foo =~ s/(<.>)(<li>)/$2$1/;
Does that answer the question?
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Thu, 25 Oct 2001 16:59:40 -0400
From: Frank Nospam <yahoo_com@francis.uy>
Subject: replacing bad old FormMail
Message-Id: <yahoo_com-EE1F43.16594025102001@news.hcf.jhu.edu>
One of my sites currently uses an old, slightly modified
copy of FormMail cgi. I just saw that Matt finally made
an updated, supposedly more secure version this summer.
At this point I could update to that, or possibly start
over with a different CGI. Are there alternatives with
basically the same functionality? I need the following:
1) CGI that takes web form input and sends it via email.
2) ability to send only selected form fields.
3) form results page, with optional link to an exit page.
4) ability to email 2 or 3 people, including the submitter.
Yes, submitter could be faked, but it's kinda necessary.
If I use FormMail 1.9 I'll need to do a fair amount of
customization to accomplish #4, so switching might make
more sense if someone can suggest a good one. Note that
I don't own the box and can't install modules.
Thanks.
------------------------------
Date: 25 Oct 2001 12:31:00 -0700
From: sgoyal@proplus.com (Saurabh Goyal)
Subject: String Substitution (Urgent)
Message-Id: <f1b41f03.0110251131.50445a4@posting.google.com>
Hi,
I have an string having alpha and numberic characters, I just want to
replace all _ (underscore) (prefix and suffix to numbers) with .
(decimal). Somehow subsitution is not working. Example script is given
below:
###################################
my $str = "A_D_3_B_1_2_3_4_C";
$str =~ s/(\d)(_)(\d)/\1\.\3/g;
print "str: $str\n";
###################################
Current Output:
A_D_3_B_1.2_3.4_C
Expected Output:
A_D_3_B_1.2.3.4_C
(if you will see in the current output 2_3 is not get replaced).
I will appreciate your help and time to reply me about my problem.
Thanks,
Saurabh
------------------------------
Date: 25 Oct 2001 15:59:34 -0400
From: Vinny Murphy <vmurphy@Cisco.Com>
Subject: Re: String Substitution (Urgent)
Message-Id: <m3itd3ze1l.fsf@vpnrel.cisco.com>
sgoyal@proplus.com (Saurabh Goyal) writes:
> Hi,
>
> I have an string having alpha and numberic characters, I just want to
> replace all _ (underscore) (prefix and suffix to numbers) with .
> (decimal). Somehow subsitution is not working. Example script is given
> below:
>
> ###################################
> my $str = "A_D_3_B_1_2_3_4_C";
> $str =~ s/(\d)(_)(\d)/\1\.\3/g;
$str =~ s/(\d)_(\d)/\1.\2/g;
> print "str: $str\n";
> ###################################
> Current Output:
> A_D_3_B_1.2_3.4_C
>
> Expected Output:
> A_D_3_B_1.2.3.4_C
>
> (if you will see in the current output 2_3 is not get replaced).
>
> I will appreciate your help and time to reply me about my problem.
To see how the regx is figuring things out you would have to recompile
perl with -DDEBUGGING to use -D switch. Not sure what the number is
that you would use (it has been a while since I had done this).
--
Vinny
------------------------------
Date: Thu, 25 Oct 2001 16:30:07 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: String Substitution (Urgent)
Message-Id: <4btgttg1o4sfc042mj31vtihf056f63svc@4ax.com>
On 25 Oct 2001 15:59:34 -0400, Vinny Murphy <vmurphy@Cisco.Com> wrote
wonderful things about sparkplugs:
>sgoyal@proplus.com (Saurabh Goyal) writes:
SNIP
>> my $str = "A_D_3_B_1_2_3_4_C";
>> $str =~ s/(\d)(_)(\d)/\1\.\3/g;
>
>$str =~ s/(\d)_(\d)/\1.\2/g;
SNIP
This produces: str: A_D_3_B_1.2_3.4_C
>To see how the regx is figuring things out you would have to recompile
>perl with -DDEBUGGING to use -D switch. Not sure what the number is
>that you would use (it has been a while since I had done this).
you can also get debugging info from:
use re "debug" ;
which produces this:
Compiling REx `(\d)_(\d)'
size 13 first at 3
1: OPEN1(3)
3: DIGIT(4)
4: CLOSE1(6)
6: EXACT <_>(8)
8: OPEN2(10)
10: DIGIT(11)
11: CLOSE2(13)
13: END(0)
anchored `_' at 1 (checking anchored) stclass `DIGIT' minlen 3
Guessing start of match, REx `(\d)_(\d)' against
`A_D_3_B_1_2_3_4_C'...
Found anchored substr `_' at offset 1...
This position contradicts STCLASS...
Looking for anchored substr starting at offset 2...
Found anchored substr `_' at offset 3...
Starting position does not contradict /^/m...
This position contradicts STCLASS...
Looking for anchored substr starting at offset 4...
Found anchored substr `_' at offset 5...
Starting position does not contradict /^/m...
Does not contradict STCLASS...
Guessed: match at offset 4
Matching REx `(\d)_(\d)' against `3_B_1_2_3_4_C'
Setting an EVAL scope, savestack=5
4 <A_D_> <3_B_1_2_> | 1: OPEN1
4 <A_D_> <3_B_1_2_> | 3: DIGIT
5 <A_D_3> <_B_1_2_> | 4: CLOSE1
5 <A_D_3> <_B_1_2_> | 6: EXACT <_>
6 <_D_3_> <B_1_2_3> | 8: OPEN2
6 <_D_3_> <B_1_2_3> | 10: DIGIT
failed...
Setting an EVAL scope, savestack=5
6 <_D_3_> <B_1_2_3> | 1: OPEN1
6 <_D_3_> <B_1_2_3> | 3: DIGIT
failed...
Setting an EVAL scope, savestack=5
8 <_3_B_> <1_2_3_4> | 1: OPEN1
8 <_3_B_> <1_2_3_4> | 3: DIGIT
9 <3_B_1> <_2_3_4_> | 4: CLOSE1
9 <3_B_1> <_2_3_4_> | 6: EXACT <_>
10 <_B_1_> <2_3_4_C> | 8: OPEN2
10 <_B_1_> <2_3_4_C> | 10: DIGIT
11 <_B_1_2> <_3_4_C> | 11: CLOSE2
11 <_B_1_2> <_3_4_C> | 13: END
Match successful!
Guessing start of match, REx `(\d)_(\d)' against `_3_4_C'...
Found anchored substr `_' at offset 2...
Starting position does not contradict /^/m...
Does not contradict STCLASS...
Guessed: match at offset 1
Matching REx `(\d)_(\d)' against `_3_4_C'
Setting an EVAL scope, savestack=5
12 <_B_1_2_> <3_4_C> | 1: OPEN1
12 <_B_1_2_> <3_4_C> | 3: DIGIT
13 <_B_1_2_3> <_4_C> | 4: CLOSE1
13 <_B_1_2_3> <_4_C> | 6: EXACT <_>
14 <_B_1_2_3_> <4_C> | 8: OPEN2
14 <_B_1_2_3_> <4_C> | 10: DIGIT
15 <_B_1_2_3_4> <_C> | 11: CLOSE2
15 <_B_1_2_3_4> <_C> | 13: END
Match successful!
Match failed
str: A_D_3_B_1.2_3.4_C
Freeing REx: `(\d)_(\d)'
--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com
------------------------------
Date: Thu, 25 Oct 2001 15:17:08 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: String Substitution (Urgent)
Message-Id: <3BD87344.80C7BC91@home.com>
Subject: String Substitution (Urgent)
Sorry, but Usenet is not a good place to get urgent help.
Saurabh Goyal wrote:
>
> ###################################
> my $str = "A_D_3_B_1_2_3_4_C";
> $str =~ s/(\d)(_)(\d)/\1\.\3/g;
There's no need to capture the _ in the search pattern.
The $1 syntax is preferred over the \1 syntax.
A . is not special in a replacement string.
> print "str: $str\n";
> ###################################
> Current Output:
> A_D_3_B_1.2_3.4_C
>
> Expected Output:
> A_D_3_B_1.2.3.4_C
The position for /g is getting moved past the last match, which is
screwing up later match attempts. You can use a zero-width lookahead
assertion to manage this:
$str =~ s/(\d)_(?=\d)/$1./g;
-mjc
------------------------------
Date: Thu, 25 Oct 2001 20:49:14 -0000
From: David Wall <darkon@one.net>
Subject: Re: String Substitution (Urgent)
Message-Id: <Xns9145AB043705Adarkononenet@207.126.101.97>
sgoyal@proplus.com (Saurabh Goyal) wrote on 25 Oct 2001:
> I have an string having alpha and numberic characters, I just want to
> replace all _ (underscore) (prefix and suffix to numbers) with .
> (decimal). Somehow subsitution is not working. Example script is given
> below:
>
> ###################################
> my $str = "A_D_3_B_1_2_3_4_C";
> $str =~ s/(\d)(_)(\d)/\1\.\3/g;
$str =~ tr/_/./;
--
David Wall
darkon@one.net
------------------------------
Date: Thu, 25 Oct 2001 16:01:14 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: String Substitution (Urgent)
Message-Id: <slrn9tgvcq.ncg.trammell@haqq.el-swifto.com>
On 25 Oct 2001 12:31:00 -0700, Saurabh Goyal <sgoyal@proplus.com> wrote:
> Hi,
>
> I have an string having alpha and numberic characters, I just want to
> replace all _ (underscore) (prefix and suffix to numbers) with .
> (decimal). Somehow subsitution is not working. Example script is given
> below:
>
> ###################################
> my $str = "A_D_3_B_1_2_3_4_C";
> $str =~ s/(\d)(_)(\d)/\1\.\3/g;
> print "str: $str\n";
> ###################################
> Current Output:
> A_D_3_B_1.2_3.4_C
>
> Expected Output:
> A_D_3_B_1.2.3.4_C
>
> (if you will see in the current output 2_3 is not get replaced).
>
> I will appreciate your help and time to reply me about my problem.
>
[ ~ ] perl -pe '1 while s/(\d)(_)(\d)/\1\.\3/'
1_2_3
1.2.3
A_D_3_B_1_2_3_4_C
A_D_3_B_1.2.3.4_C
^D
[ ~ ]
--
ultimate_answer_t deep_thought(void) { sleep(years2secs(7500000)); return 42; }
------------------------------
Date: Thu, 25 Oct 2001 21:17:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: String Substitution (Urgent)
Message-Id: <x7snc71ks3.fsf@home.sysarch.com>
>>>>> "JJT" == John J Trammell <trammell@haqq.hypersloth.invalid> writes:
JJT> [ ~ ] perl -pe '1 while s/(\d)(_)(\d)/\1\.\3/'
regardless of the correctness of that, don't use backreferences in the
replacement part of s///. use the $1, $2 vars as that is what they are
for. backreferences are only meant to be used in the match portion where
the $1 vars can't be used (as they will interpolate their PREVIOUS values).
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 25 Oct 2001 16:30:26 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: String Substitution (Urgent)
Message-Id: <slrn9th13h.nm4.trammell@haqq.el-swifto.com>
On Thu, 25 Oct 2001 21:17:19 GMT, Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "JJT" == John J Trammell <trammell@haqq.hypersloth.invalid> writes:
>
>
> JJT> [ ~ ] perl -pe '1 while s/(\d)(_)(\d)/\1\.\3/'
>
> regardless of the correctness of that, don't use backreferences in the
> replacement part of s///. use the $1, $2 vars as that is what they are
> for. backreferences are only meant to be used in the match portion where
> the $1 vars can't be used (as they will interpolate their PREVIOUS values).
>
You know, I just cut and pasted the s/// from the OP; didn't even
see the backreferences. Go fig!
--
Steve Balmer, CEO of Microsoft, recently referred to Linux as a Cancer.
Unsurprisingly, that's incorrect; Linux was released on August 25th, 1991
and is therefore a Virgo.
------------------------------
Date: Thu, 25 Oct 2001 19:12:29 GMT
From: "Joe Giordano" <joeg@optonline.net>
Subject: Re: Stripping Duplicates From Arrays
Message-Id: <xuZB7.6936$C7.2849000@news02.optonline.net>
I tried this but I got errors in my syntax on the line %temp = map ( { $_ =>
1 } @TMP); saying next 2 tokens.
I am new at perl and actually going to class next week. But here is what I
have
after opening and reading the file:
@TMP = split (/:/);
%temp = map ( { $_ => 1 } @TMP);
@TMP2=keys %temp;
any help you could provide would be great.
Thanks,
Joe
"Tom Renfro" <trenfro@i-55.com> wrote in message
news:9r9e70$cag$1@news.datasync.com...
> Joe,
>
> One possibility is using map() to put the array elements into a hash as
> keys. This will eliminate duplication easily. For example,
>
> my @array = (1,2,4,65,2,1,4,2,1);
> my %temp = map ( { $_ => 1 } @array );
> my @uniquevalues = keys %temp;
>
> The intermediate line is required for the keys() function to see the
mapped
> hash as a hash and not as list. I can't say if this is the most efficient
> method or not.
>
> Hope this helps,
>
> -Tom
>
> "Joe Giordano" <joeg@optonline.net> wrote in message
> news:PaWB7.6375$C7.2592557@news02.optonline.net...
> > I currently have a script that looks @ a dat file; each line of the dat
> file
> > is split on a colon seperating the line into columns. Each column is
then
> > put into an array. I want to take out or ignore the duplicate variables
in
> > the array. I then use each variable in the first array in a loop (So
> > unfortunatley each time the script uses the same variable I get the same
> > results. What is the best way to achieve this.
> >
> > Thanks,
> >
> > Joe
> >
> >
>
>
------------------------------
Date: Thu, 25 Oct 2001 19:10:51 +0100
From: "Scott Bell" <news@scottbell.org>
Subject: Re: Telnet client in perl
Message-Id: <4xYB7.74766$uh1.8189536@news6-win.server.ntlworld.com>
I managed to write something that could telnet in, read data but wasn't able
to collect data from the keyboard to send. It also made my computer go very
slow since I was doing a loop.
--
Scott Bell
Email: scott@scottbell.org
The content of this message has been certified 100% correct.
Chas Friedman <friedman@math.utexas.edu> wrote in message
news:3bd82c0c.1112936390@news.cc.utexas.edu...
> On Wed, 24 Oct 2001 21:52:46 +0100, "Scott Bell" <news@scottbell.org>
> wrote:
>
> >Does anyone know of a telnet client in perl, I'm not looking for a
telnet.pm
> >module, an actual perl script.
> >
> >Thanks.
> >
> >--
> >Scott Bell
> >Email: scott@scottbell.org
> >
> >The content of this message has been certified 100% correct.
> >
> >
> >
> I tried to write a telnet client using Net::Telnet, but never could
> get anything even close to a full featured result. My main problem was
> that using Net::Telnet, you seem to have to always wait for and check
> that the response is in some known fixed form. Pehaps I just wasn't
> clever enough...if you learn how to write such a client in Perl, I'd
> like to see the result. (I imagine it can be done, but it probably
> isn't trivial.)
> chas
begin 666 telnet.pl
M(R$O=7-R+V)I;B]P97)L#0IU<V4@3F5T.CI496QN970[#0H-"B1H;W-T;F%M
M92 ](")S8V]T=&)E;&PN;W)G(CL-"B1P;W)T(#T@(C(S(CL-"@T*)'1E;&YE
M=" ](&YE=R!.970Z.E1E;&YE=" H5&EM96]U=" ]/B M,2P-"B @(" @(" @
M(" @(" @(" @(" @(" @(" @(%1E;&YE=&UO9&4@/3X@,"D[#0HD=&5L;F5T
M+3YO<&5N*$AO<W0@/3X@)&AO<W1N86UE+ T*(" @(" @(" @(" @(" @(%!O
M<G0@/3X@)'!O<G0I.PT*#0IW:&EL92 H)'!O<G0@/B Q,"D@>PT*(" @)&QI
J;F4@/2 D=&5L;F5T+3YG970[#0H@("!P<FEN=" D;&EN93L-"@T*?0T*
`
end
------------------------------
Date: 25 Oct 2001 13:21:15 -0700
From: vivekvp@spliced.com (vivekvp)
Subject: VVP:making a string=string.
Message-Id: <9bf633be.0110251221.350503fa@posting.google.com>
Hello,
I have a web page that sends the parameter 'head' to a script and put
it in a
varible called $head_number (it is text and numbers). Then I try to
set it one called $p_str. But get this:
here is what you entered: SGB000096
p_str: SGB000096 [Thu Oct 25 16:14:11 2001] poheadp.cgi: Can't call
method "execute" without a package or object reference at
/disc2/ns3.6/docs/dev_vprasad/sumittweb/poheadp.cgi line 35.
Content-type: text/html
Software error:
Can't call method "execute" without a package or object reference at
/disc2/ns3.6/docs/dev_vprasad/sumittweb/poheadp.cgi line 35.
SGB000096 is what I entered. it never gets to p_str, and never to my
database query.
If I set $p_str="'$head_number'" - I do not get an error - but no
results - just blanks. Looks like this:
here is what you entered: SGB000096
p_str: 'SGB000096'
PO Header Info
poutput:
I am trying to get a person to enter a field and have it queried.
It seems my sql statement "SELECT * FROM poheader WHERE
head_number=$p_str" is not equalling "SELECT * FROM poheader WHERE
head_number='SGB000096"
Any help?
Thanks,
V
Script:
#!/usr/bin/perl -w
use DBI; # Load the DBI module
use CGI; # HTML
use strict; # keep it usable
use CGI qw(:standard);
use CGI::Carp qw( fatalsToBrowser );
###
my $query = new CGI;
my ($sth);
my $head_number;
my(@poutput,$poutput);
my $p_str;
print $query->header("text/html");
$head_number=$query->param('head');
print "<BR> here is what you entered: $head_number <BR> \n";
$p_str = $head_number;
print "<BR>p_str: $p_str \n \n";
### Attributes to pass to DBI->connect() to disable automatic
### error checking
my %attr = (
PrintError => 0,
RaiseError => 0,
);
### Perform the connection using the Informix driver
my $dbh = DBI->connect( "dbi:Oracle:test\@test","test","test"
,\%attr )or die "Can't connect to database: ", $DBI::errstr, "\n";
$sth=$dbh->prepare("SELECT * FROM poheader WHERE head_number=$p_str");
$sth->execute();
# will dump out all fields $poutput=$sth->dump_results();
@poutput=$sth->fetchrow_array();
print "<br>PO Header Info";
foreach $poutput (@poutput) {
if ($poutput="") {
$poutput="NULL";
}
print "<br>poutput: $poutput <BR>";
}
print "<BR>@poutput<BR>";
$sth->finish;
------------------------------
Date: Thu, 25 Oct 2001 15:50:02 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: VVP:making a string=string.
Message-Id: <slrn9tgunq.n8q.trammell@haqq.el-swifto.com>
On 25 Oct 2001 13:21:15 -0700, vivekvp <vivekvp@spliced.com> wrote:
[snip]
> ### Perform the connection using the Informix driver
> my $dbh = DBI->connect( "dbi:Oracle:test\@test","test","test"
> ,\%attr )or die "Can't connect to database: ", $DBI::errstr, "\n";
>
> $sth=$dbh->prepare("SELECT * FROM poheader WHERE head_number=$p_str");
$sth=$dbh->prepare("SELECT * FROM poheader WHERE head_number = ?");
$sth || die "unable to get statement handle";
> $sth->execute();
$sth->execute($p_str);
> # will dump out all fields $poutput=$sth->dump_results();
> @poutput=$sth->fetchrow_array();
> print "<br>PO Header Info";
> foreach $poutput (@poutput) {
> if ($poutput="") {
> $poutput="NULL";
> }
> print "<br>poutput: $poutput <BR>";
> }
> print "<BR>@poutput<BR>";
>
> $sth->finish;
--
ERR_NOSIG: sigfile out of commission while removing 'all your base'
references.
------------------------------
Date: Thu, 25 Oct 2001 20:42:38 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What's wrong with File::Find
Message-Id: <9r9tfu$283i$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Bart Lateur
<bart.lateur@skynet.be>], who wrote in article <v3igtt4sf22c22l5h7ci7u4106qcug78qg@4ax.com>:
> > [At least if the
> >lexical is introduced in the subroutine.]
>
> Well, it's not. See the source for File::Find. Somewhere at the top of
> the file, there's
>
> my %SLnkSeen;
>
> which means it's a "global" lexical for the entire file.
Not so in the copy I checked (mid-summer). It is in find_opt().
Ilya
------------------------------
Date: Thu, 25 Oct 2001 20:44:17 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What's wrong with File::Find
Message-Id: <9r9tj1$28bu$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Mark Jason Dominus
<mjd@plover.com>], who wrote in article <3bd8457f.29ab$103@news.op.net>:
> >Think what you like. But this is b******t. Pad captures the
> >environment for closures only, not for non-closure anonymous subs.
>
> So what? This is an internal optimization that has no effect on the
> the execution of any code. The subroutine is still closed.
Same expletive again. As other messages in this thread explained, it
*is* very visible from the user code.
Ilya
------------------------------
Date: Thu, 25 Oct 2001 22:03:25 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Win32 Perl book/software suggestions?
Message-Id: <9r9r32$6vt$02$1@news.t-online.com>
"Frank McKenney" <frank_mckenney@mindspring.com> schrieb im Newsbeitrag
news:9r97sq$a2o$1@slb6.atl.mindspring.net...
| How do you all go about impressing/educating co-workers and IT
| people of the advantages of Perl?
Considering he's a programmer, you might be able to impress him by showing
him why Perl is "Practical." Show him some code and let him compare with the
Clipper equivalent ;)
However, GUI programming is not a particular strength of Perl. I could think
of Learning Perl/Tk http://www.stonehenge.com/cgi/amazon?isbn=1565923146 but
eventhough I heard only good about it, I cannot judge it myself.
HTH,
Steffen
------------------------------
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 2012
***************************************