[10291] in Perl-Users-Digest
Perl-Users Digest, Issue: 3884 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 3 17:07:23 1998
Date: Sat, 3 Oct 98 14:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 3 Oct 1998 Volume: 8 Number: 3884
Today's topics:
$i = int($1) if ($st = /([0-9]+)/ ==> the int($1) is ig (Richard Gibson)
Re: $i = int($1) if ($st = /([0-9]+)/ ==> the int($1) i <jdf@pobox.com>
Re: Are there conditional comments? (Larry Wall)
Re: Beginner - Help with simple calculation... (Matthew Bafford)
General quesitons about packages, scope, OOP and the HT (Allan M. Due)
Re: General quesitons about packages, scope, OOP and th (Allan M. Due)
Re: Help needed with fcntl in perl <spicano@ptdcs2.intel.com>
help regarding parallel programs <venkat@sol.uconn.edu>
Re: Help! Problem using Sprite SQL module <gellyfish@btinternet.com>
Multi-dimensional arrays <jstallkamp@gmx.net>
Re: Need IP Address Sort Subroutine <willliams@clark.net>
newbie question(EXCEL)! (xinyu cui)
Re: Omaha Perl Mongers - First Meeting ! <eashton@bbnplanet.com>
Re: Omaha Perl Mongers - First Meeting ! <gellyfish@btinternet.com>
open statement in Perl for Win32 not working <dan@bns.com>
Re: open statement in Perl for Win32 not working <gellyfish@btinternet.com>
Re: passing javascript vars to CGI <jeff@vpservices.com>
Re: Perl as solution? <eashton@bbnplanet.com>
Re: Perl as solution? (Leslie Mikesell)
Re: Perl as solution? <dgris@perrin.dimensional.com>
Re: Perl Bug??? (Richard Gibson)
Re: POLL: Perl features springing into your face (Larry Wall)
Re: Script does not write to file <rob@ccsn.com>
Re: Script does not write to file <rob@ccsn.com>
split/join - c/r,lf <arm@home.com>
Re: using sendmail with accents in a cgi? <eashton@bbnplanet.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 03 Oct 1998 11:17:18 GMT
From: Rich@chilidogNOSPAM.com (Richard Gibson)
Subject: $i = int($1) if ($st = /([0-9]+)/ ==> the int($1) is ignored, why?
Message-Id: <361605bc.664936247@news.rmii.com>
Hi,
I am reading a file with numbers embedded 'somewhere' in a certain
position of each line:
simplified sample (in the real data there are more columns):
some text for the first bit number anywhere in here
This is sample text 12345
this is more text 12345
and more 12345
My code looks like this:
while (<>){
/^(.{33})(.{15})/
$st1= $1;
$st2= $2;
$i = $1 if ($st2 =~ /([0-9]+)/); #this works
$i = int($1) if ($st2 =~ /([0-9]+)/); #this does the same thing
}
So: why doesn't the int($1) seem to have an effect?
Cheers,
Rich
------------------------------
Date: 03 Oct 1998 21:35:40 +0200
From: Jonathan Feinberg <jdf@pobox.com>
To: Rich@chilidog.com (Richard Gibson)
Subject: Re: $i = int($1) if ($st = /([0-9]+)/ ==> the int($1) is ignored, why?
Message-Id: <m3btnt8mlv.fsf@joshua.panix.com>
Rich@chilidogNOSPAM.com (Richard Gibson) writes:
> This is sample text 12345
> this is more text 12345
> and more 12345
> $i = $1 if ($st2 =~ /([0-9]+)/); #this works
> $i = int($1) if ($st2 =~ /([0-9]+)/); #this does the same thing
> So: why doesn't the int($1) seem to have an effect?
What effect were you expecting? Those numbers already seem to be
integers.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 3 Oct 1998 10:20:17 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: Are there conditional comments?
Message-Id: <6v5mch$9e2@kiev.wall.org>
In article <36150F07.51B46F85@techne.ca>,
Robert Krajcarski <robertk@techne.ca> wrote:
>I sure somebody out there can give me a hand:
>
>I am writing a module for a large app that will be responsible for
>logging all important information. It will include various
>DEBUG settings, so that the program can turn off all messages (to
>improve performance). The problem that I am facing is that unlike other
>languages (C, C++) there doesn't seem to be any facility to use
>conditional comments (similar to the preprocessor #if ... #endif
>commands). I know that there is the -P command line option that will
>put the perl script throught a C preprocessor, but that doesn't seem to
>be a wonderful solution (since all files will have to be run through the
>perl on the command line, rather then making files executable, in
>addditional to the problems of comments begining with if, else, ....).
>
>My hands are sort of tied in terms of the computational
>requirements...it seems that an "if statement" may be too expensive
>since it is likely to be deeply embeded in loops. So the major question
>is this:
>
> Is there some way for line (4) in the following code to be ignored?
There is no need for conditional compilation in Perl, because the Perl
compiler is smart enough to delete any code that is inside a conditional
that is known at compile time to be false. Watch this:
$ perl -Dx
sub PrintStuff () { 0; }
do_something_heavy() if PrintStuff;
print "here\n";
__END__
{
10 TYPE = leave ===> DONE
FLAGS = (VOID,KIDS,PARENS)
{
4 TYPE = enter ===> 5
}
{
5 TYPE = nextstate ===> 6
FLAGS = (VOID)
LINE = 2
}
{
TYPE = null ===> (6)
(was const)
FLAGS = (VOID)
}
{
6 TYPE = nextstate ===> 7
FLAGS = (VOID)
LINE = 3
}
{
9 TYPE = print ===> 10
FLAGS = (VOID,KIDS)
{
7 TYPE = pushmark ===> 8
FLAGS = (SCALAR)
}
{
8 TYPE = const ===> 9
FLAGS = (SCALAR)
SV = PV("here
")
}
}
}
The only vestige of the statement is the "nextstate" op that was
outside the conditional to begin with. The null op (that one that "was
const", meaning it had determined that your entire statement had a
constant value) is bypassed in execution. See the 5 ===> 6, which show
the execution order of nodes.
Larry
------------------------------
Date: Sat, 3 Oct 1998 12:29:26 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Beginner - Help with simple calculation...
Message-Id: <MPG.10801aee537d1b439896c3@news.south-carolina.net>
In article <6v5gd2$odr$1@news.quebectel.com> on Sat, 3 Oct 1998
11:42:47 -0400, Raynald Provencher (pasdespam@pasdespam.com)
pounded in the following text:
=> Sorry, it does not work...
What do you mean it doesn't work? Does it just sit around doing
nothing? Does your computer explode? Does perl core dump? Is
Perl on strike? Is it demanding a pay increase? Does it print
6.22222222222222222222222222222222222222222? Please be specific.
The code does in fact print out correctly:
% perl -v
This is perl, version 5.005_02
[SNIP]
% perl -e 'printf "%.2f", 6.95 * 0.9'
6.25
% perl -e 'printf "%.2f", 110.00 * 0.9'
99.00
%
So, either you didn't try the code, or you are using a pre-5.005
version of Perl, and your system's libraries are messed up.
=> Any other suggestion?
Tell us what's wrong?
=>
=> Abdulaziz Ghuloum a icrit dans le message <36163916.8A839CA0@psu.edu>...
=> >Raynald Provencher wrote:
=> >> $total = $price * 0.9
=> >> This gives me, for example:
=> >> 6.95 * 0.9 = 6.255 or
=> >> 110.00 * 0.9 = 99
=> >>
=> >> What should I do to get "6.25" instead of "6.255" and "99.00" instead of
=> >> "99"?
=> >
=> >try:
=> >printf ("Total = \$%.2f\n", $total);
=> >
=> > Aziz,,,
=>
=>
=>
--Matthew
------------------------------
Date: 3 Oct 1998 20:15:19 GMT
From: Allan@Due.net (Allan M. Due)
Subject: General quesitons about packages, scope, OOP and the HTML module
Message-Id: <6v60kn$la9$0@206.165.146.40>
Hi Folks,
[warning semi-long rambling post]
I have a friend getting ready to move a large number of files from
one domain to another. I saw the example in the Perl Cookbook to change
hrefs and thought it would do the trick for him and so I volonteered to
modify the script for him. Plus I thought it would be a good
opportunity for me to learn more about parts of Perl I dug into before.
I got my script to work but I don't really understand why (and I am
pretty sure it is not correct) and so I have some questions if anyone
has the inclination to enter educator mode. Mostly the questions have
to do with Packages and OOP. I am sure that I am not doing things
correctly so any feedback would be appreciated.
My goal was to change the script so that names of files to be changed
(and the changes to be made for that matter) could be passed to the
package and the results written to a variable.
The original script is below. Statements in the original script that
I commented out are marked with an #X and the lines I added end in #me.
Questions:
1. If I move my my variable declarations to below the package, the
package can't access them but if they are above the package it can. Why
is this? Where should the use strict go? On a related note, I
somewhere obtained the muleheaded notion that a my variable declared in
the main body of a program was global but that doesn't seem to be true.
If any one could explain way the following prints foobar I would
appreciate it.
$fir = 'bar';
my $fir = 'temp';
$fir = 'foo';
print $fir,$main::fir;
2. Could someone explain what the two subroutines from the HTMl::Filter
are supposed to do. I am pretty sure that the first one is writing the
results from the modified start to an annonymous array. I am able to
write out its conent within the subroutine, so I know it is doing but I
can't figure out how to access it or exactally what is going on.
3. The sub filtered_html joins the array created by output but I can't
figure out how to execute it. I have tried all kinds of variations of
&MyFilter::filter_html and ->s but clearly there is a huge black hole in
my understanding of all this. I get a use of on initialized variable
message which I think reffers to @{$_[0]->{fhtml}} but since I really
don't know what that is I remain befuddled.
4. How would I have to changed things so that I could call this package
in the way that modules are typically called, passing the $from,$to and
file to be parsed all at the same time. Or is that just too much of a
question for where I am at.
I know the following doesn't look like much but I worked on this for
four hours today. I have learned a ton but still a long way to go.
Thanks.
__
Allan M. Due
Allan@Due.net
The beginning of wisdom is the definitions of terms.
- Socrates
---------------------------
#!/usr/bin/perl -w
# hrefsub - make substitutions in <A HREF="..."> fields of HTML files
# from Gisle Aas <gisle@aas.no>
#X sub usage { die "Usage: $0 <from> <to> <file>...\n" }
#X my $from = shift or usage;
#X my $to = shift or usage;
#X usage unless @ARGV;
my $infile = 'scooby.html';#me
my $from = 'shergold.html';#me
my $to = 'cards.html';#me
# The HTML::Filter subclass to do the substitution.
package MyFilter;
require HTML::Filter;
@ISA=qw(HTML::Filter);
use HTML::Entities qw(encode_entities);
#--------
#The commented out subs are from the Filter.pm pod
#sub output {push(@{$_[0]->{fhtml}}, $_[1]);}
sub output {push(@keepit, $_[1]);} #me
sub filtered_html { join("", @{$_[0]->{fhtml}}) }
sub combine{join("",@keepit)}; #me,
#had a return in sub combine but don't seem to need it
#-------
sub start {
my($self, $tag, $attr, $attrseq, $orig) = @_;
if ($tag eq 'a' && exists $attr->{href}) {
if ($attr->{href} =~ s/\Q$from/$to/g) {
# must reconstruct the start tag based on $tag and $attr.
# wish we instead were told the extent of the 'href' value
# in $orig.
my $tmp = "<$tag";
for (@$attrseq) {
my $encoded = encode_entities($attr->{$_});
$tmp .= qq( $_="$encoded ");
}
$tmp .= ">";
$self->output($tmp);
return;
}
}
$self->output($orig);
}
# Now use the class.
#X package main;
#X foreach (@ARGV) {
#X MyFilter->new->parse_file($_);
#X }
package main;
use strict; #me
#X MyFilter->new->parse_file($infile);
#me for all below
my $filter_file = new MyFilter;
$filter_file->parse_file($infile);
print $filter_file->combine;
#first try
#my @newout = &MyFilter::combine;
# foreach (@newout) {
# print "$_\n";
# }
------------------------------
Date: 3 Oct 1998 20:31:49 GMT
From: Allan@Due.net (Allan M. Due)
Subject: Re: General quesitons about packages, scope, OOP and the HTML module
Message-Id: <6v61jl$la9$1@206.165.146.40>
In article <6v60kn$la9$0@206.165.146.40>, Allan M. Due (Allan@Due.net)
posted...
|Hi Folks,
|
|[warning semi-long rambling post]
|
I love posting to the newsgroup becuase it means immediately thereafter
a light bulb will appear over my head. Here is my next version, looks
much better already I think.
---------------------------
#!/usr/bin/perl -w
# hrefsub - make substitutions in <A HREF="..."> fields of HTML files
# from Gisle Aas <gisle@aas.no>
# The HTML::Filter subclass to do the substitution.
package MyFilter;
require HTML::Filter;
@ISA=qw(HTML::Filter);
use HTML::Entities qw(encode_entities);
#sub output {push(@{$_[0]->{fhtml}}, $_[1]);}
sub new_href {
my $self = shift;
$self->{to} = shift;
}
sub old_href {
my $self = shift;
$self->{frome} = shift;
}
sub output {push(@keepit, $_[1]);}
sub filtered_html { join("", @{$_[0]->{fhtml}}) }
sub combine {return join("",@keepit)};
sub start {
my($self, $tag, $attr, $attrseq, $orig) = @_;
if ($tag eq 'a' && exists $attr->{href}) {
#X if ($attr->{href} =~ s/\Q$from/$to/g) {
if ($attr->{href} =~ s/\Q$self->{frome}/$self->{to}/g) {
# must reconstruct the start tag based on $tag and $attr.
# wish we instead were told the extent of the 'href' value
# in $orig.
my $tmp = "<$tag";
for (@$attrseq) {
my $encoded = encode_entities($attr->{$_});
$tmp .= qq( $_="$encoded ");
}
$tmp .= ">";
$self->output($tmp);
return;
}
}
$self->output($orig);
}
# Now use the class.
package main;
my $infile = 'scooby.html';
$filter_file = new MyFilter;
$filter_file->old_href("shergold.html");
$filter_file->new_href("Allan.html");
$filter_file->parse_file($infile);
print $filter_file->combine;
__
Allan M. Due
Allan@Due.net
The beginning of wisdom is the definitions of terms.
- Socrates
------------------------------
Date: Sat, 03 Oct 1998 13:15:13 -0700
From: Silvio Picano <spicano@ptdcs2.intel.com>
To: "Bas A. Schulte" <bas@yournews.nl>
Subject: Re: Help needed with fcntl in perl
Message-Id: <361685D0.BA647165@ptdcs2.intel.com>
Bas A. Schulte wrote:
> Hi all,
>
> while trying to toy with some samples from Stevens' Advanced Programming
> in the Unix environment in perl, I've run across something I can't seem
> to figure out. This is the piece of C code I'm trying to do in perl:
>
> struct flock lock;
>
> lock.l_type = F_WRLCK;
> lock.l_start = 0;
> lock.l_whence = SEEK_SET;
> lock.l_l_len = 0;
>
> fcntl(fd,F_SETLK,&lock);
>
> I just can't seem to be able to do it. IO::File, POSIX::open, built-in
> perl i/o, pack, somehow it doesn't add up for me ;)
>
> Anyone help out?
>
> Regards,
>
> Bas.
Bas,
Make a C program first, to do fcnt() locking, in order to
find the sizes of your particular, OS structures; e.g.,
613 ;# SunOS /usr/include/sys/fcntlcom.h file:
614 ;#
615 ;# /* file segment locking set data type - information passed to system by user */
616 ;# struct flock {
617 ;# short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */
618 ;# short l_whence; /* flag to choose starting offset */
619 ;# long l_start; /* relative offset, in bytes */
620 ;# long l_len; /* length, in bytes; 0 means lock to EOF */
621 ;# short l_pid; /* returned with F_GETLK */
622 ;# short l_xxx; /* reserved for future use */
623 ;# };
624 ;#
625 ;# $ ./fcntl_lock_SunOS
626 ;# sizeof(lk) = 16 bytes.
627 ;# -------------------------------
628 ;# sizeof(lk.l_type) = 2.
629 ;# sizeof(lk.l_whence) = 2.
630 ;# sizeof(lk.l_start) = 4.
631 ;# sizeof(lk.l_len) = 4.
632 ;# sizeof(lk.l_pid) = 2.
633 ;# sizeof(lk.l_xxx) = 2.
634 ;# Total element size = 16 => Matches sizeof(lock) structure.
635 ;# Attempting to lock(tmpfile) ... successful
636 ;# Sleeping for 15 seconds ... Attempting to unlock(tmpfile) ... successful.
Based on the results, you can code a perl routine ...
717 if ($osname_s =~ /sunos/i) {
718 ;# for SunOs 4.1.3;
719 $flock_write_lock_rec = pack("ssllss", F_WRLCK, 0, 0, 0, 0, 0);
720 $flock_unlock_rec = pack("ssllss", F_UNLCK, 0, 0, 0, 0, 0);
721 }
then later ...
738 if ($mode eq 'set') {
739 ;# get a network-wide lock based on this file-handle. Set file segment
740 ;# lock according to the flock structure pointed to by $flock_write_lock_rec.
741 while (1) {
742 $ret_b = fcntl($$fhptr, F_SETLK, $flock_write_lock_rec);
743 if (defined($ret_b)) {
744 ;# successful
745 return (1, "$routine_s: success");
746 }
747 if (++$fail_cnt > $retry_limit_i) {
748 return (-2, "$routine_s: failed fcntl(F_SETLK, F_WRLCK) [$retry_limit_i] times.");
749 }
750 }
751 }
etc ...
Silvio
------------------------------
Date: Sat, 03 Oct 1998 16:17:48 -0500
From: "Venkata N. Malepati" <venkat@sol.uconn.edu>
Subject: help regarding parallel programs
Message-Id: <3616947B.CB15A2A0@sol.uconn.edu>
Hello:
I am trying to invoke parallel simulations on host of computers in the
LAN from a
single program runnning on a single machine. All the simulations invoke
some kind
of GUI. My own program is also a GUI based, so that i should be able to
display the
status of all the simulations running on different computers on my GUI.
I want to use the full power of CPU in all the computers to perform
extensive time consuming
simulations.
Please help. How to write perl modules to perform such a task ?
Regards,
Vivek Rajan
E-MAIL: rajan@sol.uconn.edu
PH: (860) 486-1799
------------------------------
Date: 3 Oct 1998 17:17:54 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Help! Problem using Sprite SQL module
Message-Id: <6v5m82$15b$1@gellyfish.btinternet.com>
On Sat, 03 Oct 1998 16:30:28 +0100 Lee J. Stoneman <look@bottom.of.message> wrote:
> HI,
> I am getting strange results from my use of the SQL module Sprite.
> Instead of returning a list of records matching the SQL query, all I get
> is the following:
> ARRAY(0x8161af4)
> ARRAY(0x8162368)
> ARRAY(0x81649f8)
> ARRAY(0x8165048)
<snip>
> foreach $record (@data)
> {
# Just for fun - you will probably want to something else with your data
print "@$record \n";
> }
> }
> exit (0);
This is because each row return by your query is an array reference
containing each field.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 03 Oct 1998 21:21:21 +0200
From: Johannes Stallkamp <jstallkamp@gmx.net>
Subject: Multi-dimensional arrays
Message-Id: <36167931.3F254970@gmx.net>
Hi folks!
I'm relatively new to perl and I'd like to know if it's possible to
create multi-dimensional arrays......
Thanks
------------------------------
Date: Sat, 3 Oct 1998 16:55:01 -0400
From: "Joe Williams" <willliams@clark.net>
Subject: Re: Need IP Address Sort Subroutine
Message-Id: <6v62us$je7$1@clarknet.clark.net>
This is in answer to my original post. First, many thanks for all the
comments. I will be traveling over the next couple of days, but look forward
to checking them out. Meantime, I'm posting a solution that is certainly not
the most elegant or efficient, but it does work, and is fairly transparent.
I used John Porter's solution to the IP string conversion with some changes
as noted. It is probably over-commented, but what the hell!
Joe Williams
williams@clark.net
#sortest_v1.pl
@list =
("\n0179 Tue 01Sep98 06:17:55 - Address of Site: 129.1.144.88#0179 Tue
(more)",
"\n0560 Tue 01Sep98 08:05:57 - Address of Site: 99.1.13.12#0186 Tu (more)",
"\n0800 Tue 01Sep98 06:38:42 - Address of Site: 205.128.134.105#0180 Tu
(more)",
"\n0460 Tue 01Sep98 07:41:32 - Address of Site: 99.1.13.12#0184 Tue 01S
(more)",
"\n0187 Tue 01Sep98 08:37:16 - Address of Site: 199.77.210.211#0187 Tue
(more)");
print "\n";
print @list;
print "\n";
# Extract the IP address and convert it into an integer and
# assign as a key to a hash with the line from which it was taken
# as the value. This code requires that the lines have a known,
# consistent structure.
#
foreach $list_item (@list)
{
$x = index($list_item, "#");
$w = (index ($list_item, "ite:") + 5);
$ip_dotted_quad = substr( $list_item, $w, ($x - $w) );
$ip_int = dotted_to_int($ip_dotted_quad);
# Must hash with $list_item as key, because $ip_int's are not unique
$hashed_by_ip{$list_item} = $ip_int; # $list_item is the key; $ip_int, the
value
}
print @sorted_lines = sort by_ip_int keys(%hashed_by_ip);
# Subroutines
# -------------------------------------------------------------------------
# Subroutine to convert a dotted quad IP addresses into a sortable number
sub dotted_to_int {
return undef if $_[0] =~ /[^0-9.]/; # undef unless IP address composition
right
my @a = split /\./, $_[0]; # Each octet is in an array element of @a
my $n = pop @a; # $n equals last octet
return undef unless $n < (256 ** ( 4 - @a )); # undef unless last octet <
256. Redundant?
# Cycles from 0 to 3--the four octets. The .. operator expands $#a
for ( 0..$#a ) { # $#a = number of array elements.
return undef unless $a[$_] < 256; # Checks again that each quad < 256
# $n starts equal to the last quad. It is unshifted, and the right
# argument of * below evaluates to zero for this octet.
# Orignal John Porter version used << vice * which returns the value of its
left
# argument shifted left by the number of bits specified by the right
argument.
# The problem is that it also produces negative integers notation
# that could cause trouble.
$n += ( ( $a[$_]) * (8**(3-$_)) ) ; # converts each octet to decimal &
adds them
}
return $n;
}
# -------------------------------------------------------------------------
sub by_ip_int
{
# Sorts by values instead of keys gecko book, p. 163.
# It could easily be place inline with the sort.
return $hashed_by_ip{$a} <=> $hashed_by_ip{$b};
}
# End program code and subroutines section -------------------------------
Michal Rutka wrote in message ...
>John Porter <jdporter@min.net> writes:
>
>> Joe Williams wrote:
>> >
>> > Does anyone have, or can anyone me toward a routine that will sort IP
>> > addresses? Many thanks.
>>
>> I assume you want to sort them numerically.
>
>Why? IP address is a string of four characters. It is better to
>sort them as strings.
>
>> You will therefore want to be able to convert dotted-quad
>> notation to an integer. The following sub does it:
>
>Why? It cost only time all this calculations. BTW your code do not
>work for IP 200.255.255.255. On my machine it returns -1. Anyway, every
>address above 127.255.255.255 is 'unsortable' by you. It just 50% of
>all addresses so who cares?
>
>>
>> sub dotted_to_int {
>> return undef if $_[0] =~ /[^0-9.]/;
>> my @a = split /\./, $_[0];
>> my $n = pop @a;
>> return undef unless $n < (256 ** ( 4 - @a ));
>> for ( 0..$#a ) {
>> return undef unless $a[$_] < 256;
>> $n += ( $a[$_] << (8*(3-$_)) );
>> }
>> $n;
>> }
>>
>> (It actually accepts all valid dotted-number notations,
>> not just dotted-quad.)
>>
>> Then you can use a Schwartzian Transform to do the sort:
>>
>> @ips_sorted =
>> map { $_->[0] }
>> sort { $a->[1] <=> $b->[1] }
>> map { $_, dotted_to_int( $_ ) }
>> @ips;
>>
>> Hope this helps.
>
>Horror.
>
>>
>> --
>> John "Many Jars" Porter
>
>Hymm, how about this:
>
>@ips_sorted = sort {pack("C4",split(/\./,$a)) cmp
pack("C4",split(/\./,$b))}
> @ips;
>
>Should be faster and without this Schwartzian thing (what is it, anyway)?
>BTW. Your 'Schwartzian' code does not work for me. I.e. lot of
uninitialized
>values and result is empty.
>
>Regards,
>
>Michal
------------------------------
Date: 3 Oct 1998 18:45:17 GMT
From: xcui@chat.carleton.ca (xinyu cui)
Subject: newbie question(EXCEL)!
Message-Id: <6v5rbt$849$1@bertrand.ccs.carleton.ca>
I am trying write a perl script to import a list of numbers to an EXCEL
file, so far I can only get them printed to the first row. I want be able
to print them to places I desire. For example, I'd like to able to print
number 2, 3, 4 in random cells such as A1, B2, C3, any suggestions? I
appreciate your help in advance!!
Xin
------------------------------
Date: Sat, 03 Oct 1998 19:01:24 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Omaha Perl Mongers - First Meeting !
Message-Id: <3616720E.1A00D197@bbnplanet.com>
Jonathan Stowe wrote:
> > Saarinen was wacky. Its a croquet wicket, of course.
>
> Lock up your pelicans Elaine wants to play croquet ;-P
Pelicans?
e.
As I was lying there with my eyes closed, just after I'd
imagined what it might be like if in fact I never got up
again, I thought of you. I opened my eyes then and got
right up and went back to being happy again.
I'm grateful to you, you see. I wanted to tell you. -R. Carver-
------------------------------
Date: 3 Oct 1998 20:06:50 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Omaha Perl Mongers - First Meeting !
Message-Id: <6v604q$17q$1@gellyfish.btinternet.com>
On 3 Oct 1998 10:06:50 -0000 Jonathan Stowe <gellyfish@btinternet.com> wrote:
> On Fri, 02 Oct 1998 19:57:45 GMT Elaine -HappyFunBall- Ashton wrote:
>> Saarinen was wacky. Its a croquet wicket, of course.
> Lock up your pelicans Elaine wants to play croquet ;-P
I reesed that up like a right gugus - that'll be flamingos of course.
I'm getting my Lewis Caroll confused with King Lear's daughters
But I think I got away with it ;-P`
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 3 Oct 1998 09:45:45 -0700
From: "Dan Bassett" <dan@bns.com>
Subject: open statement in Perl for Win32 not working
Message-Id: <3616571b.0@news1.starnetinc.com>
I am trying to use an open statement such as the one below to execute a
program
on my Win95 machine:
open (FILE, "program variable1 variable2") or die "The program cannot be
executed.\n";
print "The program executed successfully.";
close (FILE);
It seems as though when I specify any variables or parameters after the
program name,
it tells me the program cannot be executed. However, when just supplying
the program
name without any variables or parameters, such as below, it tells me the
program executed successfully:
open (FILE, "program") or die "The program cannot be executed.\n";
print "The program executed successfully.";
close (FILE);
On my Unix machine, the above scripts work as they should, however, on my
Win95 machine,
running the latest Perl for Win32, the first script above does not want to
work.
Any ideas?
Thanks,
Dan
dan@bns.com
------------------------------
Date: 3 Oct 1998 20:00:53 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: open statement in Perl for Win32 not working
Message-Id: <6v5vpl$17n$1@gellyfish.btinternet.com>
On Sat, 3 Oct 1998 09:45:45 -0700 Dan Bassett <dan@bns.com> wrote:
> I am trying to use an open statement such as the one below to execute a
> program
> on my Win95 machine:
> open (FILE, "program variable1 variable2") or die "The program cannot be
> executed.\n";
> print "The program executed successfully.";
> close (FILE);
In this snippet Perl will not find a file called "program variable1 variable2"
to open for a plain read - you have omitted the "|" that would cause Perl
to recognize this as a pipe.
<snip>
> open (FILE, "program") or die "The program cannot be executed.\n";
> print "The program executed successfully.";
> close (FILE);
In this case it is probable that Perl can find a file called "program" to
open and read. However it is not executed simply read.
You really must read the perlfunc manpage regarding "open" or alternatively
use the backticks to execute an external command and capture its output.
I hate to say this but it probably is appropriate under this circumstance:
RTFM.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 3 Oct 1998 15:31:55 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: passing javascript vars to CGI
Message-Id: <361642B4.875ADF44@vpservices.com>
[pre-note to clpm-ers: right, this has nothing to do with perl, but
three previous clpm-ers gave bogus answers to this question about using
wrap or saying this is a javascript question (which it isn't, it's an
html question, so to clear the air...]
In comp.lang.perl.misc Phinneas G. Stone <phinneas@eskimo.com> wrote:
>Is it possible to process a variable with javascript, then pass that
>value along to a CGI script? What I'm trying to do is preserve the
>line breaks in a <textarea> by encoding with the javascript escape()
>function and decoding them with perl once the form has been submitted.
Is this a trick question? Why would you need to use javascript to
escape the contents of the textarea? *Anything* in a form is
automatically escaped when you submit the form so escaping it again
would be pointless. And line breaks *are already automatically*
preserved in a textarea regardless of wrap being set to physical or
virtual or not. Wrap only impacts lines where the user does not press
carriage return (i.e. where there are no line breaks).
Perhaps what you mean is that the line breaks do not show up when you
display the form on the web. That's because any amount of whitespace
(including line breaks) is turned into a single space by a conforming
browser.
If you want the line breaks to show up on your web page, you don't need
to do anything on the form itself, just, when you decode the form, do
this for each param: $param =~ s/\n/<br>/g;
- Jeff
------------------------------
Date: Sat, 03 Oct 1998 19:08:13 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Perl as solution?
Message-Id: <361673A7.74BF28CB@bbnplanet.com>
Daniel Grisinger wrote:
> RTFM.
>
> $ perldoc -q 'car alarm'
>
> =head1 Found in perlfaq1764.pod
Hehheeh. Cute. Well, my program was a bit buggy too. I came ever so
close to getting arrested for disturbing the peace (if I heard Celine
Dion at 3am I'd be callin' the cops too) but it got their attention and
the alarm will be desensitised. I live in a dry town where the average
age is 70 why one would need one of those is a wonderment. I leave my
car doors unlocked and it has never been touched.
e.
As I was lying there with my eyes closed, just after I'd
imagined what it might be like if in fact I never got up
again, I thought of you. I opened my eyes then and got
right up and went back to being happy again.
I'm grateful to you, you see. I wanted to tell you. -R. Carver-
------------------------------
Date: 3 Oct 1998 14:51:34 -0500
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Perl as solution?
Message-Id: <6v5v86$d7d$1@Venus.mcs.net>
In article <6v4ekq$eck$1@mathserv.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Daniel Grisinger
><dgris@perrin.dimensional.com>],
>who wrote in article <m3vhm2ur7t.fsf@perrin.dimensional.com>:
>> my $neighbor = 'fred';
>> my $is_annoying = 1;
>>
>> while (1) {
>> if ($sentry -> is_disturbed) {
>> if ($neighbor = is_annoying()) {
> ^^^
> |
>
>I wonder what missile guidance AI could detect an error like this one?
You mean better than "perl -w" which would report:
Found = in conditional, should be == at - line nnn
Now we just need a taint-like check for variables that are alternately
used in time() related functions and strings containing "19".
Les Mikesell
les@mcs.com
------------------------------
Date: Sat, 03 Oct 1998 20:02:12 GMT
From: Daniel Grisinger <dgris@perrin.dimensional.com>
Subject: Re: Perl as solution?
Message-Id: <m3d889s9lq.fsf@perrin.dimensional.com>
les@MCS.COM (Leslie Mikesell) writes:
> In article <6v4ekq$eck$1@mathserv.mps.ohio-state.edu>,
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> ><dgris@perrin.dimensional.com>],
> >who wrote in article <m3vhm2ur7t.fsf@perrin.dimensional.com>:
> >> if ($neighbor = is_annoying()) {
> >I wonder what missile guidance AI could detect an error like this one?
>
> You mean better than "perl -w" which would report:
>
> Found = in conditional, should be == at - line nnn
^^^^^^^^^^^^
-w is wrong. It doesn't know my neighbors. :-)
dgris
------------------------------
Date: Sat, 03 Oct 1998 11:53:04 GMT
From: Rich@NOSPAM.chilidog.com (Richard Gibson)
Subject: Re: Perl Bug???
Message-Id: <36160fe2.667534163@news.rmii.com>
On Fri, 2 Oct 1998 21:43:45 -0400, "Craig Bandon" wrote:
>foreach $var ( keys %ENV )
>{
> print $var . "='" . $ENV{$var} . "'<br>\n";
>}
>
>Other helpful information. I run this locally and get all of the environment
>variables. I run it on an NT host and a Unix host and everything seems to be
>OK. I run it on my host at www.imconline.net (NT server) and it don't work.
>I have changed variable names added () around %ENV. I have tried values
>instead of keys. My host provider says they have checked everything out on
>their end and everything is OK.
>
>What am I missing????
Have your provider check the mappings. I would bet that they are
mapping .pl (or whatever extension you are using) to PerlIS.dll,
rather than to Perl.exe.
That is fine...in fact, it means that your scripts execute faster, but
when you run Perl as an ISAPI filter under NT you lose access to the
%ENV hash.
Cheers,
Rich
------------------------------
Date: 3 Oct 1998 10:37:33 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: POLL: Perl features springing into your face
Message-Id: <6v5nct$9i2@kiev.wall.org>
In article <1dgapxq.1k7x8g2egvnndN@bay1-183.quincy.ziplink.net>,
Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
>Larry Wall <larry@kiev.wall.org> wrote:
>
>> >Definitely I like barewords where they are unambiguous: in ->{foo},
>> >foo => and `use foo'. A list of places where they should be allowed
>> >should be created.
>>
>> According to the official definition of "bareword", none of these examples
>> are. Real barewords are already outlawed by 'use strict'.
>
>This means, ironically, that there are no barewords in this statement:
>
>no clothes;
Just don't call me "emperor". :-)
Larry
------------------------------
Date: Sat, 3 Oct 1998 12:14:00 -0500
From: "Roberto Cerini" <rob@ccsn.com>
Subject: Re: Script does not write to file
Message-Id: <6v5m4h$fjo@nnrp3.farm.idt.net>
There sure are a lot of idiots around here who think they are f@#$g
geniuses. Well, I sure as hell hope you never find yourself in the dark
about something...
Regards,
--
Roberto Cerini
rob@ccsn.com
Ronald J Kimball wrote in message
<1dgapmg.69lu6f1c5i6z5N@bay1-183.quincy.ziplink.net>...
>Roberto Cerini <rob@ccsn.com> wrote:
>
>> My script has the following lines in it:
>>
>> open(testfile,"/home/user/public_html");
>> print testfile "This is a test\r\n";
>> close testfile
>>
>> When I run the script, nothing happens to the testfile (which I have
already
>> created).
>>
>> Any suggestions?
>
>1. Read the documentation.
>
>2. Check the return value of open.
>
>3. Open the file for *writing*. Duh!
>
>--
> _ / ' _ / - aka - rjk@coos.dartmouth.edu
>( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
> / http://www.ziplink.net/~rjk/
> "It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 3 Oct 1998 12:14:00 -0500
From: "Roberto Cerini" <rob@ccsn.com>
Subject: Re: Script does not write to file
Message-Id: <6v5mnc$fp9@nnrp3.farm.idt.net>
There sure are a lot of idiots around here who think they are f@#$g
geniuses. Well, I sure as hell hope you never find yourself in the dark
about something...
Regards,
--
Roberto Cerini
rob@ccsn.com
Ronald J Kimball wrote in message
<1dgapmg.69lu6f1c5i6z5N@bay1-183.quincy.ziplink.net>...
>Roberto Cerini <rob@ccsn.com> wrote:
>
>> My script has the following lines in it:
>>
>> open(testfile,"/home/user/public_html");
>> print testfile "This is a test\r\n";
>> close testfile
>>
>> When I run the script, nothing happens to the testfile (which I have
already
>> created).
>>
>> Any suggestions?
>
>1. Read the documentation.
>
>2. Check the return value of open.
>
>3. Open the file for *writing*. Duh!
>
>--
> _ / ' _ / - aka - rjk@coos.dartmouth.edu
>( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
> / http://www.ziplink.net/~rjk/
> "It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 03 Oct 1998 19:45:03 GMT
From: Alan Melton <arm@home.com>
Subject: split/join - c/r,lf
Message-Id: <36167D30.CB757A73@home.com>
1998]Spring]MAE]5583]0-13-359993-0]ALL]PRINCIPLES CORROSION]92.25
1998]Spring]STAT]4091]1-58025-018-1]ALL]SAS SYSTEM ANALYSIS]28.25
1997]Fall]CIED]3710]0-87120-228-X]003,004]INSPIRING LEARNING]14.95
1998]Fall]PSYCH]1113]0-15-510231-1]901]IN SEARCH MACINTOSH CD ROM]87.50
I have a program that will allow extraction of data out of
a delimited file:
for $filename ("ftext.txt") {
open (IN, "<$filename") or die "Cannot read $filename: $!";
@titles = qw/CAT CAT5 SEC CAT2 CAT1 CAT4 NAME SKU/;
while (<IN>) {
chomp;
@f = split (']'), $_;
print OUTPUT join ('|', map {$_ . '=' . shift @f} @titles), "|\n";
}
close IN;
}
1;
and then join them with a | delimiter and add to each field
extra i.e. CAT=1998
If I take
print OUTPUT join ('|', map {$_ . '=' . shift @f} @titles), "|\n";
and change it to add a few extra fields i.e.
print OUTPUT join ('|', map {$_ . '=' . shift @f} @titles),
"|TAX=Y|CAT11=N|\n";
the final output puts the two additional fixed fields (TAX and CAT11) on
a separate
line (0D0A) but I want them appended onto the same line.
Present output
CAT4=1998|CAT3=Spring|CAT8=MAE|CAT=5583|CAT9=0-13-359993-0|CAT7=ALL|NAME=PRINCIPLES
& PREVENTION OF CORROSION|PRICE=92.25
|TAX=Y|SHG=A|SH=@total|CAT5=N|
I want
CAT4=1998|CAT3=Spring|CAT8=MAE|CAT=5583|CAT9=0-13-359993-0|CAT7=ALL|NAME=PRINCIPLES
& PREVENTION OF CORROSION|PRICE=92.25|TAX=Y|SHG=A|SH=@total|CAT5=N|
What can I do to the split or join to make this happen?
Thanks, Alan Melton
------------------------------
Date: Sat, 03 Oct 1998 19:39:32 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: using sendmail with accents in a cgi?
Message-Id: <36167AFF.164C07A@bbnplanet.com>
Sam Wang wrote:
> add the -x flag/switch to the sendmail call.
**whack** This is incorrect. This has little to do with sendmail but
with the cgi. I have never done this but I would suggest looking at the
character set that your form is using. No special header required that I
know of other than the charset which should tell the MUA how to display
the characters. The question is whether or not you can set that inside
of a cgi form. I think there is an accecpt-charset=<inserthere> or
somesuch tag that you can use. Find a good html reference and check.
e.
As I was lying there with my eyes closed, just after I'd
imagined what it might be like if in fact I never got up
again, I thought of you. I opened my eyes then and got
right up and went back to being happy again.
I'm grateful to you, you see. I wanted to tell you. -R. Carver-
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3884
**************************************