[17564] in Perl-Users-Digest
Perl-Users Digest, Issue: 4984 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 28 21:05:58 2000
Date: Tue, 28 Nov 2000 18:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975463509-v9-i4984@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 28 Nov 2000 Volume: 9 Number: 4984
Today's topics:
Re: algorith help: combining similar lines (Craig Berry)
AOL email --> RFC822, stuck. gjs.REMOVE@khalsa.com
Re: Encrypting passwords (Honza Pazdziora)
FAQ 4.19: How do I remove consecutive pairs of charac <faq@denver.pm.org>
Re: Gotta weird problem...disappearing variables <ronh@iainc.com>
How do I query a named to translate IP into hostname <linux@wizdom.org.uk>
Re: How do I query a named to translate IP into hostnam <taboo@comcen.com.au>
Re: Multiple Modules (Chris Fedde)
Re: Multiple Modules (Tom Christiansen)
Perl + Win32:OLE + ADO - Please help :) gonzalogil99@my-deja.com
Re: PLEASE HELP ME???!!!! <joe+usenet@sunstarsys.com>
Re: PLEASE HELP ME???!!!! (Ilya Zakharevich)
Re: PLEASE HELP ME???!!!! (Malcolm Dew-Jones)
Re: PLEASE HELP ME???!!!! <joe+usenet@sunstarsys.com>
Re: Should { } always indicate a scope? <ren.maddox@tivoli.com>
Re: Should { } always indicate a scope? <jeffp@crusoe.net>
Re: Simple Open file fails in Active Perl 5.6.0 on Wind <martin.long@virgin.net>
Re: Simple Open file fails in Active Perl 5.6.0 on Wind <wyzelli@yahoo.com>
Re: Skipping lines in a file <taboo@comcen.com.au>
Socket connection through firewall... fallenang3l@my-deja.com
Re: system() argument: multiple spaces collapsed into s <bcaligari@my-deja.com>
Re: Unmatched Single Quote <taboo@comcen.com.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 28 Nov 2000 23:19:31 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: algorith help: combining similar lines
Message-Id: <t28fc3qncr5b4a@corp.supernews.com>
Adam Spragg (atspragg@garbanzo.engr.ucdavis.edu) wrote:
: I have a text file that looks like this
:
: ABCD, 100, DEF, GHI, JKL
: ABCD, 50, DEF, GHI, JKL
: ABCD, 1000, DEF, GHI, JKL
: XYZ, 100, IJK, LMN, OPQ
: XYZ, 200, IJK, LMN, OPQ
:
: As ouput, I'd like the sum totals for each grouping:
:
: ABCD, 1150, DEF, GHI, JKL
: XYZ, 300, IJK, LMN, OPQ
:
: Any ideas? I wrote something which is pretty ugly (double while loop)
: which reads a line, then reads in the rest of the lines, does some
: matching, etc... But is there a better way? And this being Perl-y, the
: answer is probably "yes."
How about this?
#!/usr/bin/perl -w
# sumgroups - demo for clpm
# Craig Berry (20001128)
use strict;
my %sum;
while (<DATA>) {
chomp;
my @fields = m/\w+/g;
my $key = join ':', @fields[0, 2..4];
$sum{$key} += $fields[1];
}
foreach (sort keys %sum) {
my @parts = split /:/;
print join(', ', $parts[0], $sum{$_}, @parts[1..3]), "\n";
}
__DATA__
ABCD, 100, DEF, GHI, JKL
ABCD, 50, DEF, GHI, JKL
ABCD, 1000, DEF, GHI, JKL
XYZ, 100, IJK, LMN, OPQ
XYZ, 200, IJK, LMN, OPQ
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Here's to the struggles of the silent war,
| here's to the closing of the age." -The Call
------------------------------
Date: Wed, 29 Nov 2000 01:40:53 GMT
From: gjs.REMOVE@khalsa.com
Subject: AOL email --> RFC822, stuck.
Message-Id: <3a245df4.711640795@news.cis.dfn.de>
(sorry if this posted twice -- server weirdness)
Hi All,
I am trying to create a script with that will convert AOL email
messages to a standard RFC format, and it is not working the way I
expect. If you don't know, AOL puts the headers beneath the body of
the email, thusly:
#BODY
#BODY
#BODY
#BODY
#BODY
--------------------Headers --------------------
#HEADERS
#HEADERS
#HEADERS
#HEADERS
And here is the pertinent section of the script :
#!C:\Perl\bin
use strict;
my %mail;
my @chunks;
my @822;
local $/ = undef;
@chunks = split(m/--------------------Headers --------------------/,
<>);
push (@822, $chunks[1]);
# Now, I want to assign each line of @822 as a key-value pair of
# hash %mail and it's not working the way I expect ...
foreach $822 (@822) {
@header = split (":", $822);
$header[0] = "$header[0]\:";
$mail{$header[0]} = $header[1]
}
print %mail;
__END__
What I am looking for, of course, is a hash made of the headers of the
email. What I get is a split after every single word, not every ':'. I
thought $/ might be the culprit but when I assigned "\n" to it, there
was no change in the output of this program. Thanks for any
insight/help into this problem!
------------------------------
Date: Tue, 28 Nov 2000 16:36:45 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Encrypting passwords
Message-Id: <G4qu59.DKo@news.muni.cz>
On Tue, 28 Nov 2000 09:26:12 -0700, Rob Greenbank <rob@frii.com> wrote:
>
> This problem has to exist for others, especially using the BDI
> modules. Has anyone else come up with a better way to solve this?
Yes, store the password to a file and give it only the necessary
permissions. The password comes up in cleartext through the connect so
encrypting it _in_ the code doesn't help if you allow people to see
the code, no matter what language you use.
Or use some other style of authentication.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Wed, 29 Nov 2000 01:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ 4.19: How do I remove consecutive pairs of characters?
Message-Id: <hOYU5.154$QX6.186756608@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How do I remove consecutive pairs of characters?
To turn `"abbcccd"' into `"abccd"':
s/(.)\1/$1/g; # add /s to include newlines
Here's a solution that turns "abbcccd" to "abcd":
y///cs; # y == tr, but shorter :-)
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep comming up. If you are some how irritated by
seeing these postings you are free to ignore them or add the sender
to your killfile. If you find errors or other problems with these
postings please send corrections or comments to the posting email
address.
If you are not able to find this or other Perl documentation from
your installation you may access it via the web by following the
appropriate links from one of the addresses listed below.
http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
http://www.perldoc.com
http://www.cpan.org
http://www.perl.com
Answers to questions about LOTS of other stuff, mostly not related to
Perl, can be found at
news:news.answers
and in the many thousands of other useful Usenet news groups.
The perlfaq manual pages contain the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
When included as an integrated part of the Standard
Distribution of Perl or of its documentation (printed or
otherwise), this work is covered under Perl's Artistic
License. For separate distributions of all or part of
this FAQ outside of that, see the perlfaq manpage.
Irrespective of its distribution, all code examples here
are public domain. You are permitted and encouraged to
use this code and any derivatives thereof in your own
programs for fun or for profit as you see fit. A simple
comment in the code giving credit to the FAQ would be
courteous but is not required.
--
This space intentionally left blank
------------------------------
Date: Tue, 28 Nov 2000 18:43:23 -0500
From: Ron Hartikka <ronh@iainc.com>
Subject: Re: Gotta weird problem...disappearing variables
Message-Id: <3A24431B.B3C4943F@iainc.com>
this program:
my $self = 'self';
my $id = ')';
my $title = 'title';
my $body = "$$id";
print "id:\t$id\n" if 1;
print "title:\t$title\n" if 1;
print "Body:\t|$body|\n" if 1;
#^^^^^^^^^^^prints $body just fine
unless ($body) { die "Missing body:$body"; }
#^^^^^^^^^^^$body is undefined here?
print "Body:\t|$body|\n" if 1;
#^^^^^^^^^^^prints $body just fine again
die "Missing or incorrect id no." unless ($id =~ /^\d+$/);
die "Missing title." unless $title;
#^^^^^^^^^^^the two lines above work fine as well
prints:
Missing body:0 at wierd.pl line 11.
id: )
title: title
Body: |0|
Maybe your data has a similar problem. Try
unless (length $body) ...
in your test; it fixes this program. Phew!
Daniel Bohling wrote:
> This one blows me away...
> the variable $body contains a news story on one line
> it is suddenly undefined on the next
> then reappears.
>
> sub index {
> my $self = shift;
> my $id = shift;
> my $title = shift;
> my $body = shift;
>
> print "id:\t$id\n" if $self->{print};
> print "title:\t$title\n" if $self->{print};
>
> print "Body:\t|$body|\n" if $self->{print};
> #^^^^^^^^^^^prints $body just fine
> unless ($body) { $self->die_gracefully("Missing body:$body"); }
> #^^^^^^^^^^^$body is undefined here?
> print "Body:\t|$body|\n" if $self->{print};
> #^^^^^^^^^^^prints $body just fine again
> $self->die_gracefully("Missing or incorrect id no.") unless ($id =~ /^\d+$/);
> $self->die_gracefully("Missing title.") unless $title;
> #^^^^^^^^^^^the two lines above work fine as well
------------------------------
Date: Wed, 29 Nov 2000 01:16:11 +0000
From: Mark Worsdall <linux@wizdom.org.uk>
Subject: How do I query a named to translate IP into hostname
Message-Id: <ulZ292CbjFJ6Ewv9@worsdall.demon.co.uk>
Hi,
I have a script that checks to see what stations are up, but I would
like if a stations is up to get its CNAME/realname/ IP address into a
name address.
Any modules to do this?
M.
--
He came from Econet - Oh no, I've run out of underpants :(
Home:- jaydee@wizdom.org.uk http://www.wizdom.org.uk
Shadow:- webmaster@shadow.org.uk http://www.shadow.org.uk
Work:- netman@hinwick.demon.co.uk http://www.hinwick.demon.co.uk
------------------------------
Date: 29 Nov 2000 12:45:01 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: How do I query a named to translate IP into hostname
Message-Id: <3a245f9d$1@nexus.comcen.com.au>
Mark Worsdall <linux@wizdom.org.uk> wrote:
>Hi,>
>I have a script that checks to see what stations are up, but I would
>like if a stations is up to get its CNAME/realname/ IP address into a
>name address.
>
>Any modules to do this?
Don't realy get what you want but, I think if you read
perldoc Socket it may help you.
------------------------------
Date: Tue, 28 Nov 2000 23:42:34 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Multiple Modules
Message-Id: <KpXU5.153$QX6.189523968@news.frii.net>
In article <t27u5ikuph084d@corp.supernews.com>,
Robert Lund <noone@dontbother.com> wrote:
>
>The names of the modules I use are not actually a-z.pm, I'm just using them
>as examples. Again, the reason I've split them up if for the sakes of
>readibility and maintainability. Each one is an individual perl module
>that exports sundry subroutines. Putting it all into one file would be
>thousands of lines of code. If I don't 'use' CGI and LWP in each of the
>smaller modules, the functions like get and param aren't available. I was
>hoping someone might have some insight as to the best way to arrange these
>files...
>
I guess that it was not clear to me. I'm sorry for the confusion.
I'm still not clear why each of the "a-z.pm" modules needs the 'use CGI;'
and 'use LWP;' lines. Is that for testing purposes? As I said in a
previous post you don't need to do it but it does not cause a problem.
Since module factorization is really a matter of design there are no hard
and fast rules to it. Choosing between 'use' and 'require' is also a bit
vague. 'Use' is more typical of classes that want to export something
since it is really a shorthand for
BEGIN { require Module; import Module LIST; }
If your module does not have an import function then you don't need to use
'use'. On the other hand it has become fashionable to use 'use' rather than
'require', Even for modules that don't implement an import function.
I guess that it makes for a more uniform interface.
From the tone of your reply I suspect that I'm way off the mark.
Good luck anyway.
chris
--
This space intentionally left blank
------------------------------
Date: 28 Nov 2000 17:15:03 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Multiple Modules
Message-Id: <3a244a87@cs.colorado.edu>
In article <KpXU5.153$QX6.189523968@news.frii.net>,
Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>If your module does not have an import function then you don't need to use
>'use'. On the other hand it has become fashionable to use 'use' rather than
>'require', Even for modules that don't implement an import function.
>I guess that it makes for a more uniform interface.
Well, there is that. But there are other reasons, too. For example,
potential "used-only-once" complaints, or mismatched prototypes.
Or the fact that it's best to resolve accessibility of needed
libraries prior to execution of the program. Or, slightly more
abstrusely, prototypes. If you called in your main program
Foo::Bar(@a,@b) and it had a sub Foo::Bar(\@\@) signature, that
would not get seen by the compiler, so the call would be miscompiled.
--tom
------------------------------
Date: Wed, 29 Nov 2000 00:42:53 GMT
From: gonzalogil99@my-deja.com
Subject: Perl + Win32:OLE + ADO - Please help :)
Message-Id: <901jec$p5e$1@nnrp1.deja.com>
Here is my example code.
What i want to do is basically display a certain amount of records per
page in my site. I've done it tons of time with ASP, but im having
problems with ADO in perl. Maybe im missing some setting, i dunno, but
i set the pagesize propertie, i checked it to make sure its right (i
printed $RS->{Pagesize} and it prints the number i specified, also i
had it printing the # of pages (i had 15 records, i set the property to
5, and so it would display 3, 3 pages of 5 records, so i know thats
setup). YET when i run it through the loop at the bottom of my script,
it prints all 15 records, instead of just the 5 its supposed to be
displaying.
Any clues?
Please help if you can :)
print "Content-type: text/html\n\n";
$DSN = "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=D:/intranet/test.mdb";
$stmt="SELECT * from patients ORDER by state";
use Win32::OLE;
$Conn = Win32::OLE->new('ADODB.Connection'); # creates a connection
object
$RS = Win32::OLE->new('ADODB.Recordset'); # creates a recordset
object
$Conn->Open("$DSN");
$Conn->{CursorLocation}=3;
$RS->{CursorType}="adOpenStatic";
$RS->{PageSize} = 5;
$RS->{AbsolutePage} = 1;
$RS->{Page}=1;
$RS->{CurrentPage}=1;
$RS->{CursorLocation} = "adUseClient";
$RS->Open($stmt,$Conn,3,3);
$count = $RS->Fields->{Count};
if (!$RS)
{
$Errors=$Conn->Errors();
print "Errors:\n";
foreach $error (keys %$Errors)
{
print "$error", "_\n";
}
die;
}
while (!$RS->EOF)
{
print $RS->Fields('state')->value, "<br>";
$RS->moveNext;
}
$RS->Close;
$Conn->Close;
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Nov 2000 18:08:55 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <m3snob7kzc.fsf@mumonkan.sunstarsys.com>
Uri Guttman <uri@sysarch.com> writes:
> try this:
>
> @l = qw( aaa bbb ccc ) ;
>
> $x = 'h1h2h3' ;
>
> $x =~ s/(h)/$1$l[rand @l]/g ;
>
> print "$x\n" ;
>
> that will randomly replace h as the $1 'changes' in each iteration of
> /g. so /e will force a complete execution each time which is a solution
> if you have no changing variables.
>
However this is implemented, it appears to be pretty well done:
--------------------
#!/usr/bin/perl -w
@words = ('a'..'e');
sub move { pop @words };
$_ = "This ZZZZ ZZZZ ZZZZ is clever ZZZZ\n";
s/(?{move()})ZZZZ/$words[rand @words]/g;
print ;
__END__
--------------------
This also works exactly as Uri described.
--
Joe Schaefer
------------------------------
Date: 28 Nov 2000 23:40:15 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <901fov$smj$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x7g0kbbtyt.fsf@home.sysarch.com>:
> BL> s/ZZZZ/$words[rand @words]/ge;
>
> BL> If anybody can explain me this: if you don't use the /e option (you
> BL> shouldn't need it because what is in brackets is executed anyway), you
> BL> get the same word for every replacement, in the whole string. Huh? Does
> BL> this not look like memoization (funcion value caching)?
>
> well, think about it this way, the replacement string is interpolated
> once and used for the global replacement. if no variables have changed
> then it won't reinterpolate.
Eh? There is no such thing as a "replacement string". Replacement is
*always* an expression. s///e is the basic form, and what s/x/bar/
does is just auto-putting quotes for you: it is equivalent to
s/x/"bar"/e.
What you observe is a bug somewhere in the code for recognition of a
"constant replacement" (to optimize some substitutions by doing them
in place). Please report.
Ilya
------------------------------
Date: 28 Nov 2000 15:45:31 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <3a24439b@news.victoria.tc.ca>
Bart Lateur (bart.lateur@skynet.be) wrote:
: Ross wrote:
: >What I'm trying to create is a program that will use the /etc/dict (or other
: >wordfile) and pick random words from this file and insert them into a
: >textfile, replacing each instance of 'ZZZZ' with one of these random words.
: Wrong newsgroup. There no module in sight. Follow-ups set to
: comp.lang.perl.misc.
: Assuming @words contains the list of words,
: s/ZZZZ/$words[rand @words]/ge;
: If anybody can explain me this: if you don't use the /e option (you
: shouldn't need it because what is in brackets is executed anyway), you
: get the same word for every replacement, in the whole string. Huh? Does
: this not look like memoization (funcion value caching)?
If you wrote
$replacement = 'BLAHBLAH';
s/ZZZZ/$replacement/g
then this would be the same as running the command
s/ZZZZ/BLAHBLAH/g
Your example is no different. "$words[rand @words]" is an interpolated
string which has a single (though random) value (e.g.) "BLATBAR"
So the s///g command is actually running as (e.g.) s/ZZZZ/BLATBAR/g
If you use s///e on the other hand, then the string on the right is used
as a command, ie instead of being treated as an interpolated string, it
is treated as a piece of code.
so that
s/ZZZZ/$words[rand @words]/ge;
is similar to (pseudo code)
foreach ZZZZ found in the string , replace it with the
results of running the code snippet "$words[rand @words]"
------------------------------
Date: 28 Nov 2000 18:53:54 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: PLEASE HELP ME???!!!!
Message-Id: <m3ofyz7iwd.fsf@mumonkan.sunstarsys.com>
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> What you observe is a bug somewhere in the code for recognition of a
> "constant replacement" (to optimize some substitutions by doing them
> in place). Please report.
Here's two code snippets that illustrate the difference:
----------------------
#!/usr/bin/perl -w
@words = ('a'..'e');
@rows = (0,1,2,3,4);
sub move { pop @rows;};
$_ = "This ZZZZ ZZZZ ZZZZ is clever ZZZZ\n";
s/ZZZZ/$words[move]/g;
print ; # prints "This e d c is clever b"
__END__
----------------------
#!/usr/bin/perl -w
@words = ('a'..'e');
@rows = (0,1,2,3,4);
$_ = "This ZZZZ ZZZZ ZZZZ is clever ZZZZ\n";
s/ZZZZ/$words[pop @rows]/g;
print ; # prints "This e e e is clever e"
__END__
That can't be the intended behavior, can it?
--
Joe Schaefer
------------------------------
Date: 28 Nov 2000 15:47:55 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Should { } always indicate a scope?
Message-Id: <m3y9y34vlg.fsf@dhcp11-177.support.tivoli.com>
"John Lin" <johnlin@chttl.com.tw> writes:
> my $x = { 2 => my $a = 1 };
> print $x->{ my $b = 2 };
> print $a,$b;
>
> The $a,$b are still visible outside.
$a and $b are special. See the documentation for strict:
Because of their special use by sort(), the
variables $a and $b are exempted from this check.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 28 Nov 2000 19:42:32 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Should { } always indicate a scope?
Message-Id: <Pine.GSO.4.21.0011281939100.5826-100000@crusoe.crusoe.net>
[posted & mailed]
On Nov 28, Ren Maddox said:
>"John Lin" <johnlin@chttl.com.tw> writes:
>
>> my $x = { 2 => my $a = 1 };
>> print $x->{ my $b = 2 };
>> print $a,$b;
>>
>> The $a,$b are still visible outside.
>
>$a and $b are special. See the documentation for strict:
The {...} used for the subscript are synonymous with the [...] used for
array subscripts:
#!/usr/bin/perl -w
use strict;
my (%hash, @array);
$hash{my $key = 'ten'} = 10;
$array[my $idx = 10] = 'ten';
print "$key => $hash{$key}\n$idx => $array[$idx]\n";
The {...} used for dereferencing a reference (as in @{$aref}) are a right
block, if they don't contain a simple expression.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Wed, 29 Nov 2000 00:48:32 -0000
From: "Martin Long" <martin.long@virgin.net>
Subject: Re: Simple Open file fails in Active Perl 5.6.0 on Windows2000 Advanced Server + IIS 5.0
Message-Id: <UhYU5.20096$ea7.396194@news2-win.server.ntlworld.com>
You are quite right - it does work if I put in the full path although it has
to be in the form:
"d:\\inetpub\\wwwroot\\.." etc. The problem with this approach is this: I
am developing the script with Activeperl on a W2K platform (i.e. my own
server). I have full control over where I put files. Ultimately I want to
upload it to my webhosting service which is Unix based and over which I have
virtually no control over the location of files. So for example, if I have
a path such as "d:\inetpub\wwwroot\webname\webfolder" how would this
correspond to a full path in a Unix system in which I can only "see"
directories subordinate to my domain name i.e. in this case it would be
http://www.webname.com/webfolder.
My other point is that in my initial example there was no path i.e. the file
should have been in the same directory as the executing perl script - I
still don't really understand why I couldn't open it.
Sorry if this sounds dumb but I am new to this stuff.
Martin
"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:Xns8FF97BC8Awyzelliyahoocom@203.39.3.131...
> "Martin Long" <martin.long@virgin.net> wrote in
> <CbjU5.14443$ea7.297716@news2-win.server.ntlworld.com>:
>
> >A very simple perl program fails on the open for input with "No such
> >file or directory" if I run it through the web server (i.e. as a link
> >from a web page) .
>
> <snip>
> >#!d:/perl/bin/perl
>
> no use strict, no -w
>
> >$file="availability.txt";
>
> Try inserting the correct full path to the file here because you are
> probably not where you think you are.
>
> $file = 'd:/inetpub/wwwroot/website/cgi-bin/availability.txt';
>
>
> >open INF,"< $file" or print "Failed $!";
>
> Wyzelli
>
> --
> #beer v2
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
> around');
> for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Wed, 29 Nov 2000 10:43:56 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Simple Open file fails in Active Perl 5.6.0 on Windows2000 Advanced Server + IIS 5.0
Message-Id: <HFYU5.9$wr2.3267@vic.nntp.telstra.net>
"Martin Long" <martin.long@virgin.net> wrote in message
news:UhYU5.20096$ea7.396194@news2-win.server.ntlworld.com...
> You are quite right - it does work if I put in the full path although
it has
> to be in the form:
> "d:\\inetpub\\wwwroot\\.." etc. The problem with this approach is
this: I
ewk. UGLY!
Did you try with 'd:/inetpub/wwwroot/..' etc? It works. Perl does the
right thing with the directory separator. This is particularly
important when a script will be used in multiple environments.
> am developing the script with Activeperl on a W2K platform (i.e. my
own
> server). I have full control over where I put files. Ultimately I
want to
> upload it to my webhosting service which is Unix based and over which
I have
> virtually no control over the location of files. So for example, if I
have
> a path such as "d:\inetpub\wwwroot\webname\webfolder" how would this
> correspond to a full path in a Unix system in which I can only "see"
> directories subordinate to my domain name i.e. in this case it would
be
> http://www.webname.com/webfolder.
You still need to know the full local path on the Unix system, not the
url.
There can be no direct correlation because the different web servers may
well be in different directories when they actually run. (I think the
current working directory for IIS is usually WINNT - could be wrong)
This is one of the areas that needs careful attention in multi platform
work.
One solution is to test the operating system, and then set a path
variable which suits the environment in which the script finds itself.
Check perlvar for details on the $^O variable.
The current version of Perl should tell you on which platform you are
operating.
if ($^O eq 'MSWin32'){
$path = 'd:/inetpub/wwwroot/mysite';
}
else{
$path = '/home/username/www';
}
Then mirror your directory structures from that point (modify to suit
your particular environments).
> My other point is that in my initial example there was no path i.e.
the file
> should have been in the same directory as the executing perl script -
I
> still don't really understand why I couldn't open it.
As stated, you probably aren't where you think you are in the directory
structure, which probably means you have a bad example to work from, or
at least it was making some assumptions about your OS which proved to be
incorrect.
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: 29 Nov 2000 12:32:47 +1100
From: "Kiel Stilring" <taboo@comcen.com.au>
Subject: Re: Skipping lines in a file
Message-Id: <3a245cbf$1@nexus.comcen.com.au>
flint@flintslacker.com (Flint Slacker) wrote:
>>I like using labels myself....
>
>LOOP: while(<INFILE>) {
> chomp;
> next LOOP if(/pattern/); #don't process
> last LOOP if(/^$/); #exit
> push(@lines, $_); #good line
> ......
>}
why not
use strict;
my @lines;
while(<INFILE>) {
chomp;
my $skip = 1 if /pattern/;
push @lines, $_ unless $skip;
}
------------------------------
Date: Wed, 29 Nov 2000 00:06:57 GMT
From: fallenang3l@my-deja.com
Subject: Socket connection through firewall...
Message-Id: <901hat$nda$1@nnrp1.deja.com>
I have made a small MP3 streamer server that I gave to my friend (he's
on highspeed DSL) so that we can listen to MP3's on our school
computers (it's T1 so we can listen to high quality MP3 which he has a
lot of). I also made a client application that I'm gonna plant on one
of the computer stations. All would be great if not for the fact that
my friend is behind a firewall (his brother set it up on his computer)
and he doesn't know how to turn it off (or can't or whatever) and my
client application can't connect. Here's the socket code for the server
(it binds on port 80):
socket SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp');
setsockopt SERVER, SOL_SOCKET, SO_REUSEADDR, 1;
my $my_addr = sockaddr_in $server_port, INADDR_ANY;
bind SERVER, $my_addr
or die "Couldn't bind to port $server_port: $!\n";
listen SERVER, $max_conn || SOMAXCONN
or die "Couldn't listen on port $server_port: $!\n";
and here's the client code:
my $proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto);
print "Looking up $remote_host..\n";
my $sin = sockaddr_in($remote_port, inet_aton($remote_host));
print "Connecting to $remote_host:$remote_port..\n";
connect(SOCK, $sin) || die "Connect failed: $!\n";
The client code fails at connect failed part. What am I doing wrong?
Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 29 Nov 2000 01:00:38 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: system() argument: multiple spaces collapsed into single space
Message-Id: <901kfk$pph$1@nnrp1.deja.com>
In article <3a243940$1@woodstock.int.westgroup.com>,
"Jeffrey R. Olson" <jeff.r.olson@westgroup.com> wrote:
> I'm running ActivePerl 522 on Windows NT 4.0, and am having the
following
> problem with the system() function:
>
> I've created a simple example of the problem I'm having. Say I have a
> script test1.pl:
>
> #---------
> my $infile = "hello world";
> print "\$infile in test1.pl: $infile\n";
> system qq(perl "test2.pl" "$infile");
> #---------
>
> And say test2.pl looks like this:
>
> #---------
> my $infile = shift;
> print "\$infile in test2.pl: $infile\n";
> #---------
>
> Upon running test1.pl, the output is this:
>
> $infile in test1.pl: hello world
> $infile in test2.pl: hello world
>
> Note how the two spaces between "hello" and "world" are collapsed
into a
> single space. In fact, it seems that any number of consecutive
spaces is
> collapsed into a single space.
>
> This problem is causing havoc with a script I have written that
passes file
> names to another script. Does anyone have any ideas why this is
happening?
> Better yet, any ideas on how to get Perl to maintain the original
$infile?
> :-)
>
> Thanks,
>
> Jeff
>
run system with a list as parameter, and it should work fine
system('myprog', 'param1', "'hello world'", 'param3');
Brendon
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 29 Nov 2000 12:22:43 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: Unmatched Single Quote
Message-Id: <3a245a63@nexus.comcen.com.au>
kliquori <kliquori@outsourceint.com> wrote:
>I'm having a problem with an "Unmatched single quote." I have an html text>field in a form that is being submitted to a Perl CGI script which then makes
>an entry into a mySQL database. It works OK - except when entering an
>apostrophe into the text field. Then the script complains about the
>"Unmatched single quote." I've tried various means of quoting around the
>variable but nothing seems to work. On the form I have: Issue: <input
>type="text" name="issuefld"> I grab this field in the CGI script with: $issue
>= $q->param( "issuefld" ); I try to insert it into the db in the same script
>with: $dbh->do( "insert into NetworkOutage (Issue) values ('$issue')") or die
>"Cannot do: " .$dbh->errstr();
>
>Any ideas on how to deal with that ' ??
>TIA . . . Kevin
I think you should use the function quotemeta
ie,
$unsafesqldata = $p->param('issuefld');
my $safesqldata = quotemeta $unsafesqldata;
then pipe $safesqldata in to your db
see perldoc -f quotemeta
or
http://www.perldoc.com/perl5.6/pod/func/quotemeta.html
regards,
Kiel Stirling
------------------------------
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 4984
**************************************