[19581] in Perl-Users-Digest
Perl-Users Digest, Issue: 1776 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 19 18:10:49 2001
Date: Wed, 19 Sep 2001 15:10:11 -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: <1000937411-v10-i1776@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 19 Sep 2001 Volume: 10 Number: 1776
Today's topics:
Re: pattern matching and multilines (sort of) <gnarinn@hotmail.com>
Perl Compiler <webmaster@kwakeb.net>
Re: Perl Compiler <Tassilo.Parseval@post.rwth-aachen.de>
Re: Perl Image Voting software? <a@b.c>
Re: PERL VARIABLE IN JAVASCRIPT (ALERT) <dima@caramail.com>
pretty printing a web page <benoitd@americasm01.nt.com>
Re: Problem with DBI+DBD MySQL, using fetchall_arrayref <gnarinn@hotmail.com>
Reading from Socket without EOF or EOL (Bikesh Patel)
Re: Sorting Hashes <bcaligari@fireforged.com>
Re: Sorting Hashes <stevea@wrq.com>
Re: What does this do ? "select( (select($writer), $|=1 (J.B. Moreno)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Sep 2001 18:32:08 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: pattern matching and multilines (sort of)
Message-Id: <1000924328.315171247813851.gnarinn@hotmail.com>
In article <wr1yl31qo0.fsf@itpc06.tollpost.no>,
Øyvind Gjerstad <ogj@itpc06.tollpost.no> wrote:
>I'm searching for a tool that lets me match lines with escaped
>newlines and treat them as one line.
>
>Let's say I have a file that look like this:
>abc \
> def \
> gih
>
>Note this is a file with 3 lines, where two of the lines have an escaped
>newline.
>
>I want to treat this as one line, i.e. when from the command line i
>grep for "def" i want to get the whole line. Preferrably as one line.
while (<>) {
if (s/\\\n$//) {
$_.=<>;
redo;
}
# do your stuff whith $_
}
you might want to add test for the case where the last line
ends with '\'
this is also discussed in the Perl Cookbook
gnari
------------------------------
Date: Wed, 19 Sep 2001 21:03:18 +0300
From: "eDeveloper" <webmaster@kwakeb.net>
Subject: Perl Compiler
Message-Id: <9oamte$fcf$1@ns1.isu.net.sa>
Hi
I heared that there is a compilers for a perl ?
is there a graphical compiler for perl for Linux ? or Windows
Regards,
eDeveloper
------------------------------
Date: Wed, 19 Sep 2001 23:09:09 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Perl Compiler
Message-Id: <3BA90975.20803@post.rwth-aachen.de>
eDeveloper wrote:
> Hi
> I heared that there is a compilers for a perl ?
Yes. perlcc. Perhaps we should set up a reward for succesful usage
($500.000 for the one who successfully compiles a script >= 5k).
> is there a graphical compiler for perl for Linux ? or Windows
What is a graphical compiler? You mean, something with a progress bar? ;-)
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Wed, 19 Sep 2001 11:42:35 -0700
From: BCC <a@b.c>
Subject: Re: Perl Image Voting software?
Message-Id: <3BA8E71B.93051737@b.c>
Yep! Actually Im a perl programmer by profession- but since this client
I consult for has a limited budget I thought I would try to save him
time/money by making sure I didnt reinvent the wheel.
Turn out Randal had already invented this particular wheel :)
With a few hacks Im home free!
Thanks!
Bryan
> As usual, 'Randy' (?) Randal L. Schwartz has some interesting ideas
> for you in one of his Web Techniques Columns. Check out the
> "Simplified Voting - Am I Hot or Not?" article at :
>
> http://www.stonehenge.com/merlyn/WebTechniques/col59.html
>
> If learning Perl is not your thing, then :
> a) you're not in the right newsgroup, and
> b) you should have a look at :
>
> http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Survey_and_Voting/
>
> HTH,
>
> Michel.
------------------------------
Date: Wed, 19 Sep 2001 20:26:17 GMT
From: "Dima" <dima@caramail.com>
Subject: Re: PERL VARIABLE IN JAVASCRIPT (ALERT)
Message-Id: <Jb7q7.50$Xk6.93309@carnaval.risq.qc.ca>
Thanks! It works!!!
Bart Lateur <bart.lateur@skynet.be> wrote in message
news:tbrfqtstm1k9pp0r9jug5d8gn4qi4jmaoj@4ax.com...
> Dima wrote:
>
> >print("<SCRIPT> alert(\"${message}\"); <SCRIPT>");
> >
> >
> >When I run the perl page, I get an error.
>
> You mean in Javascript? Maybe that's because you have two open SCRIPT
> tags. That closing tag should be hidden by a Javascript "begin comment"
> marker: "file://".
>
> Plus, you should be escaping special characters, including double quotes
> (as another poster already wrote), backslashes and newlines. Those
> should become
>
> \"
> \\
> \n
>
> respectively. Yes, just as in Perl. A s/// plus a substitution hash
> should work just fine:
>
> my %escape = ( '\\' => '\\\\', "\n" => '\n', '"' => '\"' );
> $message =~ s/([\n\\"])/$escape{$1}/g;
>
> --
> Bart.
------------------------------
Date: Wed, 19 Sep 2001 16:54:30 -0400
From: "Desrosiers, Benoit [CAR:9F53:EXCH]" <benoitd@americasm01.nt.com>
Subject: pretty printing a web page
Message-Id: <3BA90606.A34588C4@americasm01.nt.com>
This is a multi-part message in MIME format.
--------------1052B629C1DA1C8F0C0F835A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
I would like to know if there are tools to pretty print a web page on a
printer.
I have a perl program which generate a web page but when I want to print
that web page, I only get the left part of it.
I have tried everything I can think of to print it: sent it in
postscript, reducing the font, changing the paper size, changing the
browser size. But everytime, I only get part of the page.
any help?
thanks,
Benoit
--------------1052B629C1DA1C8F0C0F835A
Content-Type: text/x-vcard; charset=us-ascii;
name="benoitd.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Desrosiers, Benoit [CAR:9F53:EXCH]
Content-Disposition: attachment;
filename="benoitd.vcf"
begin:vcard
n:Desrosiers;Benoit
x-mozilla-html:TRUE
org:DaVinci;9F53
adr:;;;;;;
version:2.1
email;internet:benoitd@americasm01.nt.com
x-mozilla-cpt:;26088
fn:Benoit Desrosiers x57252
end:vcard
--------------1052B629C1DA1C8F0C0F835A--
------------------------------
Date: Wed, 19 Sep 2001 18:07:54 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Problem with DBI+DBD MySQL, using fetchall_arrayref and dereferencing with random function
Message-Id: <1000922874.988182337488979.gnarinn@hotmail.com>
In article <54d5ca0a.0109190244.a2328b3@posting.google.com>,
Altair04 <altair_04@altavista.com> wrote:
>Hello, I have the following sentences that read all te rows in the
>"countries" table and then select one of those rows, using the random
>function. The print works OK, but if I assign the same expression to a
>variable, it contains always a '1':
>
(snip)
>#################################################################
># this print works OK (gives the name of a country, at random): #
>#################################################################
>print @{@{$countries_ref}[rand(@{$countries_ref})]};
>
>#################################
># but this prints always a '1': #
>#################################
>$country = @{@{$countries_ref}[rand(@{$countries_ref})]};
>print $country;
this does not have anything to do with DBI.
the same effect can be had by
my @arr=(1,2,3);
print @arr,"\n";
my $scalar=@arr;
print $scalar,"\n";
is this hint enough for you to solve your problem?
gnari
------------------------------
Date: 19 Sep 2001 12:23:20 -0700
From: bikesh@my-deja.com (Bikesh Patel)
Subject: Reading from Socket without EOF or EOL
Message-Id: <728ad7c2.0109191123.349be739@posting.google.com>
I have RS 232 device connect to lantronix (for connection via sockets)
The RS232 device does NOT put EOF or EOL after the output
I want to issue a command and read the output, but since there is NO EOL or EOF
my script just hangs... any suggestions will help
attached is perl script and output from the device telnet
my inputs are ^F001, ^G, ^A001, ^B001
Trying 172.16.1.251...
Connected to 172.16.1.251.
Escape character is '^]'.
^F001
00
^F001
00^G
000000000000000000000000000000000000000000000000^A001
^G
010000000000000000000000000000000000000000000000^B001
^G
000000000000000000000000000000000000000000000000^A001^F001
99
-------------------------------------------------------------------------
#!/usr/bin/perl
require 5.003;
use Socket;
use FileHandle;
use strict;
my($Buf, $Buffer, $port, $LogName, $remote, $proto);
my($servertime, $packed_address, @now);
$port = 14001;
$LogName = getlogin;
$remote = "lantronix";
my @addr = gethostbyname($port, $remote);
sub readcli {
while(read CLIENT, $Buffer, 1){
$Buf .= $Buffer;
print $Buf
last if ($Buffer eq "\n");
chomp $Buf;
}
}
print "@addr\n";
$packed_address = pack('Sna4x8', AF_INET, $port, $addr[4]);
$proto = getprotobyname('tcp');
if (socket(CLIENT, PF_INET, SOCK_STREAM, $proto)) {
print "socket ok\n";
}
else { die $!;}
if (connect(CLIENT, $packed_address)) {
print "connect ok\n";
}
else { die $!;}
CLIENT->autoflush;
print CLIENT "^F001\n";
readcli();
print "Received from server: $Buf"
if ($Buf > 0 );
close(CLIENT);
Thanks
bikesh
bikesh@my-deja.com
------------------------------
Date: Wed, 19 Sep 2001 20:43:56 -0000
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: Sorting Hashes
Message-Id: <9oavjk02g7j@enews1.newsguy.com>
"Michael J. Vincent" <mjvincent@lucent.com> wrote in message
news:Xns912189DA8F7ABjohnnyfingers@135.7.153.102...
> perl guru's,
>
> I have a hash whose index is IP addresses and value is the number of
> times the IP address appears in a file. I'd like to print output sorted
by
> the most occurances to the least and secondary sorted on the increasing IP
> address.
>
> An example:
>
> $hash{172.16.5.1} = 5
> $hash{172.16.5.2} = 5
> $hash{172.16.5.3} = 7
> $hash{172.16.6.1} = 10
> $hash{172.16.7.1} = 2
>
> I would like the output to be:
>
> 10 172.16.6.1
> 7 172.16.5.3
> 5 172.16.5.1
> 5 172.16.5.2
> 2 172.16.7.1
>
my %hash;
$hash{'172.16.5.1'} = 5;
$hash{'172.16.5.2'} = 5;
$hash{'172.16.5.3'} = 7;
$hash{'172.16.6.1'} = 10;
$hash{'172.16.7.1'} = 2;
for (sort { ($b->[4] <=> $a->[4]) ||
($a->[0] <=> $b->[0]) ||
($a->[1] <=> $b->[1]) ||
($a->[2] <=> $b->[2]) ||
($a->[3] <=> $b->[3])
} map {[split(/\./), $hash{$_}]} keys %hash) {
print "$$_[4]\t$$_[0].$$_[1].$$_[2].$$_[3]\n";
}
converting the hash to an 'array of array references' makes the list easier
to sort.
B.
------------------------------
Date: Wed, 19 Sep 2001 21:52:39 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Sorting Hashes
Message-Id: <u66aeoni3.fsf@wrq.com>
"Michael J. Vincent" <mjvincent@lucent.com> writes:
>perl guru's,
I'm not a guru, but I want to practice sorting techniques.
>
> I have a hash whose index is IP addresses and value is the number of
>times the IP address appears in a file. I'd like to print output sorted by
>the most occurances to the least and secondary sorted on the increasing IP
>address.
>
> An example:
>
> $hash{172.16.5.1} = 5
> $hash{172.16.5.2} = 5
> $hash{172.16.5.3} = 7
> $hash{172.16.6.1} = 10
> $hash{172.16.7.1} = 2
>
> I would like the output to be:
>
> 10 172.16.6.1
> 7 172.16.5.3
> 5 172.16.5.1
> 5 172.16.5.2
> 2 172.16.7.1
The technique can be found from
perldoc -q sort "How do I sort a hash (optionally by value instead of
key)?".
I added a brute-force routine to sort the ip addresses:
#!/usr/bin/perl -w
use strict;
my %ips = (
'172.16.5.1' => 5,
'172.16.5.2' => 5,
'172.16.5.3' => 7,
'172.16.6.1' => 10,
'172.16.7.1' => 2,
);
printf "%2d %s\n", $ips{$_}, $_ for
sort { $ips{$b} <=> $ips{$a} || sortips($a, $b) } keys %ips;
sub sortips {
my($aa, $bb) = @_;
my @aa = split /\./, $aa;
my @bb = split /\./, $bb;
for (0..3) {
return -1 if $aa[$_] < $bb[$_];
return 1 if $aa[$_] > $bb[$_];
}
return 0;
}
exit 0;
__END__
Critiques welcome - that's how I learn.
--
-- Steve __
------------------------------
Date: Wed, 19 Sep 2001 14:51:06 -0400
From: planb@newsreaders.com (J.B. Moreno)
Subject: Re: What does this do ? "select( (select($writer), $|=1)[0] );" ?
Message-Id: <1ezzl1q.pz3vb39d7ecjN%planb@newsreaders.com>
Stan Brown <stanb@panix.com> wrote:
> Can you read?
>
> I ask this, because if you had bothered to look at the post with, what you
> claim was "5k of code", you would have found that it consited of t small
> subroutines, and a fair amount of debuging printout to demonstrate the
> problem that I am faceing.
Did you never stop to think that lots of people have killfiles for post
that contain that much text? It's a fairly sure sign of spam -- so it
is NOT worth the bother of looking at it, as one has to override the
killfile rule before being /able/ to look at it.
Obviously this wasn't the case with Uri, but it does support his point
(posting so much code doesn't help you at all, not that Uri is the only
one to respond to your message).
--
JBM
"Your depression will be added to my own" -- Marvin of Borg
------------------------------
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 1776
***************************************