[17041] in Perl-Users-Digest
Perl-Users Digest, Issue: 4453 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 27 21:15:37 2000
Date: Wed, 27 Sep 2000 18:15:23 -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: <970103723-v9-i4453@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Sep 2000 Volume: 9 Number: 4453
Today's topics:
Re: Prompt pattern stdenton@my-deja.com
Re: Questions about space-saving techniques stdenton@my-deja.com
Re: Questions about space-saving techniques <bkennedy@hmsonline.com>
Re: Questions about space-saving techniques <bkennedy@hmsonline.com>
Re: Recommendations for Best Beginners book? jthornton@my-deja.com
Re: Recommendations for Best Beginners book? <uri@sysarch.com>
recommended link checking script? mikelot@my-deja.com
Re: REGEX problem <ren.maddox@tivoli.com>
Re: Running other processes and waiting (Abigail)
Re: Send HTMLmail via Perl Script <lr@hpl.hp.com>
Re: Shortest code for Fibonacci? (Mark-Jason Dominus)
Re: Shortest code for Fibonacci? (Mark-Jason Dominus)
Re: SIGALRM with NT <elephant@squirrelgroup.com>
sort prob pgh@ga.nl
Re: sort prob (Craig Berry)
Re: sort prob (Abigail)
Re: sort prob <juex@deja.com>
Re: Substituting $variable strings in a file <ren.maddox@tivoli.com>
Re: unexpected changes from 5.005_03 to 5.6.0 (Abigail)
Re: unexpected changes from 5.005_03 to 5.6.0 (Ilya Zakharevich)
Re: unexpected changes from 5.005_03 to 5.6.0 <ren.maddox@tivoli.com>
Re: What does this do?! (Gwyn Judd)
What is %{$_} nlymbo@my-deja.com
Re: What is %{$_} (Mark-Jason Dominus)
Re: Windows 98 / Active Perl / CGI oi03_2000@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Sep 2000 21:57:15 GMT
From: stdenton@my-deja.com
Subject: Re: Prompt pattern
Message-Id: <8qtqfn$mul$1@nnrp1.deja.com>
The bits that look like (in hex) "ff .. .." are telnet escape
characters that are used for connection negotiation. They will change
depending on all sorts of things, so ignore them. (Read the telnet RFC
and look for "IAC" and "do/dont/will/wont" for more info.)
So, dropping that, you've got this (in qq// escapes) "\r\n\Password: ",
so just look for /word:/ or something and you should be OK.
In article <8qtp6n$lku$1@nnrp1.deja.com>,
scarlzong@my-deja.com wrote:
> Hello,
>
> I'm currently writing a script to access a D-Link 106 which can be
> administrated through telnet. The telnet module fails at the login
with
> tyhe following error: "timed-out waiting for login prompt at
> E:\tmp\isdn.pl line 7"
>
> Using Dump_log I recorded the following output from D-Link:
>
> E:\tmp>type dump.log
> < 0x00000: ff fb 03 ff fb 01 0d 0a 50 61 73 73 77 6f 72
> 64 √. √...Password
> < 0x00010: 3a 20 :
>
> > 0x00000: ff fd 03 ff fd 01 ². ².
>
> Anyone good att regular expressions able to help me to set the prompt
> correctly (since I figure that is the problem) ?
>
> Regards,
> Sune
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 22:07:45 GMT
From: stdenton@my-deja.com
Subject: Re: Questions about space-saving techniques
Message-Id: <8qtr3c$ne8$1@nnrp1.deja.com>
In article <zHsA5.5155$l35.125439@iad-read.news.verio.net>,
chadbour@wwa.com (James Weisberg) wrote:
> Is this portable? I believe assuming a 1-byte char is pretty
portable
> but assuming a 2-byte short might not be. If you pack a number <
65536 as
> an unsigned short, are you gaurenteed to return 2 as its length on any
> machine which doesn't store 2-byte shorts? If this is not portable,
should
> the uncompress function above refer to some global vars which know the
> size of these datatypes:
Just addressing this point, no it isn't always portable. Read the docs
on 'pack' and pay attention to the differences between i/I, l/L, s/S,
and n/N, v/V.
--Sam
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 23:33:52 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Questions about space-saving techniques
Message-Id: <AtvA5.10573$td5.1887118@news1.rdc2.pa.home.com>
"James Weisberg" <chadbour@wwa.com> wrote in message
news:zHsA5.5155$l35.125439@iad-read.news.verio.net...
> And then, if I wrote that correctly, @record will unpack correctly
> using $packstring as the reference instruction. So at this point it is
> speculation whether or not the 40-bytes tacked on to the beginning of
> the record string, for every record, saves more memory than simply
> packing the whole record as a string of long ints as above. Certainly
> I know this will take more processing time, but that I'm willing to
> sacrifice for a significant memory savings.
That depends solely on your data. You could also probably optimize your
pack template somewhat, by doing things such as turning CCCC to C4 - you'd
have to burn another byte to specify the length of the template. But
overall, is it really even worth it? Your original post mentioned "several
thousand records", and even at 40 integers per record, is not a huge amount
of resources. Another thing, your original post mentioned only needing to
process one record at a time - why not then iterate over the tied hash with
each()? Then only one record is in memory at a time. Another thing occured
to consider, which maybe someone else can answer - you seem satisfied with
the storage on disk, but want to save space in memory, but what is the
overhead of Perl variables (maybe the space saved is negligable)? And does
Perl automatically select the best storage mechanism for numbers? These
things I do not know.
> Is this portable? I believe assuming a 1-byte char is pretty portable
> but assuming a 2-byte short might not be. If you pack a number < 65536 as
> an unsigned short, are you gaurenteed to return 2 as its length on any
> machine which doesn't store 2-byte shorts? If this is not portable, should
> the uncompress function above refer to some global vars which know the
> size of these datatypes:
from perlfunc pack, a signed short is exactly 16 bits, and a signed long is
exactly 32 bits - an integer might vary though. I imagine that assuming a 8
bit char is probably ok too.
--Ben Kennedy
------------------------------
Date: Thu, 28 Sep 2000 00:05:30 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Questions about space-saving techniques
Message-Id: <eXvA5.10675$td5.1897801@news1.rdc2.pa.home.com>
"James Weisberg" <chadbour@wwa.com> wrote in message
news:zHsA5.5155$l35.125439@iad-read.news.verio.net...
> And then, if I wrote that correctly, @record will unpack correctly
> using $packstring as the reference instruction. So at this point it is
> speculation whether or not the 40-bytes tacked on to the beginning of
> the record string, for every record, saves more memory than simply
> packing the whole record as a string of long ints as above. Certainly
> I know this will take more processing time, but that I'm willing to
> sacrifice for a significant memory savings.
That depends solely on your data. You could also probably optimize your
pack template somewhat, by doing things such as turning CCCC to C4 - you'd
have to burn another byte to specify the length of the template. But
overall, is it really even worth it? Your original post mentioned "several
thousand records", and even at 40 integers per record, is not a huge amount
of resources. Another thing, your original post mentioned only needing to
process one record at a time - why not then iterate over the tied hash with
each()? Then only one record is in memory at a time. Another thing occured
to consider, which maybe someone else can answer - you seem satisfied with
the storage on disk, but want to save space in memory, but what is the
overhead of Perl variables (maybe the space saved is negligable)? And does
Perl automatically select the best storage mechanism for numbers? These
things I do not know.
> Is this portable? I believe assuming a 1-byte char is pretty portable
> but assuming a 2-byte short might not be. If you pack a number < 65536 as
> an unsigned short, are you gaurenteed to return 2 as its length on any
> machine which doesn't store 2-byte shorts? If this is not portable, should
> the uncompress function above refer to some global vars which know the
> size of these datatypes:
from perlfunc pack, a signed short is exactly 16 bits, and a signed long is
exactly 32 bits - an integer might vary though. I imagine that assuming a 8
bit char is probably ok too.
--Ben Kennedy
------------------------------
Date: Wed, 27 Sep 2000 22:29:27 GMT
From: jthornton@my-deja.com
Subject: Re: Recommendations for Best Beginners book?
Message-Id: <8qtsbv$od9$1@nnrp1.deja.com>
> I am wondering what the recommendation for the best "complete"
> beginner's book would be. One that starts from the "Very" ground
> floor up.
Learning Perl, by Randal L. Schwartz, Tom Christiansen (O'Reilly)
http://www.amazon.com/exec/obidos/ASIN/1565922840/jamesthorntoncom/
...it is also referred to as the llama book.
________________________________________________________________________
Be a part of THE UNIFIED MIND at http://www.unifiedmind.com (coming
soon)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 22:53:27 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Recommendations for Best Beginners book?
Message-Id: <x7aect8n14.fsf@home.sysarch.com>
>>>>> "j" == jthornton <jthornton@my-deja.com> writes:
j> Learning Perl, by Randal L. Schwartz, Tom Christiansen (O'Reilly)
j> http://www.amazon.com/exec/obidos/ASIN/1565922840/jamesthorntoncom/
posting a url with your kickback ID is not a nice thing to do.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 27 Sep 2000 23:59:32 GMT
From: mikelot@my-deja.com
Subject: recommended link checking script?
Message-Id: <8qu1l2$sgp$1@nnrp1.deja.com>
I'm looking for a perl script that I can use to recursively check a web
site, and that I can limit by either depth or url pattern matching. I
need to do this via http, so that rules out some of the file based
approaches. Any recommendations for any of your favorites?
I've looked at randal's script at
http://www.stonehenge.com/merlyn/WebTechniques/col14.html
that's pretty close to what i want, but if there's a similar script
that generates a little more user friendly reports (I'm going to give
this to someone who's not technical) that would be great. Otherwise,
it's not a big chore to modify, but if there's something better someone
has already done...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 27 Sep 2000 15:43:05 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: REGEX problem
Message-Id: <m31yy5r2g6.fsf@dhcp11-177.support.tivoli.com>
ansok@alumni.caltech.edu (Gary E. Ansok) writes:
> In article <mao3tscejuqk4475f971m7oaojughkdh36@4ax.com>,
> Bart Lateur <bart.lateur@skynet.be> wrote:
> >Shawn and Francine wrote:
> >
> >>I need to search a string and replace all instances of "." with a
> >>space.
> >
> > tr/./ /;
> >or
> > s/\./ /g;
>
> Actually, to do the operation as requested it should be
>
> tr/./ /s;
Don't think so... even if you choose to interpret the all as universal
rather than as "each", that wouldn't lead to the behavior you have
provided. What you have given replaces each group of "."-s with a
single space. Perhaps something like:
s/\./ /; tr/.//d;
would achieve that interpretation -- but I don't think it is the
correct interpretation (though it may be the desired result). The
inclusion of the word "instances" after "all" implies that "each" is
meant.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 27 Sep 2000 22:53:24 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Running other processes and waiting
Message-Id: <slrn8t4ugm.lo9.abigail@alexandra.foad.org>
Kyle Parfrey (kyle@iol.ie) wrote on MMDLXXXIV September MCMXCIII in
<URL:news:39D239F3.D2E338@iol.ie>:
?? Hi all.
?? I have been trying to write a perl program that simply calls a plotting
?? program called gnuplot, makes it do something then exits (it is as
?? preparation for a bigger project). I was using a filehandle to write to
?? gnuplot (command line interface) but the graph that it creates flashes
?? on the screen and the perl program exits. Is there a simple way that I
?? can have the graph onscreen awaiting an order from the keyboard to get
?? rid of it? I have heard about an expect function or system but can't
?? find anything about it in "programming perl".
You have to realize that by default, gnuplot closes the window when it
exits (and it exits when reading eof from its stdin). Which leaves you
three options: change the default (details can be found in the gnuplot
manual), have gnuplot write to stdout (details can be found in the gnuplot
manual), and pipe that into a viewer that stays up, or don't close the
pipe to gnuplot. But in the latter case, note that terminating your Perl
program will close the pipe.
I'd go for the first option.
Abigail
--
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT
# A pair of salmon
# darting in the pool. The Pope
# under a birch.
------------------------------
Date: Wed, 27 Sep 2000 16:21:24 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Send HTMLmail via Perl Script
Message-Id: <MPG.143c20d1a847d72098adcd@nntp.hpl.hp.com>
In article <39d279ff.27504228@news.screaming.net> on Wed, 27 Sep 2000
22:54:45 GMT, mr. apocalypse <apocalyptic_death@removethis.hotmail.com>
says...
> On Tue, 26 Sep 2000 13:21:59 GMT, joshfeingold@my-deja.com wrote:
...
> >print MAILINPUT <<"TEST";
> ><HTML><b>Hello $your_name</b></HTML>
> >TEST
...
> >Can't find string terminator "TEST" anywhere before EOF at warranty.pl
> >line 116.
>
> Read the error message. Can't find string terminator "TEST". Notice the
> quotes. Your start is "TEST" and you end with TEST. Take your pick which
> one to fix.
ASTOUNDING!
You are too lazy to execute even the following before posting:
perl -e "print <<TEST;"
The double-quotes are added by the diagnostic.
The doc I quoted said *explicitly* that <<TEST and <<"TEST" have
identical semantics, but still you post your garbage without having the
courtesy to verify your assertion.
Begone, twit!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 27 Sep 2000 19:52:38 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39d27548.1166$3ba@news.op.net>
Keywords: achromatic, geochronology, rigging, stool
In article <8qth2u$ea4$1@nnrp1.deja.com>,
Quantum Mechanic <quantum_mechanic@my-deja.com> wrote:
>> sub mm {
>> my ($n) = @_;
>> return (1, 0, 0, 1) if $n == 0;
>> return (1, 1, 1, 0) if $n == 1;
>> if ($n % 2) { # odd n
>> my ($a, $b, $c, $d) = mm($n-1);
>> ($a+$b, $a, $c+$d, $d);
>> } else { # even n
>> my ($a, $b, $c, $d) = mm($n>>1);
>> my ($ad, $bc) = ($a+$d, $b*$c);
>> ($a*$a+$bc, $b*$ad, $c*$ad, $d*$d+$bc);
>> }
>> }
>>
>Your efficient algorithm is very quick indeed, but it fails at F(12),
Oops. The line that says
>> ($a+$b, $a, $c+$d, $d);
should say
>> ($a+$b, $a, $c+$d, $c)
Thanks very much for catching this.
>> but it's past 2:30 AM here and I can't remember it offhand.
Apparently the compulsion to write $d as the last element of a
four-element list was irresistible at 2:30 AM.
Anyway, it occurred to me while looking at this (not at 2:30 AM this
time) that $c is totally superfluous:
sub mm {
my ($n) = @_;
my @r;
return (1, 0, 1) if $n == 0;
return (1, 1, 0) if $n == 1;
if ($n % 2) { # odd n
my ($a, $b) = mm($n-1);
return ($a+$b, $a, $b);
} else { # even n
my ($a, $b, $d) = mm($n>>1);
my ($x, $y) = ($a*$a+$b*$b, $b*($a+$d));
return ($x, $y, $x-$y);
}
}
sub fib {
my ($f) = &mm; # LOD
}
------------------------------
Date: Thu, 28 Sep 2000 00:02:10 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39d28a82.1576$3a1@news.op.net>
Keywords: Klan, insist, rubbish, trammel
In article <39d27548.1166$3ba@news.op.net>,
Mark-Jason Dominus <mjd@plover.com> wrote:
> sub mm {
> my ($n) = @_;
> return (1, 0, 1) if $n == 0;
> return (1, 1, 0) if $n == 1;
> if ($n % 2) { # odd n
> my ($a, $b) = mm($n-1);
> return ($a+$b, $a, $b);
> } else { # even n
> my ($a, $b, $d) = mm($n>>1);
> my ($x, $y) = ($a*$a+$b*$b, $b*($a+$d));
> return ($x, $y, $x-$y);
> }
> }
Ho! Another improvement; we can get rid of $d too:
sub mm {
my ($n) = @_;
return (1, 0) if $n == 0;
return (1, 1) if $n == 1;
if ($n % 2) { # odd n
my ($a, $b) = mm($n-1);
return ($a+$b, $a);
} else { # even n
my ($a, $b) = mm($n>>1);
return ($a*$a+$b*$b, $b*(($a<<1)-$b));
}
}
------------------------------
Date: Thu, 28 Sep 2000 09:53:49 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: SIGALRM with NT
Message-Id: <MPG.143d3396997828ee9897d0@localhost>
Ghost wrote ..
>I'm trying to use SIGALRM using perl 5.005_03 for NT
>The code i'm trying to use is...
>
>$SIG{ALRM} = sub {die "timeout"};
>
>eval {
> alarm(3600);
> #Operation i'm trying to timeout here
> alarm(0);
>};
>
>if ($@) {
> if ($@ =~ /timeout/) {
> print "timed out";
> } else {
> alarm (0);
> die;
> }
>}
>
>I get the following error
>The Unsupported function alarm function is unimplemented at test.pl
>line 15.
>
>line 15 is the alarm (0); line just past the else. I'm assuming the SIG
>{ALRM} is unsupported in NT. So, if there is any other way to time out
>an operation in NT, I'd be tickled pink to find out. Thanks
go and read the documentation .. then you'll see the unsupported
functions - and where applicable - the workarounds for getting similar
functionality
assuming you're using the standard ActiveState Perl the documentation
has been converted to lovely HTML and there's a shortcut to it on your
Programs menu
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 27 Sep 2000 22:08:07 GMT
From: pgh@ga.nl
Subject: sort prob
Message-Id: <39d66fc3.13462383@news.freeler.nl>
Hi,
I have the following "script"
#!perl
open(INPUT, "main.txt" ) || die "error opening file";
while(<INPUT>)
{
( $veld1, $veld2 ) = split( /">/, $_ );
@array = sort ($veld2);
foreach $veld2 ( @array ) {
@sorted = sort($veld2);
print "@sorted";
}
}
close(INPUT);
How come it isn't sorting?
I have a text file and I want this file to be sorted.
I need to vars to remove the first chars of this line (see: $veld1 and $veld2 )
and sort on the second var ($veld2)
What am I doing wrong here ?
Regards, Patrick.
------------------------------
Date: Wed, 27 Sep 2000 23:17:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: sort prob
Message-Id: <st5014a0mtvn02@corp.supernews.com>
pgh@ga.nl wrote:
: I have the following "script"
:
: #!perl
No -w? No 'use strict'?
: open(INPUT, "main.txt" ) || die "error opening file";
...but at least you check the results of open().
: while(<INPUT>)
: {
: ( $veld1, $veld2 ) = split( /">/, $_ );
: @array = sort ($veld2);
@array is guaranteed to contain exactly one element at this point, the
value of $veld2. Sorting a one-element array seems a bit silly.
: foreach $veld2 ( @array ) {
Reusing the name $veld2 is needlessly confusing.
: @sorted = sort($veld2);
Again, you're sorting a one-element list. Doesn't do anything.
: print "@sorted";
For each line, this will be whatever got split into $veld2 above.
: How come it isn't sorting?
It *is* sorting; it's just that one-element sorts are hard to detect. :)
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Quidquid latine dictum sit, altum viditur."
|
------------------------------
Date: 28 Sep 2000 00:08:26 GMT
From: abigail@foad.org (Abigail)
Subject: Re: sort prob
Message-Id: <slrn8t52tc.lo9.abigail@alexandra.foad.org>
pgh@ga.nl (pgh@ga.nl) wrote on MMDLXXXIV September MCMXCIII in
<URL:news:39d66fc3.13462383@news.freeler.nl>:
// Hi,
//
// I have the following "script"
//
// #!perl
There's no -w!
// open(INPUT, "main.txt" ) || die "error opening file";
Why not use $! in the message?
// while(<INPUT>)
// {
// ( $veld1, $veld2 ) = split( /">/, $_ );
// @array = sort ($veld2);
// foreach $veld2 ( @array ) {
// @sorted = sort($veld2);
// print "@sorted";
// }
// }
// close(INPUT);
//
// How come it isn't sorting?
Of course it's sorting. You give sort a list of one element to sort,
and it returns that list sorted! It's a trivial sort, but it's still
sorted.
// I have a text file and I want this file to be sorted.
// I need to vars to remove the first chars of this line (see: $veld1 and $veld2
// and sort on the second var ($veld2)
//
// What am I doing wrong here ?
It's better to sum up what you are doing right here. You're totally missing
how you remove something, or how you sort something. Or even basic loops,
as you really don't want to sort after each line you read, let alone print.
Here's an ST sort, a GRT is left as an exercise:
open my $fh => "main.txt" or die "Failed to open main.txt: $!\n";
print map { $_ -> [0]}
sort { $a -> [1] cmp $b -> [1]}
map {[reverse split /">/ => $_, 3]}
<$fh>;
close $fh;
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: Wed, 27 Sep 2000 17:50:26 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: sort prob
Message-Id: <39d29588$1@news.microsoft.com>
<pgh@ga.nl> wrote in message news:39d66fc3.13462383@news.freeler.nl...
Your logic is more than screwed:
> while(<INPUT>)
For each line of the input file
> {
> ( $veld1, $veld2 ) = split( /">/, $_ );
> @array = sort ($veld2);
assign the tail of this line to @array. At this point the array contains
exactly one element. Always!
> foreach $veld2 ( @array ) {
Now you are looping over this one-element array
> @sorted = sort($veld2);
to sort the element (not even the @array) and assign the sorted one-element
result to @sorted
> print "@sorted";
and print it
> }
> }
> close(INPUT);
>
> How come it isn't sorting?
It is sorting perfectly fine
> I have a text file and I want this file to be sorted.
> I need to vars to remove the first chars of this line (see: $veld1 and
$veld2 )
> and sort on the second var ($veld2)
>
> What am I doing wrong here ?
>
> Regards, Patrick.
>
>
>
------------------------------
Date: 27 Sep 2000 15:35:04 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Substituting $variable strings in a file
Message-Id: <m34s31r2tj.fsf@dhcp11-177.support.tivoli.com>
tebrusca@my-deja.com writes:
> I want to embed variable names in a file
> then read the file and have the variables
> interpreted. Below is the shell of the
> code, I've tried escapes, eval, and read
> all docs I could think of ... I DON'T
> want to do it with S/UBSTI/TUITION or with
> < <HERE. Basically I'm thinking the program
> is compiled and there's no way to get it
> to interpret the $word in the file?
As already mentioned, there is a FAQ for this...
Depending on what can be in the file, this can certainly be tricky.
You need to quote the data twice -- once for the eval, and once so
that it will be treated as a double-quoted string inside the eval.
The problem is that the second quoting mechanism needs to be something
that will not collide with the data.
For example, if the data contains a ", then using:
print eval qq("$string");
will not work as the embedded " will cause a syntax error. You can
reverse it:
print eval "qq($string)";
which will handle embedded "s fine, but will break on embedded ")".
The normal way to get around this problem is with a HERE document, but
you specifically disallowed that. I'm going to assume that you didn't
really mean to disallow it in this circumstance, so here it is:
print eval qq(<<STRING_NOT_IN_THE_DATA
$string
STRING_NOT_IN_THE_DATA);
Watch out for the newline that gets included at the end with this
method. Also note that STRING_NOT_IN_THE_DATA *can* be in the data as
long as it isn't on a line by itself.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 27 Sep 2000 22:38:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: unexpected changes from 5.005_03 to 5.6.0
Message-Id: <slrn8t4tjr.lo9.abigail@alexandra.foad.org>
Ryan Honeyman (honeyman@decipher.com) wrote on MMDLXXXIV September
MCMXCIII in <URL:news:39D21B51.72C213DB@decipher.com>:
:) *** post for free via your newsreader at post.newsfeeds.com ***
:)
:) This code snip below behaves differently:
:) -----------------------------------------
:)
:) my $this = "2";
:) if ($this <= 10) { $this = "1$this"; }
:) printf("%s %02d\n",$this,$this);
:)
:) perl 5.005_03 output...: 12 12
:) perl 5.6.0 output......: 12 02
:)
:) ---------------------------
That's a bug. It is however fixed in 5.7.0, which means it's hopefully
fixed in 5.6.1 as well.
8 line sig and *20* line advertisement snipped.
Please be considerated. There's no reason for an 8 line sig; what you are
saying there fits in 2 or 3 lines easily.
Now, we know you don't put the ad there, but there isn't a reason to use
a service that uses 20 line advertisements in every post.
Time to add some more killfile rules.
Abigail
--
@_=map{[$!++=>$_^$/]}split$²=>"\@\x7Fy~*kde~box*Zoxf*Bkiaox";$\="\r";
$|=++$*;do{($#=>$=)=(rand@_=>rand@_);@_[$#,$=]=@_[$=,$#]}for($*..@_);
for$:($|..@_-$|){for($|..@_-$:){@_[$_-$|,$_]=@_[$_=>$_-$*]if$_[$_][$¼
]<$_[$_-$*][$®];print+map{$_->[$|]}@_;select$·,$°,$½,"$[.$|"}}print$/
------------------------------
Date: 27 Sep 2000 22:49:22 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: unexpected changes from 5.005_03 to 5.6.0
Message-Id: <8qtthi$n9g$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Ryan Honeyman
<honeyman@decipher.com>],
who wrote in article <39D21B51.72C213DB@decipher.com>:
> *** post for free via your newsreader at post.newsfeeds.com ***
>
> This code snip below behaves differently:
> -----------------------------------------
>
> my $this = "2";
> if ($this <= 10) { $this = "1$this"; }
> printf("%s %02d\n",$this,$this);
>
> perl 5.005_03 output...: 12 12
> perl 5.6.0 output......: 12 02
Let me guess: your 5.6.0 compile is 64-bit? My "sane numerics"
patches were specifically intended for 32-bit compiles only, since at
the time bitwise operators were hopelessly (and intentionally) broken on
64-bit platforms.
Later this shortcoming of 64-bit stuff was removed, and some people
claimed to copy my 32-bit stuff for 64-bit compiles. But I never
checked whether the tests they did were reasonable.
This is clearly a bug, and deserves to be reported ASAP.
Ilya
------------------------------
Date: 27 Sep 2000 17:37:06 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: unexpected changes from 5.005_03 to 5.6.0
Message-Id: <m3og19pilp.fsf@dhcp11-177.support.tivoli.com>
Ryan Honeyman <honeyman@decipher.com> writes:
I added:
print "Perl version: $]\n\n";
to the beginning of your code. Here is my result:
Perl version: 5.006
this starts at 2, that starts at 0
this = 12, that = 12, both should be 12
multiply (12 * 2): 24 (should be 24)
multiply (12 * 2): 24 (should be 24)
12 <-- that should be 12
12 <-- this should be 12
__END__
Of course, you already knew it worked for me, so I guess this doesn't
really help you any.
I don't know if it matters, but my "perl -v" actually says:
This is perl, v5.6.0 built for i686-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
"perl -V" includes:
CONTEXT
Locally applied patches:
ActivePerl Build 616
Perhaps ActiveState fixed something? That would seem rather strange
that it wouldn't have made it into the standard build. I'm really not
sure what the significance of the ActiveState build number is.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 27 Sep 2000 23:57:56 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: What does this do?!
Message-Id: <slrn8t52ja.q6.tjla@thislove.dyndns.org>
I was shocked! How could Yanick Champoux <yanick@babyl.sympatico.ca>
say such a terrible thing:
>It's an encryption/decryption program. To encrypt a file, do
>
> mysterious.pl password clear.txt > encrypt.txt
>
>and to decrypt it
>
> mysterious.pl password encrypt.txt
Very good, but you got the name wrong :)
>Note that I called the script 'mysterious.pl', although
>I have the feeling the original script was named
>'X' or 'XXX' because of the statement
>'$0=~s/X*$// if $d;' (I mean, it's obvious, isn't? ;)
nope...well it could have been, but that's not what it was in the book
:)
>Almost readable:
>
>#!/smart2/bin/perl -s
>
># called as mysterious.pl [ -d ] <key> <text_file>
># -d is to decrypt the message
># E.g.: mysterious.pl password clear.txt > encrypt.txt
># mysterious.pl password encrypt.txt
>
>$0 =~ s/X*$// if $d;
too weird. obscure the name only if decrypting?
>$D = pack('C*', (33..86));
hmm...interesting that he should have used the "pack" function on this
particular line. Kind of punny in fact.
>$p = uc shift @ARGV;
>$U = "\$D=~s/(.*)U\$/U\$1/;\n\$D=~s/U(.)/\$1U/;";
$U = <<EOU;
# move the bottom to the top, if it is a particular character
$D =~ s/(.*)U$/U$1/;
# and then move it down one anyway
$D =~ s/U(.)/$1U/;
EOU
# and we'll do the same for some other character too
>($V = $U) =~ s/U/V/g;
# create the keystream using the key
>$p =~ s/[A-Z]/do { $k = ord($&) - 64, &e }/eg;
>$k = 0;
>$o = uc join '', <>;
>$o =~ y/A-Z//cd; # remove anything but letters
>
>$o .= 'X' while length($o) % 5 and not $d; # padding time
>
>$f = $d ? -1 : 1;
# add each digit to the next number in the keystream, modulo 26
# and convert back to a character
>$o =~ s/./ chr(($f * &e + ord($&) - 13) % 26 + 65) /eg;
>$o =~ s/.{5}/$& /g; # split in segments of 5 letters
>
>print "$o\n";
# look at the character at index $x and convert it into a number from 1
# to 53
>sub v {
> my $x = shift;
> $v = ord(substr $D, $x) - 32;
> $v > 53 ? 53 : $v;
>}
# cut below the character at position $x moving everything below it
# except the bottom one to the top
>sub w {
> my $x = shift;
> $D =~ s/(.{$x})(.*)(.)/$2$1$3/;
>}
>sub e {
# move some characters around
> eval "$U$V$V";
# move some more cards...oops I mean characters around
> $D =~ s/(.*)([UV].*[UV])(.*)/$3$2$1/;
# cut using the chracter at the bottom as an index
> &w(&v(53));
# cut using the top character as an index. if you strike either a 53
# or a 54 then start over
> $k ? &w($k) : ($c = &v(&v(0)), $c > 52 ? &e : $c);
>}
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Hey! Let's do that 2,000-pound man thing. I'll be that Carl Reiner guy,
and you be what's-his-face.
-- Homer Simpson
Homer vs. Patty and Selma
------------------------------
Date: Wed, 27 Sep 2000 23:19:54 GMT
From: nlymbo@my-deja.com
Subject: What is %{$_}
Message-Id: <8qtval$qn5$1@nnrp1.deja.com>
I'm looking at someone else's code and don't understand the variables
that i am seeing...could someone explain the following??
1) @{$list{$_}}
2) %{$_}
my (@key_list) = parse_billkeys("cas1,cas2", "hashed" => "cornbeef");
my (%list, $hash, $key, $verd);
foreach (@key_list) {
# Yeah, using the bill ID hash ref as the key is a bit spooky, but
# dang it works nicely fer later.
push(@{$list{$_}}, get_texts_by_billkey(%{$_}));
}
^^^^^^^^^ ^^^^^
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 21:31:29 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: What is %{$_}
Message-Id: <39d28c73.15c6$172@news.op.net>
In article <8qtval$qn5$1@nnrp1.deja.com>, <nlymbo@my-deja.com> wrote:
>I'm looking at someone else's code and don't understand the variables
>that i am seeing...could someone explain the following??
>
>1) @{$list{$_}}
$list{$_} you already know about: %list is a hash, and this uses $_
as a key into the hash to get the associated value.
@{$list{$_}} means that the associated value is an reference to an
array, and recovers the array. Since it's the argument of 'push', the
return value for get_texts_by_billkey is pushed onto this array.
>2) %{$_}
$_ is a reference to a hash. %{$_} recovers the hash.
See http://www.plover.com/~mjd/perl/FAQs/References.html for more
details. That page has an explanation of an example that is quite
similar to yours:
push @{$table{$state}}, $city;
------------------------------
Date: Thu, 28 Sep 2000 00:20:53 GMT
From: oi03_2000@my-deja.com
Subject: Re: Windows 98 / Active Perl / CGI
Message-Id: <8qu2t1$tet$1@nnrp1.deja.com>
In article <slrn8t4ln8.1hv.tim@degree.ath.cx>,
tim@degree.ath.cx (Tim Hammerquist) wrote:
> oi03_2000@my-deja.com <oi03_2000@my-deja.com> wrote:
> > Tim, thanks for your direction. It was really helpful. I was in a
hurry
> > to get the script working, so I did not read my book thoroughly.
Yes, I
> > missed the "Content type" in my script, secondly there was another
minor
> > syntactical error in the script (html part) because of which the
script
> > did not work.
>
> Glad I could help. =)
>
> > But the script never ran on Personal web server though. So I
> > downloaded/installed Apache server on win 98 and every thing is
working
> > fine now. Excepting that the line "content type" shows up on my
output
> > page on the web browser. I'm sure that's not supposed to happen,
still
> > need to figure that out.
>
> If "content type" (or hopefully "Content-type: text/html") shows up in
> the browser, then the header was probably already sent. This could
come
> from anywhere, but most likely comes from a call to CGI::header().
For
> instance:
>
> # ex 1
> use CGI; # keeps namespaces cleaner
> print CGI::header();
>
> # ex 2
> use CGI qw(:standard); # clutters namespaces, but trade-off
> print header(); # for convenience
>
> # ex 3
> use CGI;
> my $q = new CGI; # object-oriented CGI interface;
> print $q->header(); # tidier namespaces; less ambiguity
>
> If you use any of those statements, you can probably remove yours.
> Simply make sure that however you call header() it must be the first
> output your script makes to STDOUT.
>
> > I'm very excited about apache and perl and the myriad things you can
do
> > with perl. Thanks again for the help.
>
> I was pleased with Win98/Apache as well, though there were still the
> standard Win32 stability problems. Apache has not been stable enough
> for production/public level serving on Win32 yet, but it's a great
tool
> nevertheless.
>
> To keep in mind: if you get into Apache/mod_perl, most recent versions
> of CGI.pm are designed to work seemlessly with it.
>
> Warning: some people (on this list) disapprove of CGI.pm. It has been
> described by its own author as "monolithic" and does tend to
> load/compile relatively slowly. However, CGI.pm provides many HTML
> shortcuts that can make life much easier. By all means, use it. If
> time-to-load is important, investigate mod_perl for Apache; it stores
> precompiled modules in memory so it only has to parse/compile them
once.
>
> --
> -Tim Hammerquist <timmy@cpan.org>
> I do not, for one, think that the problem was that the band was down.
> I think that the problem may have been...that there was a Stonehenge
> monument on the stage that was in danger of being crushed by a dwarf.
> -- David St. Hubbins, "This is Spinal Tap"
>
Yeah I was using CGI.pm and was calling header() as you mentioned. Hence
I removed "content type" from my script. I still cannot get this script
working on Personal Web Server (of course now I would never go back to
PWS). As you said, I should move into apache/mod_perl. Does mod_perl
work on regular unix machines (because all the work I do on Windows /
Apache gets moved to production unix box)
The other thing I'm curious about is how the perl/cgi scripts get
executed. My script basically gets input from the HTML form and writes
it to a text file. I was wondering what happens if the web site gets
lot of hits approximately at the same time. How does the cgi script get
executed (multi/single threaded). since I'm writing to the same file ,
is there any chance of some data getting lost.
If anybody has any thoughts, feel free to post here or I would go back
to my reading materials, when I have to more free time to explore these
kind of stuff.
Thanks!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4453
**************************************