[13561] in Perl-Users-Digest
Perl-Users Digest, Issue: 971 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 2 07:07:10 1999
Date: Sat, 2 Oct 1999 04:05:08 -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: <938862308-v9-i971@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 2 Oct 1999 Volume: 9 Number: 971
Today's topics:
Re: Advice from the Wise <gellyfish@gellyfish.com>
Re: Bye Tom? (WAS: Re: injecting "my" varibales into ca <gellyfish@gellyfish.com>
Email Address Syntax Checking. (Abigail)
Forum richard@softhome.net
Re: Good Perl book <fbe2@ucla.edu>
Re: Perl - SQL examples (Abigail)
Re: Perl IDE for X (Abigail)
Perl <kkkkk>
perlcc compile problem? <jason@romos.net>
Ples Hep Me! adding users to mysql is impossible! (Jeff Greer)
Re: Processing a comma delimited file (Eric Bohlman)
Re: Q: Syntax to open a file in PERL on an NT server <gellyfish@gellyfish.com>
Re: Simple newbie problem... <gellyfish@gellyfish.com>
Re: sort question (Larry Rosler)
Re: Split() on vertical bar | (Abigail)
Re: Trouble w/ Regex in ActivePerl for Win32 <gellyfish@gellyfish.com>
Re: webfetch (Mark A. Hershberger)
Re: What is 'rmdir' REALLY doing? (Alan Curry)
Re: What is 'rmdir' REALLY doing? <michael@shoebox.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Oct 1999 09:10:16 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Advice from the Wise
Message-Id: <7t4i5o$5ef$1@gellyfish.btinternet.com>
On Fri, 1 Oct 1999 17:46:07 -0700 Larry Rosler wrote:
> In article <37F544A3.ABC8BBDD@mail.cor.epa.gov> on Fri, 01 Oct 1999
> 16:32:51 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
> ...
>> After you run ActiveState's install program, you'll be able to
>> read their intro material just by clicking on the entry it drops
>> into your Start Menu. One thing to look for is the perlport 'page'
>> which talks about difference in Perl functionality between OSes.
>
> Oh, thanks for reminding me. He won't find the 'perlport' page listed
> in the table-of-contents frame! Despite my having sent a trouble report
> about this ages ago, ActiveState has yet to fix the problem. I have to
> edit the file by hand every time I upgrade to their latest build.
>
Ooh, I hadnt even noticed that, but then I tend to have a VT open and
just type 'man perlport' there.
This sounds emminently patchable - there is a simple script that puts this
stuff together I think: I will look on monday ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 1 Oct 1999 20:49:33 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope)
Message-Id: <7t36ou$4bh$1@gellyfish.btinternet.com>
On Fri, 01 Oct 1999 12:25:43 +1000 Martin Gleeson wrote:
> In article <37f2ab3b$0$219@nntp1.ba.best.com>, Paul J. Lucas <pjl@fuckoff.com>
> wrote:
>
>> In <slrn7v56b3.3d2.*@dragons.duesouth.net> *@dragons.duesouth.net (Matthew Bafford) writes:
>>
>> >Once upon a time (29 Sep 1999 22:27:59 GMT), Paul J. Lucas"
>> ><pjl@best.com> was attempting to figure out Ilya's new Perl
>> >regex features, and accidently sent the following to
>> >comp.lang.perl.misc:
>> >: In <slrn7uuk78.k8j.*@dragons.duesouth.net> *@dragons.duesouth.net (Matthew Bafford) writes:
>> >: > we'll miss you.
>> >: > [tom]
>> >:
>> >: I won't. How can anybody think he's NOT a major asshole?
>> >: He seems like an angry, bitter little man.
>>
>> >You know, I almost put `most of us will miss you', but, although true,
>> >that isn't exactly as nice a thing to say. Anyway, I figured the
>> >non-most people would have the sense and decency to keep their fingers
>> >away from the keyboard.
>>
>> Since when does Tom deserve decency?
>
> Why don't you tell us, Mr pjl@fuckoff.com?
> You are obviously the authority on the subject.
>
Thats alright he can be emailed at pjl@best.com
[Followups set]
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 2 Oct 1999 05:33:07 -0500
From: abigail@delanet.com (Abigail)
Subject: Email Address Syntax Checking.
Message-Id: <slrn7vboat.1dd.abigail@alexandra.delanet.com>
Here's an updated version, that allows for the appropriate whitespace
at the appropriate places as well. Comments aren't being recognized yet.
Abigail
package RFC::822::Address;
#
# $Id: Address.pm,v 1.2 1999/10/02 10:08:48 abigail Exp abigail $
#
# $Log: Address.pm,v $
# Revision 1.2 1999/10/02 10:08:48 abigail
# Grammar is now aware of the whitespace rules.
# Comment rules still have to be implemented.
# used h2xs.
# Created initial test.pl file.
#
# Revision 1.1 1999/10/01 08:50:13 abigail
# Initial revision
#
#
use strict;
use Exporter;
use Parse::RecDescent;
use vars qw /@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION/;
@ISA = qw /Exporter/;
@EXPORT = qw //;
@EXPORT_OK = qw /valid/;
%EXPORT_TAGS = ();
($VERSION) = '$Revision: 1.2 $' =~ /([\d.]+)/;
my $CRLF = '\x0D\x0A';
$Parse::RecDescent::skip = "((?:$CRLF)?[ \t])*";
local $/;
# Now, pay attention. There are only 2 important lines of Perl in this
# module, and they follow now. ;-)
my $parser = Parse::RecDescent -> new (<DATA>) or die "Compilation error.\n";
sub valid {$parser -> valid (shift)}
# That's it. The rest is just data....
<<'=cut'
=pod
=head1 NAME
RFC::822::Address -- RFC 822 style address validation.
=head1 SYNOPSIS
use RFC::822::Address qw /valid/;
print "Valid\n" if valid 'abigail@delanet.com';
=head1 DESCRIPTION
This module checks strings to see whether they are have the valid
syntax, as defined in RFC 822 [1]. One subroutine, C<valid>, can
be imported, which takes a single string as argument. If the string
is valid according to RFC 822, a true value is returned, else a
false value is returned.
=head1 REFERENCES
=over 4
=item [1]
David H. Crocker (revisor): "STANDARD FOR THE FORMAT OF ARPA INTERNET
TEXT MESSAGES". RFC 822. 13 August 1982.
=back
=head1 CAVEATS and BUGS
This module sets the variable C<$Parse::RecDescent::skip>. This will
all other C<Parse::RecDescent> parsers. And this parser will break if
you set C<$Parse::RecDescent::skip> to another value. It doesn't look
that it is possible to set an alternative skip value for each parser,
other than setting the skip value on each production.
This validator does not accept comments. Yet.
=head1 REVISION HISTORY
$Log: Address.pm,v $
Revision 1.2 1999/10/02 10:08:48 abigail
Grammar is now aware of the whitespace rules.
Comment rules still have to be implemented.
used h2xs.
Created initial test.pl file.
Revision 1.1 1999/10/01 08:50:13 abigail
Initial revision
=head1 AUTHOR
This package was written by Abigail, abigail@delanet.com.
=head1 COPYRIGHT and LICENSE
This package is copyright 1999 by Abigail.
This program is free and open software. You may use, copy, modify,
distribute and sell this program (and any modified variants) in any way
you wish, provided you do not restrict others to do the same.
=cut
__DATA__
HTAB: /\x09/ # ASCII Horizontal tab
LF: /\x0A/ # ASCII Linefeed
CR: /\x0D/ # ASCII Carriage return
SPACE: ' ' # ASCII space
AT: '@' # ASCII AT
LWSP_char: SPACE | HTAB # Semantics = SPACE
CHAR: /[\x00-\x7F]/ # Any ASCII character.
CTL: /[\x00-\x1F\x7F]/ # Any ASCII control character
# and DEL
special: /[]()<>@,;:\\".[]/ # Must be in quoted string
# to be use within word.
CRLF: <skip: ""> CR LF
linear_white_space: # Semantics = SPACE
<skip: ""> # CRLF => folding
(CRLF(?) LWSP_char)(s)
atom: /[^]\x00-\x20 \x7F\x80-\xFF()<>@,;:\\".[]+/
# Any CHAR except specials,
# SPACE and CTLs
dtext: /[^]\\\x0D\x80-\xFF[]/ # Any CHAR, excepting [, ], \,
| linear_white_space # and CR, and including
# linear-white-space =>
# may be folded
qtext: /[^"\\\x0D\x80-\xFF]/ # Any CHAR, excepting ", \,
| linear_white_space # and CR, and including
# linear-white-space =>
# may be folded
quoted_pair: <skip: ""> '\\' CHAR # May quote any char
quoted_string:
<skip: "">
'"' (qtext | quoted_pair)(s?) '"' # Regular qtext or quoted chars
domain_literal:
<skip: "">
'[' (dtext | quoted_pair)(s?) ']'
word: atom
| quoted_string
phrase: word(s) # sequence of words
valid: address /^\Z/ {1}
address: mailbox # one addressee
| group # named list
group: phrase ':' <leftop: mailbox ',' mailbox>(?) ';'
mailbox: addr_spec # simple address
| phrase route_addr # name & addr-spec
route_addr: '<' route(?) addr_spec '>'
route: <leftop: (AT domain) ',' (AT domain)> ':'
# path-relative
addr_spec: local_part '@' domain # global address
local_part: <leftop: word '.' word> # uninterpreted
# case-preserved
domain: <leftop: sub_domain '.' sub_domain>
sub_domain: domain_ref
| domain_literal
domain_ref: atom # symbolic reference
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
use strict;
my $loaded;
BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use RFC::822::Address qw /valid/;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
my @valids = split /\n/ => <<'VALIDS';
abigail@delanet.com
abigail@delanet.com
abigail@delanet.com
abigail @delanet.com
*@qz.to
"\""@foo.bar
fred&barny@stonehedge.com
---@perl.com
foo-bar@yes.no
"127.0.0.1"@[127.0.0.1]
Abigail <abigail@delanet.com>
Abigail<abigail@delanet.com>
Abigail<@a,@b,@c:abigail@delanet.com>
"This is a phrase"<abigail@delanet.com>
"Abigail "<abigail@delanet.com>
"Joe & J. Harvey" <ddd @Org>
Abigail <abigail @ delanet.com>
Abigail made this < abigail @ delanet . com >
VALIDS
push @valids =>
qq {"Joe & J. Harvey"\cM
<ddd@ Org>},
qq {"Joe &\cM
J. Harvey" <ddd @ Org>},
;
my @invalids = split /\n/ => <<'INVALIDS';
fred(&)barny@stonehedge.com
fred\ barny@stonehedge.com
Abigail <abi gail @ delanet.com>
INVALIDS
push @invalids =>
# Invalid, only a LF, no CR.
qq {"Joe & J. Harvey"
<ddd@ Org>},
# Invalid, CR LF not followed by a space.
qq {"Joe &\cM
J. Harvey" <ddd @ Org>},
;
my $c = 1;
foreach my $test (@valids) {
$c ++;
print valid ($test) ? "ok $c\n" : "not ok $c\n";
}
foreach my $test (@invalids) {
$c ++;
print valid ($test) ? "not ok $c\n" : "ok $c\n";
}
__END__
--
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 02 Oct 1999 07:59:09 +0200
From: richard@softhome.net
Subject: Forum
Message-Id: <37F59F2D.6546@softhome.net>
Hi Folks,
I'm looking or a Forum script. The Forum must have the features: The
webmaster/administrator must be in a position to delete unwanted
postings by monitoring. Subjet, Date and time postings are coming in.
etc,etc,
Who has such a Forum for me or who knows a place where I can download a
free one.
Thanks in advance
Richard
------------------------------
Date: Fri, 01 Oct 1999 23:22:36 -0700
From: Beverley Eyre <fbe2@ucla.edu>
Subject: Re: Good Perl book
Message-Id: <37F5A4AC.83283799@ucla.edu>
I'd like to learn more about how to use modules. I'm having real problems with some modules and 'use
strict' and 'use diagnostics'. I don't know how to declare it. Is it like:
Getopt::var1;
or something like that?
Bev
Clyde Ingram wrote:
>
> Even better is the O'Reilly Perl CD which has 6 Perl books, including the
> twoMark quite rightly recommends. Plus Perl Cookbook, Advanced Perl, Perl
> on Win32, and Perl in a Nutshell. They throw in a paper copy of the
> Nutshell book too, with the CD.
>
> A great combination. Easy to browse on hyperlinks across all 6 titles,
> making up for some of the deficiencies in the indexes in the paper versions
> of these books,
>
> Regards,
> Clyde
>
> Me <NOSPAMmark@nl.gxn.net> wrote in message
> news:7ssflm$8ik$1@blue.nl.gxn.net...
> > Learning Perl and Programming Perl
> > by O'reilly Publishers
> >
> > --
> > Mark Spring GX Networks B.V.
> > email: mark@nl.gxn.net Televisieweg 2
> > tel: +31 36 5462400 1322 AC Almere
> > fax: +31 36 5462424 The Netherlands
> >
> > Stephen Cui <yosho@hi.net> wrote in message
> > news:MPG.125b30b5ca50a39c989680@news.hi.net...
> > > Can anyone recommend a great PERL book to start with and get good at? I
> > > got a coupon for barnesandnoble.com that expires on the 30th and would
> > > like to get me a good book..
> > >
> > > Thanks in advance..
> > > Stephen Cui
> > >
> > > yosho@hi.net
> >
> >
--
----------------------------------------------------------------------
Beverley Eyre I grew tired of meekness
fbe2@ucla.edu when I saw it without effect.
http://www.ee.ucla.edu/~eyre Of late therefore I have been saucy...
-- Ben Franklin
------------------------------
Date: 1 Oct 1999 23:34:11 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl - SQL examples
Message-Id: <slrn7vb3a0.1dd.abigail@alexandra.delanet.com>
Michael Peppler (mpeppler@peppler.org) wrote on MMCCXXI September
MCMXCIII in <URL:news:37F36F62.BE033730@peppler.org>:
||
|| Correct. DBI/DBD is definitely the way to go if you need portability to
|| other database engines.
||
|| If not - well I just wanted to correct any misconception that sybperl was
|| old/antique code.
I've always used sybperl to great satisfaction myself. When I started
using it, sybperl was mature, and DBI::Sybase either very young, or
non-existing yet.
sybperl works very well, and because it's just glue to the Sybase libraries,
you can use the Sybase documentation. ;-)
And since what I used to do was very Sybase specific anyway, there was
never any reason to even look at DBI/DBD.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 1 Oct 1999 23:40:35 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl IDE for X
Message-Id: <slrn7vb3m0.1dd.abigail@alexandra.delanet.com>
Kent Perrier (kperrier@blkbox.com) wrote on MMCCXX September MCMXCIII in
<URL:news:DC0C3C5D09731199.97CE5C76D0B2DE71.90FEF9633D125C75@lp.airnews.net>:
'' Francisco Romero <fromero@csudh.edu> writes:
''
'' > Does anyone know if there is an Integrated Developmental Enviornment for
'' > perl?
''
'' Sure. have two xterms open. In one, have a vi session going with your
'' code in it. in the other, run your script.
What do you mean *two* xterms? I just hit ALT-R in my vi-clone, and it
runs the program in the buffer. Or ALT-P to have it compile.
Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 2 Oct 1999 13:52:16 +0400
From: "ii" <kkkkk>
Subject: Perl
Message-Id: <7t4ktn$8mq@harpy.skfgvc.pyatigorsk.su>
Народ, помогите.
Я тут недавно начал писать на Perl и очень мне это язык понравился.
Но так как приходится работать под NT (а что делать, нормальная операционка
(в офисе)), то использую очень,по-моему, гарный редактор MultiEdit. Нород
просьба если кто знает где взять дополнительные макросы или шаблоны к
MultiEdit для Perl налейте URL или намыльте на адрес aleksei@boka.cmw.ru
------------------------------
Date: Sat, 02 Oct 1999 08:17:44 GMT
From: Jason Romo <jason@romos.net>
Subject: perlcc compile problem?
Message-Id: <37F5C26F.34CE38BC@romos.net>
This is a multi-part message in MIME format.
--------------33B7C904CCFFBB0EFD2D848F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I am trying to compile the DBI.pm DBD.pm and Socket.pm.
perlcc *.pm
I test them with the perl script.
I use the
require 'module.so';
it fails with
Unrecognized character \177 at /usr/lib/perl5/5.00503/i386-linux/Socket.so
line 1.
Any clues?
I have tried this by doing a static perl and dynamic perl.
Nothing has worked.
I am using: 5.005_03 on Redhat 6.0.
--------------33B7C904CCFFBB0EFD2D848F
Content-Type: text/x-vcard; charset=us-ascii;
name="jason.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jason Romo
Content-Disposition: attachment;
filename="jason.vcf"
begin:vcard
n:Romo;Jason
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:jason@romos.net
note;quoted-printable:############################################################=0D=0A split // =3D> '"'=3B=0D=0A${"@_"} =3D "/"=3B split // =3D> eval join "+" =3D> 1 .. 7=3B=0D=0A*{"@_"} =3D sub {foreach (sort keys %_) {print "$_ $_{$_} "}}=3B=0D=0A%{"@_"} =3D %_ =3D (Just =3D> another =3D> Perl =3D> Hacker)=3B &{%{%_}}=3B
x-mozilla-cpt:;0
fn:Jason Romo
end:vcard
--------------33B7C904CCFFBB0EFD2D848F--
------------------------------
Date: Sat, 02 Oct 1999 08:55:26 GMT
From: jgreer@showmethenet.com (Jeff Greer)
Subject: Ples Hep Me! adding users to mysql is impossible!
Message-Id: <37f5c4f5.39779437@news-server.kc.rr.com>
I thought making perl connect to mysql through DBI was hard to set up, but that
is nothing compared to adding a new user to mysql. I set up Apache, DBI, Perl,
and DBD::mysql. I can send and retrieve values to my database from web pages
that call perl scripts, but I can't add a new user to mysql. I can only access
the database as root.
Can anybody please explain the steps in adding a new user to mysql. I'll never
figure this out from the manual. In all respects I think the mysql manual is
pretty good except in the area of users and access privileges.
I've tried everything I could that was listed in the mysql official manual to
create user: test with pw: test** but I cannot do it. I keep getting this
error:
/root > mysql -h localhost -u test -ptest**
ERROR 1045: Access denied for user: 'test@localhost' (Using password: YES)
thanks
--
Jeff Greer
B.S. computer science, University of MO - Rolla
--------------------------------------------------
Windows NT has crashed,
I am the Blue Screen of Death,
No one hears your screams...
If you don't have anything mean to say about
Microsoft, don't say anything at all.
------------------------------
Date: 2 Oct 1999 06:46:40 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Processing a comma delimited file
Message-Id: <7t49og$el6@dfw-ixnews19.ix.netcom.com>
Jeff Gordon (jeff@gordon-net.comXnoSpam) wrote:
: # =======================
: # Get the header record
: $line = <DB>;
: @vars = parse_csv (lc($line));
: $vars = "\$" . join ", \$", @vars;
:
: # =======================
: while (<DB>) {
: $line = $_;
: ($index, $last_name, $first_name, $company, $website) =
: parse_csv($line);
: ### do stuff with each variable here ####
: }
:
: # =======================
: sub parse_csv {
: return quotewords(",",0,$_[0]);
: }
:
: ========================================================
: I'm processing the data just fine, but my problem is that I'd like to
: generalize this a bit, so that the variable names (ie $index, $last_name,
: $first_name, $company, $website) don't need hard-coded in the program but
: rather get created from the first data record. That's the purpose of those
: lines that deal with $vars and @vars. I feel like I'm getting close with
: those lines, but I'm really not sure and I haven't a clue what to do next
: with it. Can someone help me out here (and please be gentle).
To do what you're actually asking for would require using symbolic
references, which is a Bad Thing; if, say, you ran across a file that,
either maliciously or accidentally, had a field titled "/" then each
attempt to read a data record would change $/, which is the input record
separator, leading to extremely crazy behavior! On a more mundane level,
you wouldn't be able to cope with fields whose titles weren't legal Perl
variable names (such as titles that contained spaces).
What you really want to do is use a hash keyed by the field titles. You
can set it up very easily by using hash slices:
while (<DB>) {
my @fields{@vars} = parse_csv($_);
### do stuff with each variable here ####
}
Now you can refer to $fields{index}, $fields{last_name}, etc. You could
even refer to $fields{'last name'} if that were how one of the fields was
titled.
------------------------------
Date: 2 Oct 1999 10:12:38 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Q: Syntax to open a file in PERL on an NT server
Message-Id: <7t4lqm$5lb$1@gellyfish.btinternet.com>
On Fri, 01 Oct 1999 16:02:09 -0700 David Cassell wrote:
> gremlin wrote:
>>
>> With regard to "relative paths". If an NT "Share" was made, would THAT
>> be relative (as I read 'D:\yaddah\yaddah\yaddah...' was)?
>
> What you have written above is an absolute path. An NT share
> can also be an absolute path. A relative path is one which
> assumes knowledge of the location of the current directory or
> its parent(s), for example, ../yadda/myimage.jpg
>
If this is running from an HTTP server of course then the shares may not
have drive letters mapped - so assuming that the process has the correct
permissions to access the network shares then one can use the UNC path :
open(BLAH,"\\\\machine\\share\\path\\to\\some\\file" ) || die " .... ";
I have put the (rather lame admittedly) escaped backslashes as I am
not in a position to check whether the more usual way works for UNC paths.
Alternatively it is possible to use the Win32::NetResource module to
add a drive mapping to a share for ones process ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 2 Oct 1999 09:44:15 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Simple newbie problem...
Message-Id: <7t4k5f$5h5$1@gellyfish.btinternet.com>
On Fri, 01 Oct 1999 23:39:42 GMT jon@osfn.org wrote:
> Hi,
>
> I need to replace one string with an other in multiple .html documents
> I've gotten this far
>
> #!/usr/bin/perl
>
You probably want to use the -w switch to warn about typos etc ..
> @files = `ls`;
>
I am certain that your files dont have newlines on the end ...
chomp(@files = `ls`);
> foreach $file (@files) {
> if ($file =~ /.html/ {
>
I would suggest that that regex might get something you dont want like
'beshmtleewoo' - you want to anchor the pattern to the end of the
string and escape the '.' :
$file =~ /\.html$/
> how do I now edit these files (I want the changed file to have the
> original name??
>
> open CURRENT, $files;
You should always check the success of a file open before you use the
filehandle -
open CURRENT, $file or die "cannot open $file - $!\n";
> while (<CURRENT>) {
> s/x/y/I; #??????????????
>
I'm not quite sure what you are saying here - you want to perform some
unspecified alteration to the file in place ? You can either use the
-i switch which allows the (<>) operator to edit a file in place and
when used with the -p switch can create a one-liner:
perl -pi -e's/x/y/i;' *.html
would be the equivalent of what you appear to be doing here. You can put
this in a file such as :
#!/usr/bin/perl -wi
while(<>)
{
s/x/y/i;
}
and run it as :
myprog *.html
Alternatively you will need to open a temporary file to write to and then
delete the original and rename the temp file to the original - your
example again:
#!/usr/bin/perl -w
chomp(@files = `ls`);
foreach $file (@files)
{
if ( $file =~ /\.html$/ )
{
open(CURRENT,$file) || die "Cant open $file - $!\n";
open(OUT,">/tmp/$$" ) || die "Cant open temp file - $!\n";
while(<CURRENT>)
{
s/x/y/i;
print OUT;
}
close CURRENT;
close OUT;
unlink ($file) || die "Couldnt unlink $file - $!\n";
rename ( "/tmp/$$",$file) || die "Couldnt rename - $!\n";
}
}
Read the perlrun manpage for more on the -i switch and perlfaq5 for
stuff on altering files (of course you did this before but just missed it
right :)
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 2 Oct 1999 00:24:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: sort question
Message-Id: <MPG.125f530b3f3acafe98a028@nntp.hpl.hp.com>
In article <RqdJ3.4417$a9.82676@sandstorm> on Fri, 1 Oct 1999 21:41:39 -
0400, cy <cy@neo.rr.com> says...
> I have a list with 10 columns. I'm sorting the list first based on column
> [0] , and then based on the division of the [4] by the [4] + [5] column.
> Sometimes the fields that I'm dividing are 0 so I get an "Illegal division
> by 0". How would I make it sorts my list, but not divide the ones that are
> 0? I don't think you can put an if statement within the sort function...
You can put whatever you want within the sort subroutine. But the goal
-- to achieve good performance -- is to put as little as possible, even
nothing!
> Here is my current sort statement that works as long as field in column 4 +
> field in column 5 does not equal 0:
>
> @L = sort {
> ( split('~', $b) )[0]
> <=>
> ( split('~', $a) )[0]
> ||
> ( (split('~', $b) )[4] / ( (split('~', $b) )[4] + ( split('~',
> $b) )[5] ) )
> <=>
> ( (split('~', $a) )[4] / ( (split('~', $a) )[4] + ( split('~',
> $a) )[5] ) )
> } @L;
>
> It's kinda messy, and I'm a rather new perl coder as I'm sure it shows
> through. Thanks to anyone who can help me!
Well, you know enough to extract a single-element list slice from the
result of a split, but not how to get a set of elements. 'slice()' is
expensive, so we don't want to do it four times for each operand.
@L = sort {
my ($a0, $a4, $a5) = (split /~/ => $a)[0, 4, 5];
my ($b0, $b4, $b5) = (split /~/ => $b)[0, 4, 5];
$b0 <=> $a0 || $b4/($b4 + $b5) <=> $a4/($a4 + $a5)
} @L;
Now, you haven't said what you want to do if either of those
denominators is 0 (except not to do the division, which is a good idea).
So I'll assume you don't care about the sort order in those cases.
@L = sort {
my ($a0, $a4, $a5) = (split /~/ => $a)[0, 4, 5];
my ($b0, $b4, $b5) = (split /~/ => $b)[0, 4, 5];
$b0 <=> $a0 ||
($b4 + $b5) && ($a4 + $a5) &&
$b4/($b4 + $b5) <=> $a4/($a4 + $a5)
} @L;
At this point, we have a workable sort function. The remaining problem
is performance. Each of those expensive splits is being done over and
over, for each of each pair of elements being compared. The solution is
to do the processing once per element, save the results, and retrive
them when needed.
There are several ways to do this. Here is a method called the Schwartz
Transform. Not only will it save the results of the split; it will also
make the decisions about the faulty divisions.
@L = map $_->[0] =>
sort { $b->[1] <=> $a->[1] || $b[2] <=> $a[2] }
map {
my ($a0, $a4, $a5) = (split /~/)[0, 4, 5];
[ $_, $a0, $a4/(($a4 + $a5) || 1) ]
} @L;
Note how little computation now takes place in the sort subroutine.
None of this has been tested, and some of it may be much for you to
swallow in one piece. But there are many places to learn more about it.
Start with perlfaq4: "How do I sort an array by (anything)?"
The definitive discussion (ahem) is at:
http://www.hpl.hp.com/personal/Larry_Rosler/sort/
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 2 Oct 1999 03:58:02 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Split() on vertical bar |
Message-Id: <slrn7vbioo.1dd.abigail@alexandra.delanet.com>
Bill Feduska (feduskabm@msx.upmc.edu) wrote on MMCCXX September MCMXCIII
in <URL:news:37F2638B.A9826D7A@msx.upmc.edu>:
.. Any ideas on how to split() a line on a vertical bar (hash mark) | ?
.. Thanks.
sub split_on_vertical_bar {
die "The plane! The plane!" unless @_;
my $str = shift;
my @chunks = ();
while (-1 < index $str => '|') {
push @chunks => substr $str => 0, index ($str => '|') => '';
substr $str => 0, 1 => '';
}
@chunks => $str;
}
HTH. HAND.
Abigail
--
perl -wlne '}print$.;{' file # Count the number of lines.
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 2 Oct 1999 10:06:28 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Trouble w/ Regex in ActivePerl for Win32
Message-Id: <7t4lf4$5l8$1@gellyfish.btinternet.com>
On Fri, 01 Oct 1999 16:49:51 -0700 Andrew Park wrote:
< fixed upside down quoting>
> David Cassell wrote:
>>
>> Andrew Park wrote:
>> >
>> > Hi, I have a text file created on a Wintel PC w/ CR & LF embedded in
>> > them. I would like to strip out the CR and leave the LF to turn this
>> > into a Unix text file. Using ActivePerl build 519, I've tries all of the
>> [snip]
>> > In every case, either the lines get concatenated into one long line or
>> > the carriage return remains. What am I doing wrong? After every change,
>> > I am copying the file to an NFS mounted machine and running VI from w/i
>> > the Unix Shell to see if the ^M were still there...
>>
>> You already received one suggestion. Let me make a non-Perl
>> one. Either use ftp to transfer the file so that the newlines
>> are handled correctly in transit, or else copy the file to
>> the unix box and use a program like dos2unix to make the
>> changes for you.
>>
>> For extra credit, you could even use the Perl module Net::FTP
>> to copy the file via ftp and do any other manipulations you want.
>>
>
> Actually, I already copy the file to a Unix machine using an NFS mount
> and then run dos2unix on it. However, this text file is generated from a
> Visual Basic program w/ CRLF's in it and I want to automate the process
> of having it converted to Unix format. Believe it or not, I intend to
> call the Perl code from the VB code and have the final output Unix
> ready.
>
> Unfortunately, for the life of me, I can't find any way to get VB to
> output LF's only instead of CRLF...
>
You could of course use dos2unix (or duconv or nlcnvt whatever) from
within your Perl program using system - I am absolutely certain there
is a DOS port of it ...
Alternatively you might try this substitution:
s/\cM//;
Or
s/\x0D//;
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 01 Oct 1999 23:11:40 -0500
From: mah@everybody.org (Mark A. Hershberger)
Subject: Re: webfetch
Message-Id: <49r9jes8oz.fsf@playpen.baileylink.net>
skorpion84@my-deja.com writes:
> I'm looking for a perl script that gets news headline from multiple
> websites and organizes those news headline into a page and place it on
> another website. The script I'm looking for is the one that
> www.newsnow.co.uk and www.linuxtoday.com uses.
Not sure what they use, but you might check out Daily Update
(http://www.newsclipper.com)
Also, Userland software agregates RSS files from around the net at
http://my.userland.com/ You could use XML::RSS to parse those.
Hope that helps,
Mark.
------------------------------
Date: Sat, 02 Oct 1999 06:55:07 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: What is 'rmdir' REALLY doing?
Message-Id: <f%hJ3.7718$t%3.639815@typ11.nn.bcandid.com>
In article <7t3omb$tu4$1@nnrp1.deja.com>, <kevinh25@my-deja.com> wrote:
>I would like to know what 'rmdir' is REALLY doing.
> Is it doing a system call to 'rm -r $dir' or
>does it traverse the directory for the files,
>unlink them all and them delete the directory or
>something totally different.
The perl rmdir function, just like the C rmdir function and the rmdir
command, is not recursive.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 01 Oct 1999 23:32:38 -0800
From: Michael Fowler <michael@shoebox.net>
Subject: Re: What is 'rmdir' REALLY doing?
Message-Id: <874sga5iax.fsf@beowulf.one.eth>
kevinh25@my-deja.com writes:
> I would like to know what 'rmdir' is REALLY doing.
> Is it doing a system call to 'rm -r $dir' or
> does it traverse the directory for the files,
> unlink them all and them delete the directory or
> something totally different.
None of the above. rmdir, on Unix systems (I suspect it acts the same
in Windows, Mac, Amiga, what-have-you, for portability's sake, but I'm
not sure) calls the rmdir(2) library call. This same call is made by
the rmdir(1) program. The library call only deletes a directory if
it's empty. There is no recursion done.
If you want to delete recursively, use File::Find, unlink, and rmdir
as appropriate.
Michael
--
There isn't a mome rath alive that can outgrabe me.
--
------------------------------
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 971
*************************************