[17489] in Perl-Users-Digest
Perl-Users Digest, Issue: 4909 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 17 03:05:37 2000
Date: Fri, 17 Nov 2000 00:05:14 -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: <974448313-v9-i4909@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 17 Nov 2000 Volume: 9 Number: 4909
Today's topics:
Advanced Web Design Books For Sale (David)
Re: Advanced Web Design Books For Sale (Gwyn Judd)
Re: Apache denies to start a Perl CGI <johngros@Spam.bigpond.net.au>
Beginners blues. <johngros@Spam.bigpond.net.au>
Re: Beginners blues. (Gwyn Judd)
Re: Beginners blues. <johngros@Spam.bigpond.net.au>
Re: Beginners blues. <johngros@Spam.bigpond.net.au>
Re: Capital Letters Won't Sort - HeLp! (Gwyn Judd)
Re: Date <bart.lateur@skynet.be>
Re: disk free (IGuthrie)
Re: Extracting data from a string (Tad McClellan)
How to access hash in the stored order? <vidulats@yahoo.co.uk>
Re: How to access hash in the stored order? <kstep@pepsdesign.com>
Re: IP geography (Ilya Zakharevich)
Re: IP geography (Chris Fedde)
Re: IP geography (Tony L. Svanstrom)
Re: Mail <smart73_NOSPAM!!_@earthlink.net>
Re: Mail (Gwyn Judd)
Newbie Perl Question <dcfor3@hotmail.com>
Re: Newbie Perl Question (Chris Fedde)
Re: Newbie Perl Question <jeffp@crusoe.net>
Re: Newbie Perl Question (Martien Verbruggen)
Re: Newbie Perl Question <atong@operamail.com>
Re: Newbie Rename() Function (Gwyn Judd)
Re: No idea about perl, Long post, short question (Tad McClellan)
Re: No idea about perl, Long post, short question (Tad McClellan)
Re: No idea about perl, Long post, short question <siwatkins@iee.org>
Re: perl readdir() question... <ztc@bigfoot.com>
Re: PERL/shell: batch renaming of files (Tad McClellan)
Re: please help!!! pos() and m//g bugs!!! <jeffp@crusoe.net>
Re: Regex to zero pad an IP address (Tad McClellan)
Re: Searching files (Tad McClellan)
Re: Why are references useful? (Chris Fedde)
XML-Parser compile problems (Chris Fedde)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Nov 2000 06:11:11 GMT
From: david_xia@yahoo.com (David)
Subject: Advanced Web Design Books For Sale
Message-Id: <8FEEEE214qx11cornelledu@132.236.56.8>
Advanced Web Design Books For Sale
All books are Brand New.
"HTML 4 for the World Wide Web Visual Quickstart Guide"
by Elizabeth Castro
Paperback - 384 pages 4th edition (January 15, 2000)
Peachpit Press; ISBN: 0201354934
Asking $12
"Platinum Edition Using HTML 4, XML, and Java 1.2"
by Eric Ladd, Jim O'Donnell
Hardcover - 1282 pages Bk&Cd Rom edition (December 1, 1998)
MacMillan Publishing Company; ISBN: 078971759X
Asking $40
"JavaScript Bible"
by Danny Goodman, Brendan Eich
Paperback - 1015 pages 3rd Edition edition (March 1998)
IDG Books Worldwide; ISBN: 0764531883
Asking $30
"Flash 4 Magic" with CD
by David J. Emberton, J. Scott Hamlin, David Emberton
Textbook Binding - 325 pages Bk&Cd Rom edition (January 2000)
New Riders Publishing; ISBN: 0735709491
Asking $30
"Flash 4 Creative Web Animation" with CD
by Derek Franklin, Brooks Patton
Paperback - 352 pages 1st edition (January 15, 2000)
Peachpit Press; ISBN: 0201354705
Asking $25
"Visual InterDev 6 Unleashed"
by Paul Thurrott, Paul Thurrott et al., Brad Jones
Paperback - 1090 pages Bk&Cd Rom edition (April 23, 1999)
Sams; ISBN: 067231262X
Asking $30
"Programming Web Components" with CD
by Reaz Hoque, Tarun Sharma
Paperback - 810 pages Bk&Cd Rom edition
McGraw Hill; ISBN: 0079123163
Asking $40
"Dynamic Html : The Definitive Reference"
by Danny Goodman
Paperback - 1073 pages (August 1998)
O'Reilly & Associates; ISBN: 1565924940
Asking $30
"Dynamic Html in Action" with CD
by Eric M. Schurman, William J. Pardi
Paperback - 497 pages 2nd Bk&cdr edition (March 1999)
Microsoft Press; ISBN: 0735605637
Asking $22
"Professional Active Server Pages 3.0"
by Alex Homer, David Sussman, Brian Francis, George Reilly, Esposito,
Dino Esposito, Andrea Chiarelli, Bill Kropog, Craig McQueen,
Godfrey Nolan, Simon Robinson, John Schenken, Kent Tegel
Paperback - 1277 pages 3rd edition (September 1999)
Wrox Press Inc; ISBN: 1861002610
Asking $40
"ASP/MTS/ADSI Web Security" with CD
by Richard Harrison
Paperback - 450 pages 1 edition (March 11, 1999)
Prentice Hall; ISBN: 0130844659
Asking $35
"Developing Asp Components"
by Shelley Powers
Paperback - 490 pages 1st edition (July 15, 1999)
O'Reilly & Associates; ISBN: 1565924460
Asking $20
"ASP in a Nutshell: A Desktop Quick Reference"
by A. Keyton Weissinger
Paperback; O'Reilly & Associates
Asking $10
"ADO 2.1 Programmer's Reference"
by David Sussman, Alex Homer
Mass Market Paperback - 607 pages 2 edition (June 1999)
Wrox Press Inc; ISBN: 1861002688
Asking $15
"Professional ADO 2.5 RDS Programming with ASP 3.0"
by John Papa
Mass Market Paperback - 819 pages 2nd edition (February 2000)
Wrox Press Inc; ISBN: 1861003242
Asking $30
"XML Bible" with CD
by Elliotte Rusty Harold
Paperback - 1015 pages Bk&Cd Rom edition (July 1999)
IDG Books Worldwide; ISBN: 0764532367
Asking $30
"Building Professional Web Sites with the Right Tools: Build It With Visual
Studio 6, FrontPage, Active Server Pages, VBScript, JavaScript, ADO, Paint
Shop Pro, and Image Composer"
by Jeff Greenberg, J. R. Lakeland
Paperback - 576 pages 1 edition (August 10, 1999)
Prentice Hall; ISBN: 0130843172
Asking $30
"Administering IIS4"
by Mitch Tulloch
Paperback - 608 pages (May 29, 1998)
Computing McGraw-Hill; ISBN: 0070655367
Asking $25
"Learning Vbscript" with CD
by Paul Lomax, Ronald Petrusha (Editor)
Paperback - 640 pages Bk&Cd-Rom edition (October 1997)
O'Reilly & Associates; ISBN: 1565922476
Asking $25
"Learning Perl"
by Randal L. Schwartz, Tom Christiansen, Larry Wall (Foreword)
Paperback - 302 pages 2nd edition (July 1997)
O'Reilly & Associates; ISBN: 1565922840
Asking $15
"Programming Perl"
by Larry Wall, Tom Christiansen, Randal L. Schwartz, Stephen Potter
Paperback - 645 pages 2nd edition (October 1996)
O'Reilly & Associates; ISBN: 1565921496
Asking $25
"Perl Cookbook"
by Tom Christiansen, Nathan Torkington, Larry Wall
Paperback - 794 pages 1 Ed edition (August 1998)
O'Reilly & Associates; ISBN: 1565922433
Asking $25
"Object Oriented Perl"
by Damian Conway, Randal L. Schwartz (Foreword)
Paperback - 490 pages (August 1999)
Manning Publications Company; ISBN: 1884777791
Asking $30
"Programming the Perl DBI"
by Alligator Descartes, Tim Bunce
Paperback - 346 pages (February 2000)
O'Reilly & Associates; ISBN: 1565926994
Asking $25
------------------------------
Date: Fri, 17 Nov 2000 06:23:01 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Advanced Web Design Books For Sale
Message-Id: <slrn919jm2.7vo.tjla@thislove.dyndns.org>
I was shocked! How could David <david_xia@yahoo.com>
say such a terrible thing:
>Advanced Web Design Books For Sale
>All books are Brand New.
Hawking your overpriced "as new" books again? At least you put them all
in one post this time. This newsgroup does not have "forsale" in the
title. Doesn't cornell have a noticeboard or something?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It has long been known that one horse can run faster than another --
but which one? Differences are crucial.
-- Lazarus Long
------------------------------
Date: Fri, 17 Nov 2000 05:08:13 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Apache denies to start a Perl CGI
Message-Id: <133R5.10639$tU2.89024@news-server.bigpond.net.au>
I agree it is an Apache problem you do have to authorise any directory to
exec cgi if it is not a sub directory of your cgi-bin.
Plus you have to have a script handler and assign the .pl extension to perl
but I guess you have your cgi-bin running perl scripts already so only
authorising the new directory to use cgi will be neccesary.
------------------------------
Date: Fri, 17 Nov 2000 05:03:57 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Beginners blues.
Message-Id: <1%2R5.10636$tU2.88922@news-server.bigpond.net.au>
I wrote a script to save a password in a file named with the email address
of a user. It does not save the pass or even create the file. Could someone
tell me what is wrong with it? I include a hard coded version that does not
work either.
$pwd=$time;
if (open(ftpdat,">C:/Progra~1/G6
FTP~1/ftpdat~1/johngros@bigpond.net.au.txt"))
{
# just to let me see it has worked
Print "OK";
$l=<stdin>;
}else{
# just to let me know it has failed
Print"Not OK";
$l=<stdin>;
print ftpdat $pwd;
close ftpdat
------------------------------
Date: Fri, 17 Nov 2000 06:33:46 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Beginners blues.
Message-Id: <slrn919ka7.7vo.tjla@thislove.dyndns.org>
I was shocked! How could John Boy Walton <johngros@Spam.bigpond.net.au>
say such a terrible thing:
>I wrote a script to save a password in a file named with the email address
>of a user. It does not save the pass or even create the file. Could someone
>tell me what is wrong with it? I include a hard coded version that does not
>work either.
Did you type that script in by hand or did you cut and paste it? because
as written it does not compile so that would explain why the file
doesn't get created. Two things to note:
Perl is case sensitive. That means "print" and "Print" are not the same
thing.
You need to make sure every (more or less) statement ends in a
semicolon.
You need to match the braces and brackets eg. if there is a '{' there
needs to be a '}' somewhere.
In a double-quoted string "@" is special so you need to escape it with a
'\'.
I suggest that you install Perl on your own machine because it seems
like what you are trying to do is debug it via your webbrowser which is
apsolutely hopeless.
Then once you have done that, this:
open '>C:/some/file/name.txt' or die "Cannot open file: $!";
is better than this:
if (open '>C:/some/file/name.txt')
{
# do something
}
else
{
# do something else
}
Also the first two lines of your script should always be:
#!/usr/bin/perl -w
use strict;
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Standing on head makes smile of frown, but rest of face also upside down.
------------------------------
Date: Fri, 17 Nov 2000 07:25:02 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Beginners blues.
Message-Id: <i35R5.10811$tU2.90017@news-server.bigpond.net.au>
Thanks Gwyn Judd,
I do have perl on my machine.
I am trying to get a website with a logon going.
I think the "escaping" the @ is the solution. And I thank you for it I was
developing a bald spot.
------------------------------
Date: Fri, 17 Nov 2000 07:51:36 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Beginners blues.
Message-Id: <cs5R5.10855$tU2.90173@news-server.bigpond.net.au>
Right almost fixed.
#!E:/Millenium Programs/perl/bin/Perl
$pwd=$time;
open(ftpdat,'>C:/Program Files/G6 FTP
Server/ftpdatabase/johngros\@bigpond.net.au.txt');
print ftpdat $pwd;
close ftpdat;
Technically it should work but the file is not there.
Should it be "open(ftpdat,'+>>C:/Program Files/G6 FTP
Server/ftpdatabase/johngros\@bigpond.net.au.txt');"?
------------------------------
Date: Fri, 17 Nov 2000 02:32:13 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <slrn91965b.4ut.tjla@thislove.dyndns.org>
I was shocked! How could fhinchey@my-deja.com <fhinchey@my-deja.com>
say such a terrible thing:
>Not to be masterbatory, but I ALMOST found the answer to my question...
>
>@sorted = sort{$a<=>$b}(@list);
>
>I thought this would do it, but it still doesn't work correctly, it
>works for the first ten then get all nutty again. Plus, only the first
>letter of the capitalized words sorts correctly, the second letter is
>still not correctly alphabetized. Maybe I'm just too anal for Perl?
I take it you aren't running with warnings on then? '<=>' only works
with numeric arguments. You want to use 'cmp':
@sorted = sort { lc $a cmp lc $b } @list;
'lc' lowercases the arguments before you compare them so everything
should then sort as you want.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Discovery consists in seeing what everyone else has seen and thinking
what no one else has thought. --
Albert Szent-Gyorgi
------------------------------
Date: Fri, 17 Nov 2000 07:53:42 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Date
Message-Id: <qvo91tsak6ggsnfgrqfpmipkkg8e6he201@4ax.com>
Wyzelli wrote:
>$today = sprintf
>"%02d/%02d/%4d",(localtime)[3],(localtime)[4]+1,(localtime)[5]+1900;
>
># Note my use of European Date format and 4 digit year - just to be
>different
Not just that. In Europe, we have the habit of putting the day first,
month second.
--
Bart.
------------------------------
Date: 17 Nov 2000 06:58:53 GMT
From: iguthrie@aol.com (IGuthrie)
Subject: Re: disk free
Message-Id: <20001117015853.21989.00000063@ng-fj1.aol.com>
>2) use FileSys::Df;
>FileSys::Df::df( ... );
>
>This seems to work well on local filesystems and avoids the headaches
>caused by require. The problem is that it does not work with NFS.
Could you be more specific when you say that it does not work with NFS? I use
it with NFS all the time on HP and Sun systems without a problem.
Thanks,
Ian
------------------------------
Date: Thu, 16 Nov 2000 23:54:55 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Extracting data from a string
Message-Id: <slrn919i1f.14v.tadmc@maxim.metronet.com>
On Thu, 16 Nov 2000 17:17:58 +0100, Josef Moellers
<josef.moellers@fujitsu-siemens.com> wrote:
> $line =~ s/.*<title>(.*)<\/title>.*/\1/i;
Please do not post code that generates warnings.
Someone might use it.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 17 Nov 2000 05:30:06 -0000
From: <vidulats@yahoo.co.uk>
Subject: How to access hash in the stored order?
Message-Id: <t19giu62390k0e@corp.supernews.com>
Hello,
I stored some elements in hash like:
%subscripts = (
'bmp', 'Bitmap',
"cpp", "C++ Source",
"txt", 'Text file' );
The one way of printing hash is raw dump: print %subscripts;
The another way is through foreach loop:
foreach $key (keys (%subscripts)) {
$value = $subscripts{$key};
print "Key = $key, Value = $value \n";
}
Or by using sort:
foreach $key (sort keys (%subscripts)) {
$value = $subscripts{$key};
print "Key = $key, Value = $value \n";
}
Or by using each:
while (($key,$value) = each(%subscripts)) {
print "Key = $key, Value = $value \n";
}
If we look at the output, then the order in which the elements are stored
in hash and the order in which it prints the hash is totally different.
Is there any way, by which I can access the elements in the same order, in
which they are stored in hash?
Is there any thumb rule, why hash prints the elements in some different
order?
Thanks in advance,
Regards,
Vidula
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Fri, 17 Nov 2000 02:25:36 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: How to access hash in the stored order?
Message-Id: <8v2mhp$pv8$1@slb2.atl.mindspring.net>
<vidulats@yahoo.co.uk> wrote in message
news:t19giu62390k0e@corp.supernews.com...
> Hello,
>
> I stored some elements in hash like:
>
> %subscripts = (
> 'bmp', 'Bitmap',
> "cpp", "C++ Source",
> "txt", 'Text file' );
>
>
> If we look at the output, then the order in which the elements are stored
> in hash and the order in which it prints the hash is totally different.
>
> Is there any way, by which I can access the elements in the same order, in
> which they are stored in hash?
>
> Is there any thumb rule, why hash prints the elements in some different
> order?
>
> Thanks in advance,
>
> Regards,
> Vidula
When you assign key/value pairs to a hash, perl mangles (hashes) the keys
into pseudo-random numbers. When you access a value by its associated key,
perl re-computes this value and searches only a small subset of the list,
providing much faster access than if you were to perform a string comparison
with each key. Unfortunately, this means that the keys are stored in an
order determined by the hashing algorithm rather than the order in which
they were added to the hash.
There are several ways to get around this. From the looks of your code
(populating a file open/save as dialog, perhaps?), the easiest thing would
be to store the keys in a separate array:
use strict;
use warnings;
my @keys = qw(bmp cpp txt);
my %subscripts = (
bmp => 'Bitmap',
cpp => 'C++ Source',
txt => 'Text file' );
print "$_: $subscripts{$_}\n" foreach (@keys);
Another option would be to use a tied class such as Tie::IxHash. This class
ties a magical replacement to your hash variable that preserves the order of
the keys while otherwise behaving like an ordinary hash.
use strict;
use warnings;
use Tie::IxHash;
my %subscripts;
tie(%subscripts, 'Tie::IxHash',
bmp => 'Bitmap',
cpp => 'C++ Source',
txt => 'Text file' );
print "$_: $subscripts{$_}\n" foreach (keys %subscripts);
Of course, if you eschew the chief virtue of Laziness you can do some really
bizarre stuff rolling your own tied classes, like creating references that
behave like hashes ($r->{key}) or arrays ($r->[3]) depending on how you
access them. Not for the feint of heart!
------------------------------
Date: 17 Nov 2000 02:35:30 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: IP geography
Message-Id: <8v25hi$1ie$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Iain Chalmers
<bigiain@mightymedia.com.au>],
who wrote in article <bigiain-1611001648150001@bigman.mighty.com.au>:
> my $m = ICBM::Launch->new('megatonnage'=>0.5);
>
> my ($lat,$lon);
>
> die "Cant find host" unless $p->ping($host);
>
> while($p->ping($host)){
> $lat=int(rand(36000)-18000)/100;
> $lon=int(rand(18000)-9000)/100;
> $m->launch($lat,$lon);
> }
>
> $p->close();
>
> print "Host $host was probably near $lat,$lon";
Do not think this is reliable enough... You may erroneously report
the coordinates of your PPP server instead of the coordinates of the
$host.
Moreover, did you check compatibility with DoomsDay::Machine.pm?
Ilya
------------------------------
Date: Fri, 17 Nov 2000 03:39:12 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: IP geography
Message-Id: <AL1R5.481$Bf7.178936832@news.frii.net>
In article <8v218h$fdk@gap.cco.caltech.edu>,
Gary E. Ansok <ansok@alumni.caltech.edu> wrote:
>In article <dWWQ5.466$Bf7.189491712@news.frii.net>,
>Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>>We couldn't find documentation on ICBM::Launch::launch? Does
>>it block till there is a detonation? I'll assume that it does.
>>Otherwise we will report bad locations.
>
>What happened when you tried it?
>
Someone in the operations group said that running it would cost
more than our budget for the month. So we decided to stub it out
for now.
--
This space intentionally left blank
------------------------------
Date: Fri, 17 Nov 2000 05:15:07 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: IP geography
Message-Id: <1ek89bj.1shzwl9r0ke8N%tony@svanstrom.com>
David Steuber <nospam@david-steuber.com> wrote:
> cfedde@fedde.littleton.co.us (Chris Fedde) writes:
>
> ' We couldn't find documentation on ICBM::Launch::launch? Does
> ' it block till there is a detonation? I'll assume that it does.
> ' Otherwise we will report bad locations.
>
> Check with http://wopr.norad.mil/
>
> Login with user Falken, password Joshua.
Try it, and then we'll know if they've got a sense of humour or not. :)
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Fri, 17 Nov 2000 04:33:30 GMT
From: Stephen S. <smart73_NOSPAM!!_@earthlink.net>
Subject: Re: Mail
Message-Id: <lbd91ts7urmi3g1dvlsg8gnka6fn5pb5l5@4ax.com>
What about something like this . . .
open MAIL,"|mail root";
print MAIL "OHH Shit!! $name or ($somename) attempted $someguess!!\n";
close MAIL;
This works on my system and send me (root) a message when someone
incorrectly puts a password in.
On Tue, 14 Nov 2000 15:48:07 -0500, "Mike Mesarch" <mesarch@ee.net>
wrote:
>Can someone provide me with some code to send a mail message in perl.
>Typically I don't ask for something like this, but I have searched to no
>avail on how to do this. In the doco it suggests using sendmail
>Mail:Mailer. All i want to do is connect to a mail server
>(smtp.something.com) and send a message. I haven't seen anything to do
>this.
>Thanks!
>Mike
>
------------------------------
Date: Fri, 17 Nov 2000 06:40:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Mail
Message-Id: <slrn919kn8.7vo.tjla@thislove.dyndns.org>
I was shocked! How could Stephen S. <smart73_NOSPAM!!_@earthlink.net>
say such a terrible thing:
>What about something like this . . .
>
>open MAIL,"|mail root";
>print MAIL "OHH Shit!! $name or ($somename) attempted $someguess!!\n";
>close MAIL;
Baaaaaaad idea. Berkeley mail is full of security issues. Unless you
want someone posting your /etc/passwd to usenet and renaming all your
files with random names that is.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
ADDER
n. A species of snake. So called from its habit of adding funeral outlays
to the other expenses of living.
------------------------------
Date: Thu, 16 Nov 2000 22:02:10 -0500
From: "dcfor3@hotmail.com" <dcfor3@hotmail.com>
Subject: Newbie Perl Question
Message-Id: <3A149FB2.ED66749C@hotmail.com>
I've been programming with perl for a couple of days now and have a
question I can't seem to find an answer to in the doc or newsgroups.
Has anyone run across this situation:
I have a file that has data listed in a column.
FILE: XYZ contains:
abc
def
ghi
123
456
789
...
I would like to write to a new file in the format bellow:
FILE:MNO contains
abc,def,ghi
123,456,789
...
Any way of doing this? TIA
------------------------------
Date: Fri, 17 Nov 2000 03:46:04 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Newbie Perl Question
Message-Id: <0S1R5.482$Bf7.190541824@news.frii.net>
In article <3A149FB2.ED66749C@hotmail.com>,
dcfor3@hotmail.com <dcfor3@hotmail.com> wrote:
>I've been programming with perl for a couple of days now and have a
>question I can't seem to find an answer to in the doc or newsgroups.
>Has anyone run across this situation:
>
>I have a file that has data listed in a column.
>FILE: XYZ contains:
>abc
>def
>ghi
>123
>456
>789
>...
>
>I would like to write to a new file in the format bellow:
>FILE:MNO contains
>
>abc,def,ghi
>123,456,789
>...
>
>Any way of doing this? TIA
>
while (<DATA>)
{
$n++;
chomp;
push @a, $_;
if ($n % 3 == 0)
{
print join(',', @a),"\n";
@a=();
}
}
print "...\n";
__DATA__
abc
def
ghi
123
456
789
--
This space intentionally left blank
------------------------------
Date: Thu, 16 Nov 2000 22:52:23 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Newbie Perl Question
Message-Id: <Pine.GSO.4.21.0011162245220.265-100000@crusoe.crusoe.net>
On Nov 16, dcfor3@hotmail.com said:
>abc
>def
>ghi
>123
>456
>789
>
>abc,def,ghi
>123,456,789
There's a sneaky solution that is derived from a merlyn answer:
perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/' in > out
It works by changing the newline to ",[NEXT LINE],[NEXT LINE]\n". This is
called "clever". ;)
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Fri, 17 Nov 2000 04:16:26 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Newbie Perl Question
Message-Id: <slrn919c7s.mf.mgjv@verbruggen.comdyn.com.au>
On Thu, 16 Nov 2000 22:52:23 -0500,
Jeff Pinyan <jeffp@crusoe.net> wrote:
> On Nov 16, dcfor3@hotmail.com said:
>
>>abc
>>def
>>ghi
>>123
>>456
>>789
>>
>>abc,def,ghi
>>123,456,789
>
> There's a sneaky solution that is derived from a merlyn answer:
>
> perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/' in > out
Very sneaky. One typo, though.
perl -pe 's/\n/chomp(my $n = <>); ",$n," . <>/e' in > out
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Fri, 17 Nov 2000 12:25:35 +0800
From: "meow" <atong@operamail.com>
Subject: Re: Newbie Perl Question
Message-Id: <8v2c04$b06@news.or.intel.com>
Below may work for your case...
open(IN, " XYZ) or die "can't open XYZ\n";
open(OUT, "> MNO);
@string = ():
@numeric = ();
while(<IN>) {
if (/^(\w+)\s+/ {
push(@string,$1);
} elsif (/^(\d+)\s+/) {
push(@numeric,$1);
} else {
print "Unrecognized format\n";
}
}
print OUT "@sting\n";
print OUT "@numeric\n";
close(IN);
close(OUT);
dcfor3@hotmail.com wrote in message <3A149FB2.ED66749C@hotmail.com>...
>I've been programming with perl for a couple of days now and have a
>question I can't seem to find an answer to in the doc or newsgroups.
>Has anyone run across this situation:
>
>I have a file that has data listed in a column.
>FILE: XYZ contains:
>abc
>def
>ghi
>123
>456
>789
>...
>
>I would like to write to a new file in the format bellow:
>FILE:MNO contains
>
>abc,def,ghi
>123,456,789
>...
>
>Any way of doing this? TIA
>
------------------------------
Date: Fri, 17 Nov 2000 02:26:54 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Newbie Rename() Function
Message-Id: <slrn9195rc.4ut.tjla@thislove.dyndns.org>
I was shocked! How could Randall <tech-removethis-@rch-usa.com>
say such a terrible thing:
>I'm using this popular (?) script:
Popular? Infamous more like. Have a search in deja.com in this group for
"Matt Wright" before you decide if you really want to saddle yourself
with it.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A bird in the bush usually has a friend in there with him.
------------------------------
Date: Thu, 16 Nov 2000 19:08:17 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: No idea about perl, Long post, short question
Message-Id: <slrn919181.up.tadmc@maxim.metronet.com>
On Thu, 16 Nov 2000 06:44:14 -0000, Simon Watkins <siwatkins@iee.org> wrote:
>"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
>news:slrn916rbu.425.mgjv@verbruggen.comdyn.com.au...
>> On Thu, 16 Nov 2000 00:22:10 -0000,
>> Nope. Just someone who's figured out the statistical relation between
>> top posting and cluelessness. Just like many people here have.
>
>I have more
>important things to do than debate whether or not top posting represents
>"cluelessness".
I think you are missing the point.
I would expect that you would want the widest possible readership
for your posts, as that seems likely to increase your chances of
getting an answer.
Posting Jeopardy style gets your posts ignored.
People are making an issue of it because it appears that you do
not know that you are needlessly limiting the number of readers,
and they want you to know how you can avoid such ignoration.
The point is not whether or not Jeopardy posting actually represents
cluelessness. The point is that the perception of the people who
you are trying to reach is that Jeopardy means clueless.
Post Jeopardy if you want your post to be ignored. Use normal
chronology if you want your post to be read.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 16 Nov 2000 23:36:40 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: No idea about perl, Long post, short question
Message-Id: <slrn919gv8.14v.tadmc@maxim.metronet.com>
On Thu, 16 Nov 2000 19:35:49 -0000, Simon Watkins <siwatkins@iee.org> wrote:
>however I suspect that
>given my brief experiences in here, I'll explore other technology avenues.
Thank you.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 17 Nov 2000 06:40:05 -0000
From: "Simon Watkins" <siwatkins@iee.org>
Subject: Re: No idea about perl, Long post, short question
Message-Id: <%l4R5.43$3k.1260@news6-win.server.ntlworld.com>
"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn919181.up.tadmc@maxim.metronet.com...
> I think you are missing the point.
No, I think you are. Have you actually read any of this? - I thought not.
Simon.
------------------------------
Date: Fri, 17 Nov 2000 05:10:18 GMT
From: "Zachary Cooper" <ztc@bigfoot.com>
Subject: Re: perl readdir() question...
Message-Id: <_43R5.476$Xt6.50258@typhoon2.ba-dsg.net>
the combination of changes works.
thanks.
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9193gs.425.mgjv@verbruggen.comdyn.com.au...
> On Fri, 17 Nov 2000 00:39:07 GMT,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> >> use CGI;
> >
> > for debugging:
> >
> > use CGI::Carp qw(fatalsToBrowser);
>
> add a
>
> my $cgi = CGI->new();
> print $cgi->header('text/plain');
>
> too.. or something equivalent. The CGI.pm documentation tells you
> more.
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | The gene pool could use a little
> Commercial Dynamics Pty. Ltd. | chlorine.
> NSW, Australia |
------------------------------
Date: Thu, 16 Nov 2000 20:40:33 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: PERL/shell: batch renaming of files
Message-Id: <slrn9196l1.rk.tadmc@maxim.metronet.com>
On Wed, 15 Nov 2000 16:07:38 -0000, Herminio Gonzalez
<exet0964@sable.ox.ac.uk> wrote:
>I have a directory tree structure which is about three or four levels deep,
>branching about 3 times at each level. I would like to traverse the tree to
>the end nodes and look for files that match a certain pattern and rename
>them. For instance, I would like all files that match
>
>*_1_QS*
>to be renamed to
>*_QS_dens1*
-----------------
#!/usr/bin/perl -w
use strict;
use File::Find;
find( \&change_name, '.');
sub change_name {
if ( (my $new = $_) =~ s/_1_QS/_QS_dens1/ ) {
rename $_, $new unless -e $new;
}
}
-----------------
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 16 Nov 2000 21:45:06 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: please help!!! pos() and m//g bugs!!!
Message-Id: <Pine.GSO.4.21.0011162143450.265-100000@crusoe.crusoe.net>
[posted & mailed]
On Nov 17, guthrie_linck@my-deja.com said:
>($a, $b) = /(\w+):(\w+)/g;
m//g in LIST CONTEXT will return ALL matches, globally. That will end up
setting pos($_) back to 0. The solution, then is either:
/(\w+):(\w+)/g;
($a,$b) = ($1,$2);
or
/(\w+):(\w+)/ and ($a,$b) = ($1,$2);
or something like that.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Thu, 16 Nov 2000 19:48:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regex to zero pad an IP address
Message-Id: <slrn9193ja.rk.tadmc@maxim.metronet.com>
On Thu, 16 Nov 2000 12:13:03 +1300, Peter Sundstrom
<peter.sundstrom@eds.com> wrote:
>
>Jack Applin <neutron@jackbert.fc.hp.com> wrote in message
>news:8uv3us$5ea$1@fcnews.fc.hp.com...
>> $ip =~ s/(\d+)/sprintf "%03d",$1/eg;
>
>Now that's a good trick. I didn't realise you could use sprintf in a regex.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You cannot use sprintf in a regex.
The first part of s/// is a regex. The second part of s/// is NOT a regex.
In the replacement part of s///e you can use not only sprintf(),
but any Perl code at all!
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 17 Nov 2000 00:01:23 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Searching files
Message-Id: <slrn919idj.14v.tadmc@maxim.metronet.com>
On Thu, 16 Nov 2000 21:26:00 +0000, Robert <robert@genie.co.uk> wrote:
>Say I have a file file of URLs, in the format
><a href="http://websitesname.com/file.asp?name=john&phone=12345>Johns
>details</a>
>obviously they wont all be john, they will all have different names
>and phone numbers.
>What I want to do is search within this file for John and then display
>the phone number for that url.
>How easy is this
Pretty easy:
print "$1: $2\n" if /name=([^&]+)&phone=([^>]+)/;
>and If someone could give me some pointers I would be
>most happy.
perldoc perlre
perldoc perlop
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 17 Nov 2000 03:36:34 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Why are references useful?
Message-Id: <6J1R5.479$Bf7.189025792@news.frii.net>
In article <8v1kl8$3j3$1@nnrp1.deja.com>, <andrew338@my-deja.com> wrote:
>Perl is my first programming language. I can do most of the basic
>things and have read about references but don't use them. I don't see
>why to. A reference is "a piece of data that refers to another piece
>of data, but I already use $variable to represent a value like "6".
>
This is one of those things that are hard to explain with simple examples.
Suffice it to say that as you write more complex code you will start to
want to manipulate more complex data. And sometimes it is conveniant to
have some kind of indirection to represent the complex structure of your
data.
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 17 Nov 2000 05:27:59 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: XML-Parser compile problems
Message-Id: <zl3R5.487$Bf7.189811712@news.frii.net>
Keywords: obvious dork posts
While building XML-Parser-2.30 using 5.6.0 I get the following.
cc -c -fno-strict-aliasing -I/usr/local/include -O -DVERSION=\"2.30\"
-DXS_VERSION=\"2.30\" -DPIC -fpic
-I/usr/local/lib/perl5/5.6.0/i386-freebsd/CORE Expat.c
Expat.xs:140: warning: `ERRSV' redefined
/usr/local/lib/perl5/5.6.0/i386-freebsd/CORE/perl.h:733: warning: this is
the location of the previous definition
Expat.xs:132: conflicting types for `Perl_newSVpvn'
/usr/local/lib/perl5/5.6.0/i386-freebsd/CORE/proto.h:547: previous
declaration of `Perl_newSVpvn'
Expat.xs: In function `nsStart':
Expat.xs:678: `sv_undef' undeclared (first use in this function)
Expat.xs:678: (Each undeclared identifier is reported only once
Expat.xs:678: for each function it appears in.)
Am I as dumb as I look?
--
This space intentionally left blank
------------------------------
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 4909
**************************************